HOME
PDF

HowTo, Matlab/Simulink for basic modeling

Nasser M. Abbasi

July 2, 2015 page compiled on July 2, 2015 at 12:03am

Contents

1 How to solve first order ode with zero initial conditions?
2 How to solve first order ode with non-zero initial conditions?
3 How to solve second order ode with zero initial conditions?
4 How to solve second order ode with non-zero initial conditions?
5 How to solve mass/spring system with unit step input?

1 How to solve first order ode with zero initial conditions?

Solve y′(t) + 3y(t) = e−t  with y(0) = 0

model_1.slx

PIC

2 How to solve first order ode with non-zero initial conditions?

Solve y′(t) + 3y(t) = e−t  with y(0) = 1

model_2.slx

PIC

3 How to solve second order ode with zero initial conditions?

Solve y′′(t) + 5y′(t) + 4y(t) = 5cos(2t)  with y(0) = 0,y′(0) = 0

model_3.slx

PIC

4 How to solve second order ode with non-zero initial conditions?

Solve y′′(t) + 5y′(t) + 4y(t) = 5cos(2t)  with y(0) = 1,y′(0) = 0.5

The initial conditions are set up by modifying the integator 1
s  block as shown below.

model_4.slx

PIC

5 How to solve mass/spring system with unit step input?

model_5.slx

From HW problem I did for ECE 717, to be solved using Simulink

PIC

Starting with the assumption that the ground surface is smooth and there is no friction. Assuming that all parts are moving in the positive direction to the right. Taking a snap shot when s2 > s1   so that the spring k2   is in compression. Spring k1   is in compression by also assuming that s1 > u  at this instance.

Any other assumptions will also lead to the same set of equations as long as they are used in consistent way when finding the forces in the springs.

Starting with drawing a free body diagram of each body showing all forces acting on them based on the above assumption, and then using F  = ma  to find the equation of motion of each body m1, m2   . The free body diagrams is shown below

PIC

Now F =  ma  is applied to each body to obtain the equation of motions. For mass m
  2

pict

And for mass m1

pict

Now the state space equations are found.

pict

Hence

pict

The above is in the form of x′ = Ax + Bu  and y = Cx  + Du  where r = 2  is number of outputs,   m =  1  is the number of input and n =  4  is the number of states.

Using k1 = k2 = 0.5,m1 =  1,m2 =  2  and x (0) = 0  now the unit step response for y1,y2   is found using Simulink. With the above values the system becomes

pict

Using simulink, state space block was used to implement the above. A step input source was used. Demux was used to send the y1   and y2   responses to two different time scopes. Simulation was set for 40 seconds to obtain long enough view of the response. The following figure shows the step response and the model used.

PIC