user2178841
user2178841

Reputation: 859

Solving in ODE45 -Matlab

I have an ODE, y'=y^2+y; So, I wrote an script as:

foo=@(y)(y.^2+y);
[x y]=ode45(foo,[1 4],1);

But it returns the following error:

Error using @(y)(y.^2+y)
Too many input arguments.

Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1}
to yp0.

Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...

I must have made some mistake in defining function. I appreciate any comments and suggestions.

Upvotes: 0

Views: 1756

Answers (1)

Eitan T
Eitan T

Reputation: 32920

Quoting the official documentation:

All solvers solve systems of equations in the form y′ = f(t,y) or problems that involve a mass matrix, M(t,y)y′ = f(t,y).

Your function accepts only one variable y, whereas it must accept two: t and y. So, if your ODE is y′ = y2 + y, define foo in the following manner:

foo = @(t, y)(y .^ 2 + y);

and it should work.

Upvotes: 4

Related Questions