Please help with using ode45

8 次查看(过去 30 天)
Christopher Carey
Christopher Carey 2018-4-26
Please assist me with resolving the errors I'm getting.
Heres my functions:
function output=funct(A,B,C,D,E,F,tmin,tmax)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
plot(t,y(:,1))
end
This is the function im attempting to cal
function ydot=func(t,y)
ydot(1)=y(2);
ydot(2)=y(3);
ydot(3)=((F*exp(-0.1*t)*cos(t))+(B*y(3))-(C*t*y(2))+(E*y(1)))/A;
ydot=ydot';
end
Here are my erros
Cannot find an exact (case-sensitive) match for 'F'
The closest match is: f in C:\Users\Christopher\Documents\MATLAB\f.m
Error in func (line 4)
ydot(3)=((F*exp(-0.1*t)*cos(t))+(B*y(3))-(C*t*y(2))+(E*y(1)))/A;
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in funct (line 2)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);

回答(1 个)

Walter Roberson
Walter Roberson 2018-4-26
You need to pass some of the variables into your fun.
  2 个评论
Christopher Carey
Christopher Carey 2018-4-26
编辑:Walter Roberson 2018-4-26
Hey trying to attempt this but still getting errors
New Code:
function output=funct(A,B,C,D,E,F,tmin,tmax)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
function ydot=func(t,y)
ydot(1)=y(2);
ydot(2)=y(3);
ydot(3)=((F*exp(-0.1*t)*cos(t))+(B*y(3))-(C*t*y(2))+(E*y(1)))/A;
ydot=ydot';
end
plot(t,y(:,1))
end
Error:
>> func(1, 5, 7, 9, 11, 13, 0, 20)
Not enough input arguments.
Error in func (line 2)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in func (line 2)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
Walter Roberson
Walter Roberson 2018-4-26
You need to change
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
to
[t,y] = ode45(@func,[tmin tmax],[0 0 0]);
You posted,
>> func(1, 5, 7, 9, 11, 13, 0, 20)
Not enough input arguments.
Error in func (line 2)
[t,y]=ode45('func',[tmin tmax],[0 0 0]);
However, that code does not occur on line 2 of func. Line 2 of func is the empty line between the 'function' header and the line
ydot(1)=y(2);
That code instead appears at line 2 of funct . With your having defined func as a nested function, there is no way you could have called func directly from the command line.
These facts suggest that you placed funct (with a t) in a file named func.m . Don't do that. Name the file funct.m

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by