matlab clase 02-10-2015

Post on 23-Jan-2016

10 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

matlab

TRANSCRIPT

>> a=[0 1 0;0 0 1;-6 -11 -6]

a =

0 1 0

0 0 1

-6 -11 -6

>> A=a

A =

0 1 0

0 0 1

-6 -11 -6

>> eig(A)

ans =

-1.0000

-2.0000

-3.0000

>> X=[1 1 1;-1 -2 -3; 1 4 6]

X =

1 1 1

-1 -2 -3

1 4 6

>> Xi=inv(X)

Xi =

0.0000 -2.0000 -1.0000

3.0000 5.0000 2.0000

-2.0000 -3.0000 -1.0000

>> Xi*AX

Undefined function or variable 'AX'.

>> Xi*A*X

ans =

-1.0000 -0.0000 -3.0000

0.0000 -2.0000 3.0000

-0.0000 -0.0000 -3.0000

>> X=[1 1 1;-1 -2 -3; 1 4 9]

X =

1 1 1

-1 -2 -3

1 4 9

>> Xi=inv(X)

Xi =

3.0000 2.5000 0.5000

-3.0000 -4.0000 -1.0000

1.0000 1.5000 0.5000

>> Xi*A*X

ans =

-1.0000 0.0000 -0.0000

0.0000 -2.0000 0.0000

-0.0000 -0.0000 -3.0000

>> syms t

>> phid=[exp(-t) 0 0;0 exp(-2t) 0;0 0 exp(-3t)]

phid=[exp(-t) 0 0;0 exp(-2t) 0;0 0 exp(-3t)]

|

Error: Unexpected MATLAB expression.

>> phid=[exp(-t) 0 0;0 exp(-2t) ;0 0 exp(-3t)]

phid=[exp(-t) 0 0;0 exp(-2t) ;0 0 exp(-3t)]

|

Error: Unexpected MATLAB expression.

>> phid=[exp(-t) 0 0;0 exp(-2t) 0;0 0 exp(-3t)]

phid=[exp(-t) 0 0;0 exp(-2t) 0;0 0 exp(-3t)]

|

Error: Unexpected MATLAB expression.

>> phid=[exp(-t) 0 0;0 exp(-2t) 0;0 0 exp(-3t)]

phid=[exp(-t) 0 0;0 exp(-2t) 0;0 0 exp(-3t)]

|

Error: Unexpected MATLAB expression.

>> phid=[exp(-t) 0 0;0 exp(-2*t) 0;0 0 exp(-3*t)]

phid =

[ exp(-t), 0, 0]

[ 0, exp(-2*t), 0]

[ 0, 0, exp(-3*t)]

>> Phi=X*phid*Xi

Phi =

[ 3*exp(-t) - 3*exp(-2*t) + exp(-3*t), (5*exp(-t))/2 - 4*exp(-2*t) + (3*exp(-3*t))/2, exp(-t)/2 - exp(-2*t) + exp(-3*t)/2]

[ 6*exp(-2*t) - 3*exp(-t) - 3*exp(-3*t), 8*exp(-2*t) - (5*exp(-t))/2 - (9*exp(-3*t))/2, 2*exp(-2*t) - exp(-t)/2 - (3*exp(-3*t))/2]

[ 3*exp(-t) - 12*exp(-2*t) + 9*exp(-3*t), (5*exp(-t))/2 - 16*exp(-2*t) + (27*exp(-3*t))/2, exp(-t)/2 - 4*exp(-2*t) + (9*exp(-3*t))/2]

>> help pretty

--- help for sym/pretty ---

pretty Pretty print a symbolic expression.

pretty(S) prints the symbolic expression S in a format that

resembles type-set mathematics.

See also sym/subexpr, sym/latex, sym/ccode.

Reference page in Help browser

doc sym/pretty

>> pretty(phi)

Undefined function or variable 'phi'.

Did you mean:

>> pretty(Phi)

+- -+

| #4 exp(-t) exp(-3 t) |

| 3 exp(-t) - 3 exp(-2 t) + exp(-3 t), #1 - #3 + --, ------- - exp(-2 t) + --------- |

| 2 2 2 |

| |

| #2 exp(-t) #4 |

| 6 exp(-2 t) - 3 exp(-t) - #4, 8 exp(-2 t) - #1 - --, 2 exp(-2 t) - ------- - -- |

| 2 2 2 |

| |

| 27 exp(-3 t) exp(-t) #2 |

| 3 exp(-t) - 12 exp(-2 t) + #2, #1 - 16 exp(-2 t) + ------------, ------- - #3 + -- |

| 2 2 2 |

+- -+

where

5 exp(-t)

#1 == ---------

2

#2 == 9 exp(-3 t)

#3 == 4 exp(-2 t)

#4 == 3 exp(-3 t)

>> A=[0 1;-2 -3]

A =

0 1

-2 -3

>> X=[1 1;-1 -2]

X =

1 1

-1 -2

>> Xi=inv(X)

Xi =

2 1

-1 -1

>> Ad=Xi*AX

Undefined function or variable 'AX'.

>> Ad=Xi*A*X

Ad =

-1 0

0 -2

>> phid=[exp(-t) 0;0exp(exp(-2*t))]

phid=[exp(-t) 0;0exp(exp(-2*t))]

|

Error: Unexpected MATLAB operator.

>> phid=[exp(-t) 0;0 exp(exp(-2*t))]

phid =

[ exp(-t), 0]

[ 0, exp(exp(-2*t))]

>> Phi=X*phid*Xi

Phi =

[ 2*exp(-t) - exp(exp(-2*t)), exp(-t) - exp(exp(-2*t))]

[ 2*exp(exp(-2*t)) - 2*exp(-t), 2*exp(exp(-2*t)) - exp(-t)]

>> pretty(Phi)

+- -+

| 2 exp(-t) - exp(exp(-2 t)), exp(-t) - exp(exp(-2 t)) |

| |

| 2 exp(exp(-2 t)) - 2 exp(-t), 2 exp(exp(-2 t)) - exp(-t) |

+- -+

>> X

X =

1 1

-1 -2

>> Xi

Xi =

2 1

-1 -1

>> Phi=X*phid*Xi

Phi =

[ 2*exp(-t) - exp(exp(-2*t)), exp(-t) - exp(exp(-2*t))]

[ 2*exp(exp(-2*t)) - 2*exp(-t), 2*exp(exp(-2*t)) - exp(-t)]

>> pretty(Phi)

+- -+

| 2 exp(-t) - exp(exp(-2 t)), exp(-t) - exp(exp(-2 t)) |

| |

| 2 exp(exp(-2 t)) - 2 exp(-t), 2 exp(exp(-2 t)) - exp(-t) |

+- -+

>> exp(exp(t))

ans =

exp(exp(t))

>> exp(exp(1))

ans =

15.1543

>> phid=[exp(-t) 0;0 exp(-2*t)]

phid =

[ exp(-t), 0]

[ 0, exp(-2*t)]

>> Phi=X*phid*Xi

Phi =

[ 2*exp(-t) - exp(-2*t), exp(-t) - exp(-2*t)]

[ 2*exp(-2*t) - 2*exp(-t), 2*exp(-2*t) - exp(-t)]

>> pretty(Phi)

+- -+

| 2 exp(-t) - exp(-2 t), exp(-t) - exp(-2 t) |

| |

| 2 exp(-2 t) - 2 exp(-t), 2 exp(-2 t) - exp(-t) |

+- -+

>> Xo=[-1; 2]

Xo =

-1

2

>> B=[0; 1]

B =

0

1

>> C=[1 0]

C =

1 0

>> D=0

D =

0

>> sys=ss(A,B,C,D)

sys =

a =

x1 x2

x1 0 1

x2 -2 -3

b =

u1

x1 0

x2 1

c =

x1 x2

y1 1 0

d =

u1

y1 0

Continuous-time state-space model.

>> help initial

initial Initial condition response of state-space models.

initial(SYS,X0) plots the undriven response of the state-space model SYS

(created with SS) with initial condition X0 on the states. This response

is characterized by the equations

.

Continuous time: x = A x , y = C x , x(0) = x0

Discrete time: x[k+1] = A x[k], y[k] = C x[k], x[0] = x0 .

The time range and number of points are chosen automatically.

initial(SYS,X0,TFINAL) simulates the time response from t=0 to the final

time t=TFINAL (expressed in the time units specified in SYS.TimeUnit).

For discrete-time models with unspecified sample time, TFINAL is

interpreted as the number of sampling periods.

initial(SYS,X0,T) uses the time vector T for simulation (expressed in the

time units of SYS). For discrete-time models, T should be of the form

Ti:Ts:Tf where Ts is the sampling time. For continuous-time models, T

should be of the form Ti:dt:Tf where dt is the sampling period for the

discrete approximation of SYS.

initial(SYS1,SYS2,...,X0,T) plots the response of several systems

SYS1,SYS2,... on a single plot. The time vector T is optional. You can

also specify a color, line style, and marker for each system, for

example:

initial(sys1,'r',sys2,'y--',sys3,'gx',x0).

When invoked with left hand arguments,

[Y,T,X] = initial(SYS,X0)

returns the output response Y, the time vector T used for simulation,

and the state trajectories X. No plot is drawn on the screen. The

matrix Y has LENGTH(T) rows and as many columns as outputs in SYS.

Similarly, X has LENGTH(T) rows and as many columns as states. The

time vector T is expressed in the time units of SYS.

See also initialplot, impulse, step, lsim, ltiview, DynamicSystem.

Overloaded methods:

DynamicSystem/initial

xregusermod/initial

localusermod/initial

localtruncps/initial

localsurface/initial

localpspline/initial

localpoly/initial

localbspline/initial

Reference page in Help browser

doc initial

>> t=0;0.1;6;

>> initial(sys,Xo;t)

initial(sys,Xo;t)

|

Error: Unbalanced or unexpected parenthesis or bracket.

>> initial(sys,Xo,t)

Error using DynamicSystem/initial (line 85)

In time response commands, the final time must be a positive scalar.

>> initial(sys,Xo,t)

Error using DynamicSystem/initial (line 85)

In time response commands, the final time must be a positive scalar.

>> SYS=ss(A,B,C,D)

SYS =

a =

x1 x2

x1 0 1

x2 -2 -3

b =

u1

x1 0

x2 1

c =

x1 x2

y1 1 0

d =

u1

y1 0

Continuous-time state-space model.

>> initial(SYS,Xo,t)

Error using DynamicSystem/initial (line 85)

In time response commands, the final time must be a positive scalar.

>> t=0:0.1;6;

>> t=0:0.1:6;

>> initial(SYS,Xo,t)

>> [Y,T,X]=initial

Error using initial (line 73)

Not enough input arguments.

>> [Y,T,X]=initial(SYS,Xo,t)

Y =

-1.0000

-0.8187

-0.6703

-0.5488

-0.4493

-0.3679

-0.3012

-0.2466

-0.2019

-0.1653

-0.1353

-0.1108

-0.0907

-0.0743

-0.0608

-0.0498

-0.0408

-0.0334

-0.0273

-0.0224

-0.0183

-0.0150

-0.0123

-0.0101

-0.0082

-0.0067

-0.0055

-0.0045

-0.0037

-0.0030

-0.0025

-0.0020

-0.0017

-0.0014

-0.0011

-0.0009

-0.0007

-0.0006

-0.0005

-0.0004

-0.0003

-0.0003

-0.0002

-0.0002

-0.0002

-0.0001

-0.0001

-0.0001

-0.0001

-0.0001

-0.0000

-0.0000

-0.0000

-0.0000

-0.0000

-0.0000

-0.0000

-0.0000

-0.0000

-0.0000

-0.0000

T =

0

0.1000

0.2000

0.3000

0.4000

0.5000

0.6000

0.7000

0.8000

0.9000

1.0000

1.1000

1.2000

1.3000

1.4000

1.5000

1.6000

1.7000

1.8000

1.9000

2.0000

2.1000

2.2000

2.3000

2.4000

2.5000

2.6000

2.7000

2.8000

2.9000

3.0000

3.1000

3.2000

3.3000

3.4000

3.5000

3.6000

3.7000

3.8000

3.9000

4.0000

4.1000

4.2000

4.3000

4.4000

4.5000

4.6000

4.7000

4.8000

4.9000

5.0000

5.1000

5.2000

5.3000

5.4000

5.5000

5.6000

5.7000

5.8000

5.9000

6.0000

X =

-1.0000 2.0000

-0.8187 1.6375

-0.6703 1.3406

-0.5488 1.0976

-0.4493 0.8987

-0.3679 0.7358

-0.3012 0.6024

-0.2466 0.4932

-0.2019 0.4038

-0.1653 0.3306

-0.1353 0.2707

-0.1108 0.2216

-0.0907 0.1814

-0.0743 0.1485

-0.0608 0.1216

-0.0498 0.0996

-0.0408 0.0815

-0.0334 0.0667

-0.0273 0.0546

-0.0224 0.0447

-0.0183 0.0366

-0.0150 0.0300

-0.0123 0.0246

-0.0101 0.0201

-0.0082 0.0165

-0.0067 0.0135

-0.0055 0.0110

-0.0045 0.0090

-0.0037 0.0074

-0.0030 0.0061

-0.0025 0.0050

-0.0020 0.0041

-0.0017 0.0033

-0.0014 0.0027

-0.0011 0.0022

-0.0009 0.0018

-0.0007 0.0015

-0.0006 0.0012

-0.0005 0.0010

-0.0004 0.0008

-0.0003 0.0007

-0.0003 0.0005

-0.0002 0.0004

-0.0002 0.0004

-0.0002 0.0003

-0.0001 0.0002

-0.0001 0.0002

-0.0001 0.0002

-0.0001 0.0001

-0.0001 0.0001

-0.0000 0.0001

-0.0000 0.0001

-0.0000 0.0001

-0.0000 0.0000

-0.0000 0.0000

-0.0000 0.0000

-0.0000 0.0000

-0.0000 0.0000

-0.0000 0.0000

-0.0000 0.0000

-0.0000 0.0000

>> plot(T,X)

>> grid

>> legend('X1','X2')

>> legend('X_1','X_2')

>> Phi

Phi =

[ 2*exp(-t) - exp(-2*t), exp(-t) - exp(-2*t)]

[ 2*exp(-2*t) - 2*exp(-t), 2*exp(-2*t) - exp(-t)]

>> x=Phi*Xo

x =

-exp(-2*t)

2*exp(-2*t)

>> x(1)

ans =

-exp(-2*t)

>> hold on

>> plot(t,x(1),'r*')

Error using plot

Conversion to double from sym is not possible.

>> plot(x(1),t,'r*')

Error using plot

Conversion to double from sym is not possible.

>> x(2)

ans =

2*exp(-2*t)

>> help lsim

lsim Simulate time response of dynamic systems to arbitrary inputs.

lsim(SYS,U,T) plots the time response of the dynamic system SYS to the

input signal described by U and T. The time vector T is expressed in the

time units of SYS and consists of regularly spaced time samples. The

matrix U has as many columns as inputs in SYS and its i-th row specifies

the input value at time T(i). For example,

t = 0:0.01:5; u = sin(t); lsim(sys,u,t)

simulates the response of a single-input model SYS to the input

u(t)=sin(t) during 5 time units.

For discrete-time models, U should be sampled at the same rate as SYS

(T is then redundant and can be omitted or set to the empty matrix).

For continuous-time models, choose the sampling period T(2)-T(1) small

enough to accurately describe the input U. lsim issues a warning when

U is undersampled and hidden oscillations may occur.

lsim(SYS,U,T,X0) specifies the initial state vector X0 at time T(1)

(for state-space models only). X0 is set to zero when omitted.

lsim(SYS1,SYS2,...,U,T,X0) simulates the response of several systems

SYS1,SYS2,... on a single plot. The initial condition X0 is optional.

You can also specify a color, line style, and marker for each system,

for example

lsim(sys1,'r',sys2,'y--',sys3,'gx',u,t).

Y = lsim(SYS,U,T) returns the output history Y. No plot is drawn on

the screen. The matrix Y has LENGTH(T) rows and as many columns as

outputs in SYS. For state-space models,

[Y,T,X] = lsim(SYS,U,T,X0)

also returns the state trajectory X, a matrix with LENGTH(T) rows

and as many columns as states.

For continuous-time models,

lsim(SYS,U,T,X0,'zoh') or lsim(SYS,U,T,X0,'foh')

explicitly specifies how the input values should be interpolated

between samples (zero-order hold or linear interpolation). By default,

lsim selects the interpolation method automatically based on the

smoothness of the signal U.

See LSIMPLOT for additional graphical options for lsim plots.

See also lsimplot, gensig, step, impulse, initial, DynamicSystem.

Overloaded methods:

DynamicSystem/lsim

resppack.ltisource/lsim

Reference page in Help browser

doc lsim

>> size(t)

ans =

1 61

>> U=ones(1,61)

U =

Columns 1 through 14

1 1 1 1 1 1 1 1 1 1 1 1 1 1

Columns 15 through 28

1 1 1 1 1 1 1 1 1 1 1 1 1 1

Columns 29 through 42

1 1 1 1 1 1 1 1 1 1 1 1 1 1

Columns 43 through 56

1 1 1 1 1 1 1 1 1 1 1 1 1 1

Columns 57 through 61

1 1 1 1 1

>> [y,t,x]=lsim(SYS,U,t,Xo)

y =

-1.0000

-0.8142

-0.6539

-0.5152

-0.3950

-0.2905

-0.1994

-0.1199

-0.0503

0.0108

0.0645

0.1117

0.1534

0.1903

0.2230

0.2520

0.2777

0.3006

0.3210

0.3392

0.3555

0.3700

0.3831

0.3947

0.4052

0.4145

0.4230

0.4305

0.4373

0.4435

0.4490

0.4539

0.4584

0.4624

0.4661

0.4693

0.4723

0.4750

0.4774

0.4796

0.4815

0.4833

0.4849

0.4863

0.4876

0.4888

0.4899

0.4909

0.4917

0.4925

0.4932

0.4939

0.4945

0.4950

0.4955

0.4959

0.4963

0.4966

0.4970

0.4973

0.4975

t =

0

0.1000

0.2000

0.3000

0.4000

0.5000

0.6000

0.7000

0.8000

0.9000

1.0000

1.1000

1.2000

1.3000

1.4000

1.5000

1.6000

1.7000

1.8000

1.9000

2.0000

2.1000

2.2000

2.3000

2.4000

2.5000

2.6000

2.7000

2.8000

2.9000

3.0000

3.1000

3.2000

3.3000

3.4000

3.5000

3.6000

3.7000

3.8000

3.9000

4.0000

4.1000

4.2000

4.3000

4.4000

4.5000

4.6000

4.7000

4.8000

4.9000

5.0000

5.1000

5.2000

5.3000

5.4000

5.5000

5.6000

5.7000

5.8000

5.9000

6.0000

x =

-1.0000 2.0000

-0.8142 1.7236

-0.6539 1.4891

-0.5152 1.2896

-0.3950 1.1196

-0.2905 0.9744

-0.1994 0.8500

-0.1199 0.7432

-0.0503 0.6512

0.0108 0.5719

0.0645 0.5032

0.1117 0.4437

0.1534 0.3919

0.1903 0.3468

0.2230 0.3074

0.2520 0.2729

0.2777 0.2427

0.3006 0.2161

0.3210 0.1926

0.3392 0.1719

0.3555 0.1537

0.3700 0.1375

0.3831 0.1231

0.3947 0.1103

0.4052 0.0989

0.4145 0.0888

0.4230 0.0798

0.4305 0.0717

0.4373 0.0645

0.4435 0.0581

0.4490 0.0523

0.4539 0.0471

0.4584 0.0424

0.4624 0.0382

0.4661 0.0345

0.4693 0.0311

0.4723 0.0281

0.4750 0.0253

0.4774 0.0229

0.4796 0.0207

0.4815 0.0187

0.4833 0.0168

0.4849 0.0152

0.4863 0.0138

0.4876 0.0124

0.4888 0.0112

0.4899 0.0102

0.4909 0.0092

0.4917 0.0083

0.4925 0.0075

0.4932 0.0068

0.4939 0.0061

0.4945 0.0055

0.4950 0.0050

0.4955 0.0045

0.4959 0.0041

0.4963 0.0037

0.4966 0.0034

0.4970 0.0030

0.4973 0.0027

0.4975 0.0025

>>c figure(2)

>> plot(t,x)

>>

top related