Borrar filtros
Borrar filtros

Hey need assistance solving third order system using ode45

3 visualizaciones (últimos 30 días)
Christopher Carey
Christopher Carey el 26 de Abr. de 2018
Respondida: Steven Lord el 26 de Abr. de 2018
Hey trying to attempt this but still getting errors 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]);

Respuestas (1)

Steven Lord
Steven Lord el 26 de Abr. de 2018
Stop calling the ODE solvers with a char vector as the first input. That syntax still exists for backwards compatibility reasons but it behaves slightly differently than the syntax using function handles and hasn't been documented for probably 10-15 year now.
I strongly recommend using function handles instead. Once you switch to using function handles, you can have the ODE solver pass additional parameters into your ODE function using one of the techniques on this documentation page.
Usually if I'm trying to solve a simple problem in the Command Window I use the anonymous function approach. The nested function approach is good if you're writing one function file with a main function that calls the ODE solver and a local function that defines the ODE function as is the case for the problem you're trying to solve.
If you want a specific example you can use as a model for your code, see the "Pass Extra Parameters to ODE Function" example on the documentation page for ode45.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by