ode45问题,急啊。
楼主 · 1 楼
杠theta 杠lambda
我的M文件是:
function varargout=DYdt3(t,Y,flag,G,ME,tspan,Y0)
switch flag
case ''
varargout{1}=f(t,Y,G,ME);
case 'init'
[vararout{1:3}]=fi(tspan,Y0);
case 'events'
[varargout{1:3}]=fev(t,Y,Y0);
otherwise
error(['unknown flag'])
end
%--------------------------------------------------------
function Yd=f(t,Y,G,ME)
X=Y(1:2);
V=Y(3:4);
r=sqrt(sum(X.^2));
Yd=[V;-G*ME*X/r^3];
%--------------------------------------------------------
function[ts,y0,options]=fi(tspan,Y0)
ts=tspan;
y0=Y0;
options=odeset('Events','on','RelTol',1e-5,'AbsTol',1e-4);
%---------------------------------------------------------
function [value,isterminal,direction]=fev(t,Y,Y0)
dDSQdt=2*((Y(1:2)-Y0(1:2))'*Y(3:4));
value=[dDSQdt;dDSQdt];
direction=[1;-1];
isterminal=[1;0]
然后在这里面调用它
G=6.672e-11;
ME=5.97e24;
vy0=4000;
x0=-4.2e7;
t0=0;
tf=60*60*24*9;
tspan=[t0,tf];
Y0=[x0;0;0;vy0];
[t,YY,Te,Ye,Le]=ode45('DYdt3',[],[],[],G,ME,tspan,Y0);
X=YY(:,1);
Y=YY(:,2);
plot(X,Y,'b','Linewidth',2);
为什么运行时会出错呢。
??? Error using ==> DYdt3
unknown flag
Error in ==> funfun\private\odearguments at 57
[def_tspan,def_y0,def_options] = feval(ode,[],[],'init',extras{:});
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
Error in ==> main at 10
[t,YY,Te,Ye,Le]=ode45('DYdt3',[],[],[],G,ME,tspan,Y0); 杠Delta 杠lambda 杠mu
杠cong 杠theta 杠tau
我的M文件是:
function varargout=DYdt3(t,Y,flag,G,ME,tspan,Y0)
switch flag
case ''
varargout{1}=f(t,Y,G,ME);
case 'init'
[vararout{1:3}]=fi(tspan,Y0);
case 'events'
[varargout{1:3}]=fev(t,Y,Y0);
otherwise
error(['unknown flag'])
end
%--------------------------------------------------------
function Yd=f(t,Y,G,ME)
X=Y(1:2);
V=Y(3:4);
r=sqrt(sum(X.^2));
Yd=[V;-G*ME*X/r^3];
%--------------------------------------------------------
function[ts,y0,options]=fi(tspan,Y0)
ts=tspan;
y0=Y0;
options=odeset('Events','on','RelTol',1e-5,'AbsTol',1e-4);
%---------------------------------------------------------
function [value,isterminal,direction]=fev(t,Y,Y0)
dDSQdt=2*((Y(1:2)-Y0(1:2))'*Y(3:4));
value=[dDSQdt;dDSQdt];
direction=[1;-1];
isterminal=[1;0]
然后在这里面调用它
G=6.672e-11;
ME=5.97e24;
vy0=4000;
x0=-4.2e7;
t0=0;
tf=60*60*24*9;
tspan=[t0,tf];
Y0=[x0;0;0;vy0];
[t,YY,Te,Ye,Le]=ode45('DYdt3',[],[],[],G,ME,tspan,Y0);
X=YY(:,1);
Y=YY(:,2);
plot(X,Y,'b','Linewidth',2);
为什么运行时会出错呢。
??? Error using ==> DYdt3
unknown flag
Error in ==> funfun\private\odearguments at 57
[def_tspan,def_y0,def_options] = feval(ode,[],[],'init',extras{:});
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
Error in ==> main at 10
[t,YY,Te,Ye,Le]=ode45('DYdt3',[],[],[],G,ME,tspan,Y0); 杠Delta 杠lambda 杠mu
杠cong 杠theta 杠tau