Skip to content

Octave基本语法(二)——微分方程和图形输出

L edited this page Nov 3, 2017 · 1 revision

微分方程(Integrating Differential Equations)

dx
-- = f (x, t)
dt
x(t = t0) = x0

需要注意的是,当输入function时,Octave会以不同的提示进行响应,以表明它正在等待完成输入
举个栗子:
先定义f (x, t)

=function xdot = f (x, t)
r = 0.25;
k = 1.4;
a = 1.5;
b = 0.16;
c = 0.9;
d = 0.8;
xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
endfunction
x0 = [1; 2];
t = linspace (0, 50, 200)';
x = lsode ("f", x0, t);

生成图形输出

为了以图形的方式输出这个方程的解决方案,使用plot命令:

plot (t, x)

Octave会自动打开一个新窗口,显示结果
1
为了保存结果,使用print命令:(会保存在bin目录下)

print -dpdf foo.pdf

查看关于print的更多选项:

help print
Clone this wiki locally