Asked by kelly
on 9 Apr 2011

Is it necessary to define the function in the function window or can I define it directly in the command window?

Also, I don't understand what the errors mean. My original funcion was 2y'''-6y''+4y'+y=sin(t) , y''(0)=0, y'(0)=0, y(0)=1. (I converted my ode to its canonical form)

>> y=-0.5*y1-2*y2+3*y3+0.5*y4; >> t0=0; >> tf=10; >> y1=1; >> y2=0; >> y3=0; >> y4=.5; >> y0=[y1,y2,y3,y4]; >> yprime=-.5*y1-2*y2+3*y3+.5*y4; >> [T,Y]=ode45('yprime',t0,tf,y0) Warning: Obsolete syntax. Use ode45(fun,tspan,y0,...) instead. > In funfun\private\odearguments at 42 In ode45 at 173 ??? Error using ==> feval Undefined function or method 'yprime' for input arguments of type 'double'.

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

Error in ==> ode45 at 173 [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Answer by Matt Tearle
on 9 Apr 2011

You do not have to write a function file, but you do have to define a function. You've defined `y1` to `y4` as numeric variables, then calculated `yprime` from them. Hence `yprime` is just a number, which is why `ode45` reports that it can't find a function `yprime`.

Unless you want to mess with anonymous function handles, I suggest writing the equations in a function file.

Opportunities for recent engineering grads.

## 0 Comments