【发布时间】:2016-03-31 10:07:40
【问题描述】:
我试图让 matlab 显示猎物与捕食者的图表
function [ output_args ] = Untitled( input_args )
options = odeset('RelTol', 1e-4, 'NonNegative', [1 2]);
[t,x] = ode45('lotka_volterra', [0 30], [2 1], options);
plot(t,x);
legend('prey', 'predators');
end
function dxdt = lotka_volterra(t,x)
a = 1.2;
b = 0.6;
d = 0.3;
gamma = 0.8;
dxdt = [0;0];
dxdt(1) = a * x(1) - b * x(1) * x(2);
dxdt(2) = d * x(1) * x(2) - gamma * x(2);
end
重点是展示生活在同一环境中的两个物种的种群之间的动态关系。
两个导数(dxdt(1) 和 dxdt(2))模拟每个种群的变化率
我尝试使用 Runge-Kutta 积分方法来获得两个物种的种群与时间的关系图
错误只是说:
Error in Untitled (line 3)
[t,x] = ode45(@(t,x) lotka_volterra, [0 30], [2 1]);
我很难过任何帮助都会很棒
【问题讨论】:
-
你确定这是 entire 错误所说的吗?
-
哦,是的,抱歉,还有更多。首先它说 unrecognized double 'lotka_volterra',然后我去掉引号,它说没有足够的参数,然后添加它说 Attempted to access x(2);索引超出范围,因为 numel(x)=1。试用错误>lotka_volterra (line 16) dxdt(1) = a * x(1) - b * x(1) * x(2);