Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple MATLAB/Octave simulation

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 http://img199.imageshack.us/img199/2140/equation1.png

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))
like image 351
Attila O. Avatar asked Oct 15 '22 10:10

Attila O.


2 Answers

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.

like image 164
duffymo Avatar answered Nov 15 '22 15:11

duffymo


[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!

like image 21
Pentium10 Avatar answered Nov 15 '22 15:11

Pentium10