I'm plotting the phase portrait of the following system of ODE:

$\frac{dx}{dt} = x + 3 y$

$\frac{dy}{dt} = -5 x + 2 y$

The code I have in matlab:

function d=dxdt1(t,x)
d=[ x(1)+3*x(2); -5*x(1)+2*x(2) ];

Then the following plots a number of trajectories

hold on 
for theta=[0:10]*pi/5
    [t,x]=ode45(@dxdt1,[0 8],x0);

As you can see, the code that plots each trajectory references the function dxdt1 defined earlier.


I don't understand the use of pi, cos and sin in this code. Namely it seems that the domain is cos and sin of 1...10 * pi.

I don't see why it's necessary to use cos and sin in the domain instead of just a simple continuous interval such as from -50 to 50.

Any help on this one?

The output of the code:

Output of the code above

  • $\begingroup$ Maybe those initial conditions make the phase portrait look nicer and more like a spiral. Make $x_0$ something like [1, -1] and see what happens. $\endgroup$ – Moo Jul 9 '16 at 0:02

It's not necessary at all. All it does is decide the initial condition for each of the curves in the plot. So, what sin, cos, pi allow the code authors to do is to make ten starting points evenly spaced around a small circle centred on the origin.

Note the /5 there. That makes the theta go, not from $0$ to $10\pi$, but from $0$ to $2\pi$. Then taking sine and cosine of theta makes a circle, and 1e-5 makes the circle small (radius $10^{-5}$).

  • $\begingroup$ Thanks for the reply, very insightful. i think in my post I was confusing the initial conditions with something else. $\endgroup$ – Imme22009 Jul 9 '16 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.