请教一道MATLAB解常微分方程的题

来源:百度知道 编辑:UC知道 时间:2024/05/20 02:34:41
求Van der Pol方程
y"+a(y方-1)y'+y=0
y(0)=-0.2
y'(0)=-0.7
a=1
在区间[0,20]上的解。
老师给的答案是
function y=vdp_eq(t,x)
y=[x(2); -(x(1)*x(1)-1)*x(2)-x(1)];
x0=[-0.2; -0.7]
t_final=20
[t,x]=ode45(@vdp_eq, [0 t_final], x0)
plot(t,x)
但是我把这个复制进M函数后运行结果提示
??? Input argument 'x' is undefined.
Error in ==>
On line 2 ==> y = [x(2); (1-x(1)^2)*x(2)-x(1)];
(E:\work\test2.m是我M函数的文件名)
请高手帮我看看哪错了,万分感谢。

在Matlab下输入:edit,然后将下面两行百分号之间的内容,复制进去,保存
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y=vdp_eq(t,x)
y=[x(2); -(x(1)*x(1)-1)*x(2)-x(1)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

返回Matlab主界面输入:
x0=[-0.2; -0.7]
t_final=20
[t,x]=ode45(@vdp_eq, [0 t_final], x0)
plot(t,x)

你要做输入的啊
在运行前要先建立input值x 和 t
例如你在主界面输入:
x = 什么...
t = 什么....
y=vdp_eq(t,x)

这样才能得到结果