Please help with using ode45
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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]);
Antworten (1)
Walter Roberson
am 26 Apr. 2018
You need to pass some of the variables into your fun.
2 Kommentare
Christopher Carey
am 26 Apr. 2018
Bearbeitet: Walter Roberson
am 26 Apr. 2018
Walter Roberson
am 26 Apr. 2018
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
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!