plotting phase portraits with matlab:

30
PLOTTING PHASE PORTRAITS WITH MATLAB: Phase portraits is a useful graphical tool to understand the stable or unstable behavior of the equilibrium points of a nonlinear systems. 2 1 2 2 2 1 1 2 1 2 1 x x 3 x 6 . 0 x x x x dt dx x , x x 0 x x 3 x 6 . 0 x Consider the previous example, [x1, x2] = meshgrid(-4:0.2:1, - 2:0.2:2); x1dot = x2; x2dot = -0.6*x2-3*x1-x1.^2; quiver(x1,x2,x1dot,x2dot) xlabel('x_1') ylabel('x_2') Matlab code to plot phase portraits range for x 1 range for x 2

Upload: coye

Post on 19-Jan-2016

155 views

Category:

Documents


2 download

DESCRIPTION

Matlab code to plot phase portraits. [x1, x2] = meshgrid(-4:0.2:1, -2:0.2:2); x1dot = x2; x2dot = -0.6*x2-3*x1-x1.^2; quiver(x1,x2,x1dot,x2dot) xlabel('x_1') ylabel('x_2'). range for x 1. range for x 2. PLOTTING PHASE PORTRAITS WITH MATLAB:. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: PLOTTING PHASE PORTRAITS WITH MATLAB:

PLOTTING PHASE PORTRAITS WITH MATLAB:

Phase portraits is a useful graphical tool to understand the stable or unstable behavior of the equilibrium points of a nonlinear systems.

2122

21

121

2

1xx3x6.0xx

xxdt

dxx,xx

0xx3x6.0x

Consider the previous example,

[x1, x2] = meshgrid(-4:0.2:1, -2:0.2:2);x1dot = x2; x2dot = -0.6*x2-3*x1-x1.^2;quiver(x1,x2,x1dot,x2dot)xlabel('x_1')ylabel('x_2')

Matlab code to plot phase portraits

range for x1 range for x2

Page 2: PLOTTING PHASE PORTRAITS WITH MATLAB:

-5 -4 -3 -2 -1 0 1 2-2.5

-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

2.5

x1=x

x2=

xd

ot (-3,0) (0,0)

Page 3: PLOTTING PHASE PORTRAITS WITH MATLAB:

Example: Consider the undamped simple pendulum

m

θl

g

0sing

l

sing

l

L=1;g=9.81;[x1, x2] = meshgrid(-1:0.2:5, -2:0.2:2);x1dot = x2; x2dot = -g/L*sin(x1);quiver(x1,x2,x1dot,x2dot)

Matlab code to plot phase portraits

range for x1 range for x2

21 x,x

-2 -1 0 1 2 3 4 5-3

-2

-1

0

1

2

3

x1

x 2

Equilibrium points: (0, 0) and (, 0)Stable Unstable

Page 4: PLOTTING PHASE PORTRAITS WITH MATLAB:

-0.1 -0.08 -0.06 -0.04 -0.02 0 0.02 0.04 0.06 0.08 0.1-0.1

-0.05

0

0.05

0.1

x1

x 2

3.1 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.2-0.1

-0.05

0

0.05

0.1

x1

x 2(0,0)

(,0)

Page 5: PLOTTING PHASE PORTRAITS WITH MATLAB:

sing

l

For l=1 m

sin81.9

At the equilibrium, all derivatives are zero

d

d

sin81.90

0

rad

rad0

0

d

d

Consider the small perturbations around the equilibrium point θd=0

m

l

22d

11d

12

21

sin81.9

Nonlinear terms can be linearized using the Maclaurin series.

2

!2

)0(f

!1

)0(f)0(f)(f

Page 6: PLOTTING PHASE PORTRAITS WITH MATLAB:

For θd=0

11

211

sin2

)0sin(

1

0cos0sin)sin(

12

21

81.9

2

1

2

1

081.9

10

A

ans =

0 + 3.1321i 0 - 3.1321i

clc;clear;A=[0 1;-9.81 0];eig(A)

For θd=

22d

11d

12

21

sin81.9

1111 sincoscossin)sin(

1cos2

)0cos(

1

0sin0cos)cos(

1

211

Higher order term

12

21

81.9

2

1

2

1

081.9

10

clc;clear;A=[0 1;9.81 0];eig(A)

ans =

3.1321 -3.1321

Marginally stable

Unstable

m

l

1

Page 7: PLOTTING PHASE PORTRAITS WITH MATLAB:

2

1

2

1

081.9

10

2

1

2

1

081.9

10

[0.1;0]

Initial conditions

[0.1;0]

Initial conditions

Page 8: PLOTTING PHASE PORTRAITS WITH MATLAB:

Example:

Mathematical model of a nonlinear system is given by the equation

f03.02x

x128000x18x2

2

Where f(t) is the input and x(t) is the output of the system.

The state variables are chosen as x1=x and x2=dx/dt=dx1/dt

Find the equilibrium points for f=80 and linearize the system for small deviations from the equilibrium points. Find the response of the system

f015.02x

x64000x9x

xx

1

21

22

21

For the equilibrium condition

80*015.02x

x64000x90

x0

d1

2d1

d2

d2

>>solve(‘64000*x1^2/(x1+2)=1.2’)

x1d=0.00613, x2d=0

x1=x1d+1=0.00613+1

x2=x2d+2=2

Karagülle, System Modeling and Analysis

Page 9: PLOTTING PHASE PORTRAITS WITH MATLAB:

f015.02x

x64000x9x

xx

1

21

22

21

x1=x1d+1=0.00613+1

x2=x2d+2=2

f=fd+u

uf015.0

2x

x640009 d

1d1

21d1

22

21

u015.0f015.0x2x

x2

1

x2

1640009 d

211d1

2d112

d1d122

21

ufxx

xx ddd

dd

015.0015.022

64000

2

640009 11

2112

1122

21

u015.0f015.0

x2

x128000x

x2

64000

x2

x128000

x2

x640009 d2

d1

2d12

d112d1d1

1d1

d1

2d1

22

21

1

322

2

211

111

aaa

aaa

a

Page 10: PLOTTING PHASE PORTRAITS WITH MATLAB:

fd*015.02x

x64000x90

x0

d1

2d1

d2

d2

=0

u015.052.3909 122

21

u015.0x

x2

64000

x2

x128000f015.0

x2

x640009 2

d112d1d1

1d1d

d1

2d1

22

21

=0152.390

u015.0

0

952.390

10

2

1

2

1

clc;clear;

A=[0 1;-390.52 -9];eig(A)

ans =

-4.5000 +19.2424i -4.5000 -19.2424i

Stable system

Page 11: PLOTTING PHASE PORTRAITS WITH MATLAB:

clc;clear a=[0 1;-390.52 -9];b=[0 0.015]';c=[1 0];d=0; sys=ss(a,b,c,d); t=[0:.025:2]; [y,t,x]=step(sys*2,t); plot(t,y,'--','Linewidth',2);axis([0 2 0 0.00015]);grid; xlabel('time (sec)');ylabel('Y output');title('Step Response')

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

0.5

1

1.5x 10

-4

time (sec)

Step Response

Matlab code for step input with magnitude 2

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2-1

-0.5

0

0.5

1

1.5x 10

-3

time (sec)

Step Response

c=[0 1]

Page 12: PLOTTING PHASE PORTRAITS WITH MATLAB:

1

22

1

We can obtain the same result using Simulink.

2

t

u(t)2

t

u(t)

Page 13: PLOTTING PHASE PORTRAITS WITH MATLAB:

Example:

Phase portrait of a linear system.

2m

m

c

k

x(t)

R

xxcW

xk2

1R

R

xk

2

1E

xmm2

1

R

xRm2

2

1

2

1xm

2

1E

22

2

22

221

0kxxcxm2

xcxkxm2

Qx

E

x

E

dt

dx

21

x1=x

x2=dx/dt=dx1/dt

122

21

xm2

kx

m2

cx

xx

Initial conditions:

x1(0)=0.2

(dx/dt)t=0=x2(0)=1

x1=x

x2=dx/dt=dx1/dt

122

21

xm2

kx

m2

cx

xx

Page 14: PLOTTING PHASE PORTRAITS WITH MATLAB:

122

21

xm2

kx

m2

cx

xx

m=10;c=2;k=1000;[x1, x2] = meshgrid(-0.5:0.1:0.5, -2:0.2:2);x1dot = x2; x2dot = -c/(2*m)*x2-k/(2*m)*x1;quiver(x1,x2,x1dot,x2dot)

Matlab Code:At equilibrium

d1

d2

xm2

k0

m2

c0

x0

0xx

0xx

dd2

dd1

-0.4 -0.2 0 0.2 0.4 0.6-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

x

xdo

t

Initial

Equilibrium

Damping ratio

007.084.282

2

10*2*10002

2

km2

c

meş=2m

Page 15: PLOTTING PHASE PORTRAITS WITH MATLAB:

-0.4 -0.2 0 0.2 0.4 0.6-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

x

xdo

tm=10;c=40;k=1000;[x1, x2] = meshgrid(-0.5:0.1:0.5, -2:0.2:2);x1dot = x2; x2dot = -c/(2*m)*x2-k/(2*m)*x1;quiver(x1,x2,x1dot,x2dot)

Matlab Code:

141.084.282

40

10*2*10002

40

km2

c

m=10;c=40;k=1000;[x1, x2] = meshgrid(-0.5:0.1:0.5, -2:0.2:2);x1dot = x2; x2dot = -c/(2*m)*x2-k/(2*m)*x1;quiver(x1,x2,x1dot,x2dot)

Matlab Code:Damping ratio

Page 16: PLOTTING PHASE PORTRAITS WITH MATLAB:

53.084.282

150

10*2*10002

150

km2

c m=10;c=150;k=1000;

[x1, x2] = meshgrid(-0.5:0.1:0.5, -2:0.2:2);x1dot = x2; x2dot = -c/(2*m)*x2-k/(2*m)*x1;quiver(x1,x2,x1dot,x2dot)

Matlab Code:

-0.4 -0.2 0 0.2 0.4 0.6-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

x

xdo

t

-0.4 -0.2 0 0.2 0.4 0.6-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

x

xdo

t

Damping ratio

Page 17: PLOTTING PHASE PORTRAITS WITH MATLAB:

Example:

k

x(t)

mµ (Coulomb friction)

0mgxsgnkxxm

x1=x

x2=dx/dt=dx1/dt

m

mgxsgnx

m

kx

xx

212

21

m

mgxsgnx

m

k0

x0

d2d1

d2

At equilbrium

0xxk

mgxx

dd2

dd1

Page 18: PLOTTING PHASE PORTRAITS WITH MATLAB:

k/m=500/10=50µ*g=0.1*9.81=0.981

0.2 m

-0.4 -0.2 0 0.2 0.4 0.6-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

x

xdo

t

Page 19: PLOTTING PHASE PORTRAITS WITH MATLAB:

-0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

x

xdo

t

m=60;k=500;mu=0.3;g=9.81;[x1, x2] = meshgrid(-0.5:0.1:0.5, -2:0.2:2);x1dot = x2; x2dot = -(k/m)*x1-sign(x2)*mu*g;quiver(x1,x2,x1dot,x2dot)

Page 20: PLOTTING PHASE PORTRAITS WITH MATLAB:

Example: Van der Pol Equation

0xkx1xc2xm 2

xm

kx1x

m

c2x 2

m=10, c=20, k=1000

xm

kx

m

c2xx

m

c2x 2

x100x4xx8x

x10

1000x

10

20*2xx

10

40*2x

2

2

Mass-spring-damper system with a position dependent damper.

Page 21: PLOTTING PHASE PORTRAITS WITH MATLAB:

The Van der Pol equation can be regarded as describing a mass-spring-damper system with a position-dependent damping coefficient 2c(x2-1) (or, equivalently, an RLC electrical circuit with a nonlinear resistor). For large values of x, the damping coefficient is positive and the damper removes energy from the system. This implies that the system motion has a convergent tendency. However, for small values of x, the damping coefficient is negative and the damper adds energy into the system. This suggest that the system motion has a divergent tendency. Therefore, because the nonlinear damping varies with x, the system motion can neither grow unboundly nor decay zero. Instead, it displays a sustained oscillation independent of initial conditions. This so-called limit cycle is sustained periodically releasing energy into and absorbing energy from the environment, through the damping term. This is in contrast with the case of conservative mass-spring system, which does not exchange energy with its environment during its vibration.

Slotine and Weiping, Applied Nonlinear Control.

Page 22: PLOTTING PHASE PORTRAITS WITH MATLAB:

Of course, sustained oscillations can also be found in linear systems, in the case of marginally stable linear systems (such as a mass-spring system without damping) or in the response to sinusoidal inputs. However, limit cycles in nonlinear systems are difefrent from linear oscillations in a number of fundamental aspects. First, the amplitude of the self-sustained excitation is independent of initial consitions, while the oscillation of a marginally stable linear system has its amplitude determined by its initial conditions. Second, marginally stable linear systems are very sensitive to changes in system parameters (with a slight change capable of leading either to stable convergence or to instability), while limit cycles are not easily affected by parameter changes.

Limit cycles represent an important phenomenon in nonlinear systems. They can be found in many areas of engineering and nature. Aircraft wing fluttering, a limit cycle caused by the interaction of aerodynamic forces and structural vibrations, is frequently encountered and is sometimes dangerous.

Slotine and Weiping, Applied Nonlinear Control.

Page 23: PLOTTING PHASE PORTRAITS WITH MATLAB:

0.200

(0.2,0)

Limit cycle

Page 24: PLOTTING PHASE PORTRAITS WITH MATLAB:

0 0.6

(0.6,0)

Limit cycle

Page 25: PLOTTING PHASE PORTRAITS WITH MATLAB:

2 0.6

(0.6,2)

Limit cycle

Page 26: PLOTTING PHASE PORTRAITS WITH MATLAB:

Important Behaviors of Nonlinear Systems:

Bifurcations:

As the parameters of nonlinear dynamic systems are changed, the stability of equilibrium point can change and so can the number of equilibrium points.

Values of these parameters at which the qualitative nature of the system’s motion changes are known as critical or bifurcation values.The phenomenon of bifurcation, i.e., quantitaive change of parameters leading to qualitative change of system properties, is the topic of bifurcation theory.

Let us consider the system described by the co-called undamped Duffing equation (mass-spring system with a hardening spring).

0xxx 3

Pitchfork bifurcation Hopf bifurcation

Slotine and Weiping, Applied Nonlinear Control.

Page 27: PLOTTING PHASE PORTRAITS WITH MATLAB:

Chaos:

For stable linear systems, small differences in initial conditions can only cause small differences in output. Nonlinear systems, however, can display a phenomenon called chaos, by which we mean that the system output is extremely sensitive to initial conditions. The essential feature of chaos is the unpredictability of the system output. Even if we have an exact model of a nonlinear system and an extremely accurate computer, the system’s response in the long-run still cannot be well predicted.

As an example of chaotic behavior, let us consider the simple nonlinear system

tsin6xx1.0x 5 which may represent a lightly-damped, sinusoidally forced mechanical structure undergoing large elastic deflections. Consider two almost identical initial conditions, namely x(0)=2, (dx/dt)0=3 and x(0)=2.01, (dx/dt)0=3.01. Due to the strong nonlinearity in x5, the two responses are radically different after some time.

Slotine and Weiping, Applied Nonlinear Control.

Page 28: PLOTTING PHASE PORTRAITS WITH MATLAB:

0 5 10 15 20 25 30 35 40 45 50-2.5

-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

2.5

Time (sec)

x(t)

3)0(x,2)0(x 01.3)0(x,01.2)0(x

Displacement

Page 29: PLOTTING PHASE PORTRAITS WITH MATLAB:

0 5 10 15 20 25 30 35 40 45 50-6

-4

-2

0

2

4

6

Time (sec)

xdot(

t)3)0(x,2)0(x

01.3)0(x,01.2)0(x

Velocity

Page 30: PLOTTING PHASE PORTRAITS WITH MATLAB:

Small changes in initial conditions can cause recordable changes in the output of the system.