【发布时间】:2012-02-26 14:03:35
【问题描述】:
我想知道是否有人可以帮助我使用 MatLab 解决 Lotka-Volterra 方程。我的代码似乎不起作用。我执行以下操作:
第 1 步 -
我创建了一个名为 pred_prey_odes.m 的文件,其中包含以下代码:
% the purpose of this program is to model a predator prey relationship
% I will be using the Lotka-Volterra equations
% Program consists of the following differential equations:
% dY1/dt = a * Y1 - c * Y1 * Y2
% dY2/dt = b * Y2 - d * Y1 * Y2
function dy = pred_prey_odes(t, y)
% function that is to be integrated
%select constants
a = 1;
b = 2;
c = 3;
d = 4;
%set up differential equations
dy = zeros(2,1);
dy(1) = a * y(1) - c * y(1) * y(2);
dy(2) = b * y(2) - d * y(1) * y(2);
我保存了文件并确保它在当前目录中,然后在命令窗口中输入以下代码:
clc
tspan = [0, 20];
y0 = [10; 10];
ode = @(t, y) pred_prey_odes(t, y);
[t, y] = ode45(ode, tspan, y0);
plot (t,y)
但是,没有情节弹出。事实上,在 matlab 中什么都没有发生,我什至无法清除命令窗口。如果我输入 clc 什么都不会发生...
任何帮助将不胜感激!
谢谢!
-斯内哈因古瓦
【问题讨论】:
-
所以命令提示符不返回?该算法可能仍在运行。尝试按 Ctrl-C 退出操作。如果是这种情况,要么是您的实现有问题,要么是 ode45 需要很长时间才能解决
标签: matlab math plot equations differential-equations