ODE45 function returning error for a system of differential equations
Afficher commentaires plus anciens
Hello MATLABers,
I am trying to run this code:
if true
clc
clear
close all
format long
odefun = @deriv ;
tspan = [0 20] ;
Y0 = [ 10; 10; 10; 10; 10 ] ;
[t,y] = ode45( odefun, tspan, Y0, [] ) ;
function dYdt = deriv(Y)
Y1 = Y(1) ;
Y2 = Y(2) ;
Y3 = Y(3) ;
Y4 = Y(4) ;
Y5 = Y(5) ;
dYdt = zeros(5,1) ;
dYdt(1) = ( 250 - (7*Y1) + (2*Y3) ) / 100 ;
dYdt(2) = ( (4*Y1) - (4*Y2) ) / 100 ;
dYdt(3) = ( 400 + Y2 - (9*Y3) ) / 100 ;
dYdt(4) = ( Y2 + (7*Y3) - (11*Y4) + (3*Y5) ) / 100 ;
dYdt(5) = ( (3*Y1) + (2*Y2) - (5*Y5) ) / 100 ;
end
But I keep getting the following error:
if true
---> Error using ODE45_Trial>deriv
Too many input arguments.
---> 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 ODE45_Trial (line 12)
[t,y] = ode45( odefun, tspan, Y0, [] ) ;
I have no idea, what I am doing wrong, because I checked several webpages and read through many questions on the MATLAB community, but was not able to arrive at a solution. Please help me, this is due tomorrow. Any help is appreciated.
P.S the 'if true' at the start is not a part of the code. Thank You
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!