Please help with using ode45

조회 수: 1 (최근 30일)
Christopher Carey
Christopher Carey 2018년 4월 26일
댓글: Walter Roberson 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