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:
ode 45 solver problems

Subject: ode 45 solver problems

From: Ender

Date: 25 Jun, 2008 15:04:02

Message: 1 of 3

I cannot see the results from the ode45 solver program
that I wrote. I tried using the plot(T,Y(:,1),'-o')
function from the ode45 help menu but nothing helps.

I then copied the example from "Example 2"the help screen
under ode45. This is what the code says:

function dy = vdp1000(t,y)
dy = zeros(2,1); % a column vector
dy(1) = y(2);
dy(2) = 1000*(1 - y(1)^2)*y(2) - y(1)

[T,Y] = ode15s(@vdp1000,[0 1],[2 0]);
plot(T,Y(:,1),'-o')

Whenever I run this code I get error:

??? Input argument "y" is undefined.

Error in ==> vdp1000 at 7
dy(1) = y(2);


I don't understand why this code doesn't work. How do I
see the results from the solver?

Subject: ode 45 solver problems

From: vedenev

Date: 25 Jun, 2008 15:13:31

Message: 2 of 3

Try to make this part of code
function dy = vdp1000(t,y)
dy = zeros(2,1); % a column vector
dy(1) = y(2);
dy(2) = 1000*(1 - y(1)^2)*y(2) - y(1)

in separate file with name vdp1000.m

------------------------------------
Maxim Vedenev, Matlab freelancer
http://simulations.narod.ru/

Subject: ode 45 solver problems

From: Steven Lord

Date: 25 Jun, 2008 15:29:09

Message: 3 of 3


"Ender " <jr147@msstate.edu> wrote in message
news:g3tmp2$klb$1@fred.mathworks.com...
>I cannot see the results from the ode45 solver program
> that I wrote. I tried using the plot(T,Y(:,1),'-o')
> function from the ode45 help menu but nothing helps.
>
> I then copied the example from "Example 2"the help screen
> under ode45. This is what the code says:
>
> function dy = vdp1000(t,y)
> dy = zeros(2,1); % a column vector
> dy(1) = y(2);
> dy(2) = 1000*(1 - y(1)^2)*y(2) - y(1)

I'm betting that your vpd1000.m function doesn't end here, but includes the
following two lines. Those two lines should be in a separate file, a
separate function, or typed at the command line.

> [T,Y] = ode15s(@vdp1000,[0 1],[2 0]);
> plot(T,Y(:,1),'-o')
>
> Whenever I run this code I get error:
>
> ??? Input argument "y" is undefined.

Yes, because you're likely calling vdp1000 with 0 input arguments; then on
line 7, where the function tries to use the second element of the second
input, that input doesn't exist.

Even if you were to call vdp1000 (the version with the ODE15S call included)
with two input arguments, when it reached the line where it calls ODE15S,
that function would call VDP1000, which would call ODE15S, which would call
VDP1000, ... and soon you hit the recursion limit. Unless you've written
your code to include a way to end the recursion (or you _want_ an "infinite"
recursion), you shouldn't use a recursive call for that application.

--
Steve Lord
slord@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