You are on page 1of 15

Introduction to State Variables Matlabs ODE Solver Matrix Representation

MCE371: Vibrations
Prof. Richter
Department of Mechanical Engineering

Handout 5 Fall 2011

Introduction to State Variables Matlabs ODE Solver Matrix Representation

State-Space Representations Output Equations

State-Space vs. Dierential Equations

Follow Palm, Sect. 3.9 and pages 527-530


1

We can derive the equation of motion for a 1 DOF system: n-th order dierential equation By using state variables, we can replace 1 n-th order di. eq. by n 1st order di. eqs. This is done to facilitate computer simulations and use modern methods of analysis State-space representations are essential for future control systems and mechatronics studies.

Introduction to State Variables Matlabs ODE Solver Matrix Representation

State-Space Representations Output Equations

Choosing State Variables


Suppose we have the n-th order dierential equation an d n 1 x d nx + a + ...a2 x + a1 x + a0 x = bu n 1 dt n dt n1
n 1

x We choose n state variables sequentially, to match x , x , x .... d dt n1 . Then we have:

x 1 = x 2 = . . . = x n 1 =

x2 x3 . . . xn (1)

Introduction to State Variables Matlabs ODE Solver Matrix Representation

State-Space Representations Output Equations

Writing the state equations

The last state derivative is found from the di. eq. itself, as you did when building computer simulation diagrams. x n = 1 {an1 xn1 an2 xn2 ... a2 x2 a1 x + bu } an

Introduction to State Variables Matlabs ODE Solver Matrix Representation

State-Space Representations Output Equations

Example
Di. eq: 2 State variables: x1 x2 x3 x x x d 3x x + 3x + 6x = 4u dx 3

The equations for the rst n 1 state derivatives is always the same: x 1 = x2 ;x 2 = x3 and so on. The last equation is x 3 = 1 {x3 3x2 6x1 + 4u } 2

Introduction to State Variables Matlabs ODE Solver Matrix Representation

State-Space Representations Output Equations

Example...

The complete set of state equations is then: x 1 x 2 x 3 = = = x2 x3 1 {x3 3x2 6x1 + 4u } 2

Introduction to State Variables Matlabs ODE Solver Matrix Representation

State-Space Representations Output Equations

Specifying Outputs

The set of n state equations contains exactly the same information as the dierential equation It is frequently useful to dene outputs of interest (other than x itself) to reect variables being measured or monitored A linear output is a combination of state variables and input: y = c1 x1 + c2 x2 + ...cn xn + du

Introduction to State Variables Matlabs ODE Solver Matrix Representation

State-Space Representations Output Equations

Example

Find a state variable representation for the standard 1 DOF mass-spring-damper system. Find output equations for the velocity and the acceleration of the block, and also for the force in the damper.

Introduction to State Variables Matlabs ODE Solver Matrix Representation

Simulating with ode45

Multi-DOF, nonlinear vibratory systems can be eciently simulated in Matlab by using a state-variable based solver instead of Simulink ode45 uses Runge-Kuttas 4-5 integration method and will suit our needs in this course. A function must be written that returns the vector of state derivatives given t , x and u . The function contains the state equations written in Matlab language. Once the function has been written, ode45 can be used from the command line or from other programs

Introduction to State Variables Matlabs ODE Solver Matrix Representation

ode45 format

function xdot=example(t,x,u) xdot1=x(2); xdot2=x(3); ... xdotn=%enter the expression here xdot=[xdot1;xdot2;...xdotn]; %return derivative vector Note: function must be saved using the function name (example) and extension m. (example.m). Test that the function works by calling it from the workspace: >>example(0,[0;0;0..0];0)

Introduction to State Variables Matlabs ODE Solver Matrix Representation

Example

The function for the previous example must be something like: function xdot=example(t,x,u) u=sin(t) %sinusoidal input xdot1=x(2); xdot2=x(3); ... xdot3=(x(3)-3*x(2)-6*x(1)+4*u)/2 xdot=[xdot1;xdot2;...xdotn];

Introduction to State Variables Matlabs ODE Solver Matrix Representation

Example...

The call to ode45 requires:


1 2

A time span [0 tend] A vector of n initial conditions x0

Example: x (0) = 1, x (0) = 0, x (0) = 1, simulate from 0 to 10 sec: >> >> >> >> x0=[1;0;-1]; tspan=[0 10]; [t,x]=ode45(example,tspan,x0); plot(t,x(:,1)) %plot 1st state

Introduction to State Variables Matlabs ODE Solver Matrix Representation

Standard Linear State-Space Form

Standard form: x = Ax + Bu and y = Cx + Du The column vector x = [x1 , x2 , ...xn ]T is called the state vector The set where x varies is the state space The column vector u = [u1 , u2 ...um ]T is the input vector The column vector y = [y1 , y2 , ...yp ]T is the output vector For n states, m inputs, p outputs: A is an n-by-n matrix, B is n-by-m, C is p -by-n and D is p -by-m.

Introduction to State Variables Matlabs ODE Solver Matrix Representation

Example

Mass-spring-damper system. Choosing position and velocity as states, we nd the following representation: x 1 x 2 For a velocity output: y = [0 1]x What are output matrices C and D for an acceleration output? = 0 k b 1 b m x1 x2 + 0
1 m

Introduction to State Variables Matlabs ODE Solver Matrix Representation

Recommended Exercise
For the dierential equation: 2 d 4x d 3x + 0.9 3 + 45.1 x + 10x + 250x = 250u 4 dt dt

1 2

Sketch a computer simulation diagram Simulate the response of the dierential equation to a unit step input excitation. Set all initial conditions to zero. Plot x as a function of time and simulate for 1 second. Find a state-variable representation. Prepare a state derivative function for use with ode45. Simulate for 1 second. Compare results. Find matrices A, B , C and D of the state-space representation

3 4

5 6

You might also like