hw3 solution

14
Homework 3 solution Question 1: 0 ) 1 ( 2 = + + y y y y & & & α MATLAB FILES To simulate the system save vander.m, vander1.m, vanderstart.m in same folder and run vanderstart.m Vander.m function xdot=vander(t,x) alpha=0.1; xdot=[x(2); -x(1)-alpha*(x(1)^2-1)*x(2)]; Vander1.m function xdot1=vander1(t1,x1) alpha=0.8; xdot1=[x1(2); -x1(1)-alpha*(x1(1)^2-1)*x1(2)]; Vanderstart.m ti=0; tf=50; tspan=[ti tf]; x0=[0 0.5]'; [t,x]= ode23('vander',tspan,x0); ti=0; tf=10; tspan=[ti tf]; x0=[0 0.5]'; [t1,x1]= ode23('vander1',tspan,x0); figure subplot(2,1,1), plot(t,x(:,1),'r'),grid on; title('Vanderpol Oscillator'),ylabel('y(t)'); xlabel('t (alpha=0.1)') subplot(2,1,2), plot(t1,x1(:,1),'b'),grid on; ylabel('y(t)');xlabel('t (alpha=0.8)') figure subplot(2,1,1), plot(x(:,1),x(:,2),'r'),grid on; title('Vanderpol Oscillator (Phase Plane Plot)'),ylabel('ydot(t)'); xlabel('y(t) (alpha=0.1)') subplot(2,1,2), plot(x1(:,1),x1(:,2),'b'),grid on; ylabel('ydot(t)');xlabel('y(t) (alpha=0.8)')

Upload: avi0341

Post on 15-Dec-2015

212 views

Category:

Documents


0 download

DESCRIPTION

lorentz

TRANSCRIPT

Page 1: HW3 Solution

Homework 3 solution Question 1:

0)1( 2 =+−+ yyyy &&& α

MATLAB FILES To simulate the system save vander.m, vander1.m, vanderstart.m in same folder and run vanderstart.m Vander.m function xdot=vander(t,x) alpha=0.1; xdot=[x(2); -x(1)-alpha*(x(1)^2-1)*x(2)]; Vander1.m function xdot1=vander1(t1,x1) alpha=0.8; xdot1=[x1(2); -x1(1)-alpha*(x1(1)^2-1)*x1(2)]; Vanderstart.m ti=0; tf=50; tspan=[ti tf]; x0=[0 0.5]'; [t,x]= ode23('vander',tspan,x0); ti=0; tf=10; tspan=[ti tf]; x0=[0 0.5]'; [t1,x1]= ode23('vander1',tspan,x0); figure subplot(2,1,1), plot(t,x(:,1),'r'),grid on; title('Vanderpol Oscillator'),ylabel('y(t)'); xlabel('t (alpha=0.1)') subplot(2,1,2), plot(t1,x1(:,1),'b'),grid on; ylabel('y(t)');xlabel('t (alpha=0.8)') figure subplot(2,1,1), plot(x(:,1),x(:,2),'r'),grid on; title('Vanderpol Oscillator (Phase Plane Plot)'),ylabel('ydot(t)'); xlabel('y(t) (alpha=0.1)') subplot(2,1,2), plot(x1(:,1),x1(:,2),'b'),grid on; ylabel('ydot(t)');xlabel('y(t) (alpha=0.8)')

Page 2: HW3 Solution

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

-1

0

1

2Vanderpol Oscillator

y(t)

t (alpha=0.1)

0 1 2 3 4 5 6 7 8 9 10-2

-1

0

1

2

y(t)

t (alpha=0.8)

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2-2

-1

0

1

2Vanderpol Oscillator (Phase Plane Plot)

ydot

(t)

y(t) (alpha=0.1)

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2-4

-2

0

2

4

ydot

(t)

y(t) (alpha=0.8)

Page 3: HW3 Solution

Question 2: MATLAB FILES To simulate the system save lorenz.m, lorenzstart.m in same folder and run lorenzstart.m Lorenz.m function xdot=lorenz(t,x) % sigma=11; r=25; b=8/3; sigma=10; r=28; b=8/3; xdot=[-sigma*(x(1)-x(2)); r*x(1)-x(2)-x(1)*x(3); -b*x(3)+x(1)*x(2)]; Lorenzstart.m close all; clear all; clc; ti=0; tf=150; tspan=[ti tf]; x0=[0.3 0.3 0.3]'; [t,x]= ode23('lorenz',tspan,x0); figure subplot(3,1,1), plot(t,x(:,1),'r'),grid on; title('Lorenz Attractor'),ylabel('x1(t)'); subplot(3,1,2), plot(t,x(:,2),'b'),grid on; ylabel('x2(t)'); subplot(3,1,3), plot(t,x(:,3),'g'),grid on; ylabel('x3(t)');xlabel('t') figure plot3(x(:,1),x(:,2),x(:,3)),grid on; xlabel('x1');ylabel('x2');zlabel('x3') title('Lorenz Attractor'); figure plot(x(:,1),x(:,2)),grid on; xlabel('x1');ylabel('x2'); title('Lorenz Attractor');

Page 4: HW3 Solution

0 50 100 150-20

0

20Lorenz Attractor

x1(t)

0 50 100 150-50

0

50

x2(t)

0 50 100 1500

20

40

60

x3(t)

t

-20-10

010

20

-40-20

0

20400

10

20

30

40

50

x1

Lorenz Attractor

x2

x3

Page 5: HW3 Solution

-20 -15 -10 -5 0 5 10 15 20-30

-20

-10

0

10

20

30

x1

x2

Lorenz Attractor

Problem 3: a)

StepScope

u2

MathFunction

1s

Integrator1

1s

Integrator

-9.8

Gain2

-1

Gain1

0.1

Gain

sin(u)

Fcn

Add

Page 6: HW3 Solution

b) Linearized

uxxxx

1.08.9 12

21+−=

=&&

Step Scope

1s

Integrator1

1s

Integrator

-9.8

Gain2

0.1

Gain

Page 7: HW3 Solution

c) clc; clear all; close all; A1=[0,1;-9.8,0]; B1=[0;0.1]; C1=[1,0]; D1=[0]; [num,den]=ss2tf(A1,B1,C1,D1); sys=tf(num,den); t=[0:0.01:1]; step=step(sys,t); plot(t,step)

Page 8: HW3 Solution

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.005

0.01

0.015

0.02

0.025

d) clc; clear all; close all; tf=[0 1]; x0=[0 0]; [t,x]=ode23('sys',tf,x0) plot(t,x(:,1)); function xdot=sys(t,x) xdot=[x(2);-(x(2))^2-9.8*sin(x(1))+0.1];

Page 9: HW3 Solution

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.005

0.01

0.015

0.02

0.025

Problem 4: The matlab code that was used to get the results for this problem is the following: clc; clear all; close all;

constant=input('input the number of the sytem:');

switch constant

case 1,

%% inverted pendulum

A=[0 1 0 0; 0 0 -1 0; 0 0 0 1; 0 0 10 0]; B=[0 0.1 0 -0.1]'; C=[1

0 0 0];

case 2,

%% flexible joint system

A=[0 1 0 0; -1 -0.2 1 0.2; 0 0 0 1; 1 0.2 -10 -2.1]; B=[0 1 0 0]';

C=[0 0 1 0];

case 3,

%% flexible link system

A=[0 1 0 0; -1 -0.1 1 0.1; 0 0 0 1; 1 0.1 -23 -0.3]; B=[0 1 0 0]';

C=[1 0 0 0];

end

D=0;

nm=0;

damp(A);

Page 10: HW3 Solution

system=ss(A,B,C,D)

p=pole(system)

[Wn,Z]=damp(system)

if constant==3,

alpha=Wn.*Z

POV1=100*exp((-(pi)*Z(4))/sqrt(1-Z(4)*Z(4)))

POV1=100*exp((-(pi)*Z(1))/sqrt(1-Z(4)*Z(1)))

end

if constant==4,

alpha=Wn.*Z

POV1=100*exp((-(pi)*Z(4))/sqrt(1-Z(4)*Z(4)))

POV1=100*exp((-(pi)*Z(1))/sqrt(1-Z(4)*Z(1)))

end

[num,den]=ss2tf(A,B,C,D,1)

z=zero(system)

for i=1:length(z),

if z(i)>0,

nm=1;

end

end

if nm==1,

fprintf('The system is non-minimum phase');

end

bode(system);

figure;

rlocus(system);

if constant==3,

time=[0:0.1:100];

u=ones(length(time),1);

figure; lsim(system,u,time);

end

if constant==4,

time=[0:0.1:150];

u=ones(length(time),1);

figure; lsim(system,u,time);

end

In the following are presented only the results that were obtained for the first three systems. The results for the fourth system are also obtained using the presented matlab code.

Page 11: HW3 Solution

For the first system the poles are: p = 0 0 3.1623 -3.1623 There are no complex poles. The transfer function of the system is:

10)-(ss0.9- 0.1s)( 22

2

=sH

The zeros of the system are 3 and -3. Since one of the zeros is in the RHP then the system is non-minimum phase. The bode plot of the system is presented in Figure 1. The root locus is presented in Figure 2. Looking at the root locus we conclude that the system is unstable so we do not plot the step response.

Figure 1. Bode plot for the first system

Page 12: HW3 Solution

Figure 2. Root locus for the first system

For the Flexible-joint system: the poles are: p = -1.0604 + 2.9975i -1.0604 - 2.9975i -0.0896 + 0.9393i -0.0896 - 0.9393i There are two pairs of complex poles. For these two pairs of poles the parameters values are: Wn= 0.9435 3.1796 alpha= 0.0896 1.0604 zeta= 0.0950 0.3335 POV1 = 32.9117 POV2 = 74.1003

Page 13: HW3 Solution

The transfer function of the system is:

93.7s11.38s2.3ss10.2s)( 234 ++++

+=sH

The system has one zero in -5. The bode plot of the system is presented in Figure 5. The root locus is presented in Figure 6. Looking at the root locus we conclude that the system is stable. The plot of the step response is presented in figure 7.

Figure 5. Bode plot for the flexible joint system

Page 14: HW3 Solution

Figure 6. Root locus for the flexible joint system

Figure 7. Step response of the flexible joint system