Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Error using ODE45 - need help figuring out what is wrong

Subject: Error using ODE45 - need help figuring out what is wrong

From: Tazmusica

Date: 8 Mar, 2011 22:33:19

Message: 1 of 3

I am trying to solve a system of differential equations. I ran into an error, so I attempted to see if I could get the example in the MATLAB help to work first. Here is the code I typed in, and saved as a file:

function dy = rigid(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);

This is directly from the MATLAB help. Next, I tried to run it by typing the following at the command prompt:

options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[T,Y] = ode45(@rigid,[0 12],[0 1 1],options);

The following errors resulted:

??? Error using ==> feval
Undefined function or method 'rigid' for input arguments of
type 'double'.

Error in ==> odearguments at 109
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, ...

Can anyone help me figure out what is going wrong? I have a feeling that I am missing something silly. Thanks.

Subject: Error using ODE45 - need help figuring out what is wrong

From: Steven_Lord

Date: 9 Mar, 2011 14:49:35

Message: 2 of 3



"Tazmusica " <tazmusica2@deletethis.gmail.com> wrote in message
news:il6arf$fa6$1@fred.mathworks.com...
> I am trying to solve a system of differential equations. I ran into an
> error, so I attempted to see if I could get the example in the MATLAB help
> to work first. Here is the code I typed in, and saved as a file:
>
> function dy = rigid(t,y)
> dy = zeros(3,1); % a column vector
> dy(1) = y(2) * y(3);
> dy(2) = -y(1) * y(3);
> dy(3) = -0.51 * y(1) * y(2);

What is the name of the file in which you saved the above function?

Remember that if the name of the main function in a file differs from the
name of the file in which it is saved, the name by which MATLAB will know
that main function is the name of the FILE not the name of the FUNCTION. So
if you saved this in a file myrigid.m you would need to call the ODE solver
using @myrigid not @rigid (and M-Lint/Code Analyzer will warn you about that
mismatch in the myrigid.m file.)

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Error using ODE45 - need help figuring out what is wrong

From: Tazmusica

Date: 9 Mar, 2011 17:02:05

Message: 3 of 3

Steve,
Thank you for your response. I saved the file as rigid.m

"Steven_Lord" <slord@mathworks.com> wrote in message <il841c$an6$1@fred.mathworks.com>...
>
>
> "Tazmusica " <tazmusica2@deletethis.gmail.com> wrote in message
> news:il6arf$fa6$1@fred.mathworks.com...
> > I am trying to solve a system of differential equations. I ran into an
> > error, so I attempted to see if I could get the example in the MATLAB help
> > to work first. Here is the code I typed in, and saved as a file:
> >
> > function dy = rigid(t,y)
> > dy = zeros(3,1); % a column vector
> > dy(1) = y(2) * y(3);
> > dy(2) = -y(1) * y(3);
> > dy(3) = -0.51 * y(1) * y(2);
>
> What is the name of the file in which you saved the above function?
>
> Remember that if the name of the main function in a file differs from the
> name of the file in which it is saved, the name by which MATLAB will know
> that main function is the name of the FILE not the name of the FUNCTION. So
> if you saved this in a file myrigid.m you would need to call the ODE solver
> using @myrigid not @rigid (and M-Lint/Code Analyzer will warn you about that
> mismatch in the myrigid.m file.)
>
> *snip*
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us