views:

209

answers:

2

This should be a very simple question for anyone who has some experience in this area, but I'm still new to this.

I have the following system (or here is an image with better resolution):

alt text

Given the following input:

u = min(2 - t/7.5, 2*(mod(t, 2) < 1));

I need to plot the output of system y.

I am describing the system with the following function:

function xprime = func(t, x)
    u = min(2 - t/7.5, 2*(mod(t, 2) < 1));
    xprime = [
        x(2);
        x(3);
        0.45*u - 4*x(3)^2 - x(2)*x(1) - 4*x(2) - 2*x(1);
        x(5);
        sin(t) - 3*x(5)*x(1);
    ];

and simulating with ode23, like this:

[tout, xout] = ode23(@func, [0 15], [1.5; 3; -0.5; 0; -1])

After the simulation, xout will have five columns. My question is: how do I know which one is the output of the y system?

EDIT: Ok, so to put it simple, I'd like to plot the solution like this:

a = 1 % what goes here? 1, 2, 3, 4 or 5?
plot(tout, xout(:,a))
A: 

[T,Y,TE,YE,IE] = ode23(odefun,tspan,y0,options)

The following table lists the output arguments for the solvers.

  • T Column vector of time points.
  • Y Solution array. Each row in Y corresponds to the solution at a time returned in the corresponding row of T.
  • TE The time at which an event occurs.
  • YE The solution at the time of the event.
  • IE The index i of the event function that vanishes.

Isten fizesse!

Pentium10
That's clear; but for each row I will have five values (the values from the five columns). Which one will correspond to the output of the *y* system?
Attila Oláh
plot(tout, xout(:,1),'-o');
Pentium10
+2  A: 

The one that corresponds to y, which appears to be x(1), of course.

If you compare your code to the equations, you can see that x(1) appears in the code every place that y appears in the equations. That would be my best guess.

duffymo