# Matlab problem 2nd order .. nonlinear sys

Discussion in 'Math' started by George_77, Jan 30, 2014.

1. ### George_77 Thread Starter New Member

Jan 30, 2014
1
0
Hello everyone,

I'm working on an autonomous nonlinear system as shown in the pic, unfortunately i don't know how to work with matlab .. I tried to get it done myself but I couldn't reach to a solution on how to plot x1 vs x2.

assuming initial condition
x1(0) = -1
x2(0) = 2

I'm trying to plot x2 versus x1? and x1(t) vs time?

what I have done so far, which is wrong, is as followed...

using a file.m
function xp=F(t,x)
xp=zeros(2,1);
xp(1)=x(2);
xp(2)=-3*x(1)-0.6*x(2)-x.^2;

comand window:

[t,x]=ode45('F',[t0,tf],[x10,x20]);

any help would be appreciated!

File size:
4.5 KB
Views:
25
2. ### MrChips Moderator

Oct 2, 2009
12,650
3,460
Matlab arrays begin with subscript (1), i.e. x1(1) and x2(1).

Create an array t = [1:n] where n is the number of elements in x1 and x2.

To plot a single array x1, you can use any of these examples:

plot(x1)

plot(t, x1)

plot(t, x1, '*')

plot(t, x1, t, x1, '*')

To plot both x1 and x2 on the same graph, use any combinations of the above.

Here are examples:

plot(t, x1, t, x2)

plot(t, x1, t, x1, '*', t, x2, t, x2, '+')

To plot x1 vs x2, you can choose

plot(x1, x2)

plot(x1, x2, '*')

plot(x1, x2, x1, x2, '*')

George_77 likes this.