Please help with using ode45
조회 수: 4 (최근 30일)
이전 댓글 표시
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
2018년 4월 26일
You need to pass some of the variables into your fun.
댓글 수: 2
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 Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!