HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe...

15
MEEN 364 Parasuram July 27, 2001 1 HANDOUT M.4 - SOLUTIONS OF ORDINARY DIFFERENTIAL EQUATIONS Introduction The majority of physical systems of interest in this course can be represented in the form of ordinary differential equations. In order to study the response of the system modeling, the differential equations must be solved. The general solution of a linear differential equation is the sum of two components, the particular integral and the complementary function. Often the particular integral is the steady-state component of the solution of the differential equation, while the complimentary function, which is the solution of the corresponding homogenous equation, is the transient component of the solution. Often the steady state component of the solution has the same form as the driving or (external) function. Solution of a second order differential equation The model of a majority of mechanical systems can be approximated with a second order differential equation. So the solution of a second order differential equation is important, as it can be used to study the response of many physical systems. Case 1: Constant forcing function Consider, for example a mass spring damper system subjected to a constant force ‘F’, as shown in the following figure: F m k c The governing differential equation of motion of the mass, ‘m’ is given by , ) ( ) ( ) ( . .. F t kx t x c t x m = + + (1) where dividing the entire equation by ‘m’, we have

Transcript of HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe...

Page 1: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

1

HANDOUT M.4 - SOLUTIONS OF ORDINARY DIFFERENTIALEQUATIONS

Introduction

The majority of physical systems of interest in this course can be represented in the formof ordinary differential equations. In order to study the response of the system modeling,the differential equations must be solved. The general solution of a linear differentialequation is the sum of two components, the particular integral and the complementaryfunction. Often the particular integral is the steady-state component of the solution of thedifferential equation, while the complimentary function, which is the solution of thecorresponding homogenous equation, is the transient component of the solution. Oftenthe steady state component of the solution has the same form as the driving or (external)function.

Solution of a second order differential equation

The model of a majority of mechanical systems can be approximated with a second orderdifferential equation. So the solution of a second order differential equation is important,as it can be used to study the response of many physical systems.

Case 1: Constant forcing function

Consider, for example a mass spring damper system subjected to a constant force ‘F’, asshown in the following figure:

F

m

k c

The governing differential equation of motion of the mass, ‘m’ is given by

,)()()(...

Ftkxtxctxm =++ (1)

where dividing the entire equation by ‘m’, we have

Page 2: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

2

Note that the time dependence is assumed and hence it is omitted for futuremanipulations.

....

mFx

mkx

mcx =++ (2)

Let

.

,2

2n

n

mkmc

ω

ωζ

=

=

So equation (2) reduces to

.2 2...

mFxxx nn =++ ωωζ (3)

As explained earlier, the solution to the above differential equation has two parts, theparticular integral and the complimentary function. To find the particular integral, whichis nothing but the steady-state solution, equate all of the derivate terms to zero, i.e.,

.0

,0.

..

=

=

x

x

Substituting the above relation in equation (3), we have

mFx

mFx

ns

n

2

2

ω

ω

=⇒

= (4)

The second of equations (4) represents the steady-state response of the system.

To find the complimentary function or the transient response, we need to consider thehomogenous equation, i.e.,

02 2...

=++ xxx nn ωωζ . (5)

Equation (5) is the left hand side of equation (3), with the right hand side set to zero.

To solve the above equation, first assume a solution of the form

Page 3: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

3

tAex λ= . (6)

Substituting the above relation in equation (5), we get

02 22 =++ tn

tn

t eAeAeA λλλ ωλωζλ (7)

0)2( 22 =++⇒ tnn eAAA λωλωζλ (8)

0=teλ is a trivial solution, as equation (6) will then be identically equal to zero, i.e.,0≡x . But we need to find the non-trivial solution, so

0≠teλ .

So from equation (8), we have

02 22 =++ nn ωλωζλ (9)

Solving the above quadratic equation, we find the following roots

.1

where

1

2

442

2

2,1

22,1

222

2,1

−=

±−=⇒

−±−=⇒

−±−=

ζωω

ωωζλ

ζωωζλ

ωωζωζλ

nd

dn

nn

nnn

Therefore the transient solution of the system is given as

ttt

dndn BeAex )()( ωωζωωζ −−+− += (10)

where A and B can be found based on the initial conditions. So the final solution of thedifferential equation given by equation (1) is

tt

n

ts

dndn BeAem

Fx

xxx)()(

2ωωζωωζ

ω−−+− ++=⇒

+=

For an unforced system, the differential equation is given by

0...

=++ kxxcxm . (11)

Page 4: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

4

Since the forcing function is equal to zero, here the steady state response of the systemwill be equal to zero, while the transient response will be the same as that of the forcedsystem. In other words the solution of the equation (11) is given as

tt

ttts

dndn

dndn

BeAex

BeAex

xxx

)()(

)()(0ωωζωωζ

ωωζωωζ

−−+−

−−+−

+=⇒

++=⇒

+=

Case 2: Time varying forcing function

In this case, instead of a constant forcing function driving the system as in case 1, let usconsider a harmonic function, Fejwt, which by Euler’s expansion is equal to

)sin(cos tjtF ωω + , driving the system. ’w’ is the frequency with which the drivingfunction is applied on the system. The governing differential equation will be

.2 2...

...

jwto

jwtnn

jwt

eFemFxxx

Fekxxcxm

==++⇒

=++

ωωζ (12)

Usually the form of the solution is similar to that of the driving function. In this case, toobtain the steady state component, we assume a solution of the form

jwtCex = .

Substituting the above relation in equation (12), we have

022

022

}2){(

2

FCj

eFeCejCeC

nn

jwtjwtn

jwtn

jwt

=+−⇒

=++−

ωωζωω

ωωωζω (13)

Diving the second equation of equation (13) by 2nω , results in

.

where

,}2)1{(}2)1{( 22

20

n

n

r

rrk

F

rr

F

C

ωω

ζζω

=

+−=

+−=

Once the value of ‘C’ is obtained, the steady state solution of the system is

jwts Cex = .

Page 5: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

5

The complimentary function or the transient response of this system is the same as that ofthe previous case, as the homogenous equation is the same. So the entire solution to thesystem subjected to a harmonic driving function is given by

.

where

,}2)1{(

conditionsinitialfromobtainedBandA

where,

2

)()(

n

jwtttst

r

rrk

FC

CeBeAex

xxxdndn

ωω

ζ

ωωζωωζ

=

+−=

−−−

++=⇒

+=−−+−

Using MATLAB to solve the differential equations

The ‘ODE’ command in MATLAB can be used to solve various differential equations.The use of this command is explained in detail with the help of the following example.

Example 1

Consider the system below.

m

k c

This system is similar to the one in case 1, except that the forcing function is equal tozero. Therefore the governing differential equation of motion of the system is

0...

=++ kxxcxm . (14)

Page 6: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

6

Problem statement

Solve for the response of the unforced system defined by the differential equation givenby equation (14). Assume ξ = 0.1; m = 1Kg; k = 100 N/m. Let the initial conditions bechosen as

smx

mx

/0)0(

02.0)0(.

=

=

Solution

Equation (14) is a second order constant-coefficient differential equation. To solve thisequation we have to reduce it into two first order differential equations. This step is takenbecause MATLAB uses a Runge-Kutta method to solve differential equations, which isvalid only for first order differential equations.

Let

..

vx = (15)

From the above expression we see that

0.

=++ kxcvvm , (16)

so equation (16) reduces to

].)()[(.

xmkv

mcv −−= (17)

We can see that the second order differential equation (14) has been reduced to two firstorder differential equations (15) and (17).

For our convenience, put

x = y (1);

);2(.

yvx ==

Note that, the variables ‘x’ and ‘v’ are the states of the system, and are each equated toanother variable y(1) and y(2) respectively to be compatible with MATLAB. Thesevariables are not the outputs of the system.

Page 7: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

7

Equations (15) and (17) reduce to

)1(.y = y (2); (18)

)2(.y = [(-c/m)*y (2) – (k/m)*y (1)]; (19)

To calculate the value of ‘c’, compare equation (14) with the following generalizedequation.

02 2...

=++ nn xx ωξω .

Equating the coefficients of the similar terms we have

nmc ξω2= (20)

mk

n =2ω . (21)

Using the values of ‘m’ and ‘k’, calculate the value of ‘c’ corresponding to the value of ξ.Once the value of ‘c’ is known, equations (18) and (19) can be solved using MATLAB.

Some of the properties of the system are defined as follows.

Natural frequency ωn = )/( mk = 10 rad/sec.For ξ = 0.1

Damped natural frequency ωd = ωn ξ 21− = 9.95 rad/sec.

Damped time period Td = 2π/ωd = 0.63 sec.

Therefore for to plot five time cycles, the time interval should be 5 times the dampedtime period, i.e., 3.16 sec.

MATLAB Code

In order to apply the ODE45 or any other numerical integration procedure, a separatefunction file must be generated to define equations (18) and (19). Actually, the right handside of equations (18) and (19) are what is stored in the file. The equations are written inthe form of a vector.

The MATLAB code is given below.

function yp = unforced(t,y)

yp = [y(2);(-((c/m)*y(2))-((k/m)*y(1)))]; (22)

In the above code ‘yp’ is a two dimensional vector representing the right hand side of theequations (18) and (19), respectively. Open a new M-file and write down the above two

Page 8: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

8

lines. The first line of the function file must start with the word “function” and the filemust be saved corresponding to the function call; i.e., in this case, the file is saved asunforced.m. The derivatives are stored in the form of a vector.

This example problem has been solved for ξ = 0.1. We need to find the value of ‘c/m’and ‘k/m’ so that the values can be substituted in equation (22). Substituting the values ofξ and ωn in equations (20) and (21) the values of ‘c/m’ and ‘k/m’ can be found out. Afterfinding the values, substitute them into equation (22). In this example

.1001

100

,2101.02

==

=××=

mkmc

Now we need to write a code, which calls the above function and solves the differentialequation and plots the required result. First open another M-file and type the followingcode.

tspan=[0 4];y0=[0.02;0];[t,y]=ode45('unforced',tspan,y0);

figure(1);plot(t,y(:,1));grid onxlabel(‘time’)ylabel(‘Displacement’)title(‘Displacement Vs Time’)

The ode45 command in the main body calls the function ‘unforced’, which defines thesystems first order derivatives. The response is then plotted using the plot command.‘tspan’ represents the time interval and ‘y0’ represents the initial conditions for y(1) andy(2), which in turn represent the displacement ‘x’ and the first derivative of ‘x’, i.e., thevelocity. In this example, the initial conditions are taken as 0.02 m for ‘x’ and 0 m/sec forthe first derivative of ‘x’ or the velocity of the mass ‘m’.

MATLAB uses a default step value for the vector ‘tspan’. In order to change the step sizeuse the following code

tspan=0:0.001:4;

This tells MATLAB that the vector ‘tspan’ is from 0 to 4 with a step size of 0.001. Thisexample uses an arbitrary step size. If the step size is too large, the plot obtained will notbe a smooth curve. So it is always better to use relatively smaller step size. But it alsotakes longer to simulate programs with smaller step size. So you have to decide which isthe best step size you can use for a given problem.

Page 9: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

9

In the above code ‘y(:,1) represents the displacement ‘x’. To plot the velocity, change thevariable in the plot command line to ‘y(:,2)’.

The plot is attached below

Note: Any nth order differential equation can be solved using MATLAB by following theprocedure outlined in example 1. In other words, the nth order differential equation can bereduced to ‘n’ first order differential equations and the ‘ode’ command in MATLAB canbe used to solve the system of ‘n’ first order differential equations.

Page 10: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

10

Example 2. Double Pendulum

Derive the governing differential equation of motion of a double pendulum. Solve thederived differential equation and plot the values of θ1 and θ2 with respect to time.Choose l1 = 1m; l2 = 1m; m1 = m2 = 5Kg. The initial conditions for θ1 and θ2 are 0.5233and 0.5233 radians respectively.

θ1

l1, m1

θ2 l2 , m2

Solution

When represented in a matrix form, the differential equations of motion for the abovesystem is

−−−

−++−=

−+

)122

1

.

1122

)12

2.

222121..

2

..

1

221212

1222112

sin(sin

sin(sin)()cos(

)cos()(

θθθθ

θθθθ

θ

θθθ

θθ

lmw

lmwwlmlm

lmlmm

MATLAB Code

These coupled second order differential equations must be converted into a vector of firstorder differential equation. This step is done by the following substitutions.

Substituting the above relations in the original nonlinear differential equation, we get thefollowing first order differential equations,

);4(

);3();2(

);1(

.

2

2

.

1

1

y

yy

y

=

==

=

θ

θθ

θ

−−−

−++−=

−+

)sin(sin

)4()sin(sin)(

)2(

)4(

)3(

)2(

)1(

0)cos(00100

)cos(0)(00001

122

1

.

1122

12

2.

222121

.

.

.

.

221212

1222112

θθθθ

θθθθ

θθ

θθ

lmw

ylmww

y

y

y

y

y

lmlm

lmlmm

Page 11: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

11

In this type of a problem where the coefficient matrix is a function of the states or thevariables, a separate M-file must be written which incorporates a switch/caseprogramming with a flag case of ‘mass’.

For example if the differential equation is of the form,

),()(),(.

ytFtyytM =

then the right hand side of the above equation has to be stored in a separate m-file called‘F.m’. Similarly the coefficient matrix should be stored in a separate m-file named‘M.m’. So, when the flag is set to the default, the function ‘F.m’ is called and later whenthe flag is set to ‘mass’ the function ‘M.m’ is called.

The code with the switch/case is given below. Note that it is a function file and should besaved as ‘indmot_ode.m’ in the current directory.

function varargout=indmot_ode(t,y,flag)

switch flagcase '' %no input flag varargout{1}=pend(t,y);case 'mass' %flag of mass calls mass.m varargout{1}=mass(t,y);otherwise error(['unknown flag ''' flag '''.']);end

To store the right hand side of the state variable matrix form of the model, a separatefunction file must be written as shown below. Note that the name of the function is‘pend’, so this file must be saved as ‘pend.m’.

%the following function contains the right hand side of the%differential equation of the form%M(t,y)*y'=F(t,y)%i.e. it contains F(t,y).it is also stored in a separate file named,pend.m.

function yp= pend(t,y)M1=5;M2=5;g=9.81;l1=1;l2=1;w2=M2*9.81;w1=M1*9.81;yp=zeros(4,1);yp(1)=y(2);yp(2)=-(w1+w2)*sin(y(1))+M2*l2*(y(4)^2)*sin(y(3)-y(1));yp(3)=y(4);yp(4)=-w2*sin(y(3))-M2*l1*(y(2)^2)*sin(y(3)-y(1));

Page 12: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

12

Similarly, to store the coefficient matrix a separate function file is written which is storedas ‘mass.m’.

% the following function contains the mass matrix.%it is separately stored in a file named, mass.m

function m = mass(t,y)M1=5;M2=5;g=9.81;l1=1;l2=1;m1=[1 0 0 0];m2=[0 (M1+M2)*l1 0 M2*l2*cos(y(3)-y(1))];m3=[0 0 1 0];m4=[0 M2*l1*cos(y(3)-y(1)) 0 M2*l2];m=[m1;m2;m3;m4];

To plot the response, the main file should call the function ‘indmot_ode.m’, which hasthe switch/case programming which in turn calls the corresponding functions dependingon the value of the flag. For the main file to recognize the coefficient matrix, theMATLAB command ODESET is used to set the mass to ‘M (t, y)’.

The MATLAB code for the main file is given below

% this is the main file, which calls the equations and solves usingode113.%it then plots the first variable.

tspan=[0 10]y0=[0.5233;0;0.5233;0]options=odeset('mass','M(t,y)')[t,y]=ode113('indmot_ode',tspan,y0,options)

subplot(2,1,1)plot(t,y(:,1))gridxlabel('Time')ylabel('Theta1')

subplot(2,1,2)plot(t,y(:,3))gridxlabel('Time')ylabel('Theta2')

For help regarding ‘subplot’ use the online help in MATLAB by typing the followingstatement at the command prompt.

help subplot

subplot(m,n,p), breaks the Figure window into an m-by-n matrix of small axes andselects the p-th axes for the current plot. The axes are counted along the top row of theFigure window, then the second row, etc. For example,

Page 13: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

13

subplot(2,1,1), plot(income) subplot(2,1,2), plot(outgo)

plots “income” on the top half of the window and “outgo” on the bottom half.

The plot has been attached.

Assignment

1) For the system shown below,

θ

Page 14: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

14

l

m

m = 10 g;l = 5 cms;

The initial conditions are θ (0) = 90° and 0)0(.

a) Derive the governing differential equation.b) Solve the above differential equation obtained analytically and plot the value of thetawith respect to time.c) Solve the differential equation using MATLAB and again plot the value of theta withrespect to time. Compare the results obtained from (2) and (3).

2) For the system shown below

F

m

k c

Using MATLAB, plot the response of a forced system given by the equation

tfkxxcxm ωsin...

=++

For ξ = 0.1.

Take m = 5 kg; k = 1000 N/m; f = 50 N; ω = 4ωn, x(0) = 5 cms; .x (0) = 0.

Page 15: HANDOUT ON SOLUTIONS OF DIFFERENTIAL EQUATIONS · jwt o jwt n n jwt e F e m F x x x m x c x kx Fe ⇒ + + = = + + = ζ ω ω (12) Usually the form of the solution is similar to that

MEEN 364 ParasuramJuly 27, 2001

15