Please help with using ode45
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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]);
Risposte (1)
Walter Roberson
il 26 Apr 2018
You need to pass some of the variables into your fun.
2 Commenti
Walter Roberson
il 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
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!