如枫 发表于 2013-3-7 22:34

请教下面求解微分方程的程序问题出在哪?

请教下面求解微分方程的程序问题出在哪?

function dy = hlduffing(t,y)
global f
dy=zeros(3,1);
dy(1)=y(2);
dy(2)=f*cos(0.8*t)-0.2*y(2)-y(1)-y(1)^3;
end


function hlduffing1_bifur_f_getmax
% 最大值法求解分岔图
global f
clear all
t0=;%积分时间
%bifurcation
for f=linspace(10,32,1000);   %f=10:32:1000;   %r的变化精度
    =ode45('hlduffing',t0,);
    =getmax(y(:,1));
    plot(f,Xmax,'k','markersize',1)
    hold on
    clear Xmax
end


下面是系统错误提示:
In an assignmentA(I) = B, the number of elements in B and I must be the same.
Error in hlduffing (line 5)
dy(2)=f*cos(0.8*t)-0.2*y(2)-y(1)-y(1)^3;
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in hltest2013 (line 7)
=ode45('hlduffing',t0,)


伤痕累累 发表于 2013-3-8 10:28

本帖最后由 伤痕累累 于 2013-3-8 10:30 编辑

matlab还得好好学,目测你的程序
global f
dy=zeros(3,1);
dy(1)=y(2);
dy(2)=f*cos(0.8*t)-0.2*y(2)-y(1)-y(1)^3;
end
中dy=zeros(3,1)和后面的方程对应不上,应该是zeros(2,1)。
end也可以不要。

另外,分岔图最好不要用getmax,频闪和极大值法都是相比较之下很好的方法,建议你试一下。
页: [1]
查看完整版本: 请教下面求解微分方程的程序问题出在哪?