first order system

40
Department of Mechanical Engineering, LSU Session V MATLAB Tutorials Session V Mathematical Applications using MATLAB (Cont….) Rajeev Madazhy Email: [email protected] Dept of Mechanical Engineering LSU

Transcript of first order system

Page 1: first order system

Department of Mechanical Engineering, LSU Session V

MATLAB Tutorials

Session VMathematical Applications using MATLAB

(Cont….)

Rajeev MadazhyEmail: [email protected]

Dept of Mechanical Engineering

LSU

Page 2: first order system

Department of Mechanical Engineering, LSU Session V

Last Session….

Using fplot function

Minimization

Zero finding

Curve fitting

Interpolation

Integration

Page 3: first order system

Department of Mechanical Engineering, LSU Session V

Session V Outline….

Solving Double Integrals

Ordinary Differential Equations

Examples of ODE using MATLAB….

Mention of DDE’s

Page 4: first order system

Department of Mechanical Engineering, LSU Session V

Solving Double Integrals….

Consider the numerical solution of

Let

We write a function to calculate the double integral using the MATLAB

Inline function dblquad.

max

min

max

min

),(x

x

y

y

dxdyyxf

)cos()sin(),( yxxyyxf

Page 5: first order system

Department of Mechanical Engineering, LSU Session V

MATLAB M-File….

Function out=integrnd(x,y)

out= y*sin(x) + x*cos(y);

To evaluate the double integral, use

result = dblquad(‘integrnd’,xmin,xmax,ymin,ymax);

at the command prompt.

Page 6: first order system

Department of Mechanical Engineering, LSU Session V

In MATLAB….

Page 7: first order system

Department of Mechanical Engineering, LSU Session V

Books on solving ODE’s using MATLAB..

Linear Algebra and Differential Equations Using MATLABMartin Golubitsky, Michael Dellnitz

Ordinary Differential Equations Using MATLABJohn C. Polking & David Arnold

Page 8: first order system

Department of Mechanical Engineering, LSU Session V

Solving ODE’s….

MATLAB has the capability to solve the first order differential

equations using numerical methods.

The functions used are ode23 and ode25

Both ode23 and ode25 work the same way except for the internal

algorithm that is being used.

Let us use ode45 in solving the Differential equations.

Page 9: first order system

Department of Mechanical Engineering, LSU Session V

Format….

The format is as follows:

[t,y] = ode45(‘function_name’,tspan,y0)

function_name is the name of a function type file where the

differential equation is stored.

tspan is a vector specifying the initial and final values of

independent variable

y0 is a column vector containing the initial conditions

Results for the command are stored in vector y.

t is the vector of independent variable

Page 10: first order system

Department of Mechanical Engineering, LSU Session V

Example….

Solve a first order homogeneous differential equation with initial condition:

We rewrite it as :

1)0(

0.

ty

yy

1)0(

.

y

yy

Page 11: first order system

Department of Mechanical Engineering, LSU Session V

Function in MATLAB…Write the function in MATLAB and save it as ode1.m

Page 12: first order system

Department of Mechanical Engineering, LSU Session V

Cont….

Write the following in another m-file:

Page 13: first order system

Department of Mechanical Engineering, LSU Session V

Result….

Page 14: first order system

Department of Mechanical Engineering, LSU Session V

Non-homogenous ODE’s….

If the differential equation is not homogenous then we do the following:

It is rewritten again as follows:

1)0(

.2

ty

eyy t

1)0(

.2

y

eyy t

Page 15: first order system

Department of Mechanical Engineering, LSU Session V

Solution….

All we need to do is change the function in the m-file ode1.m

Rest remains the same as coded earlier.

Page 16: first order system

Department of Mechanical Engineering, LSU Session V

Higher order differential Equations….

The higher order differential equations can be converted to a

system of first order differential equations.

Next example shows how to solve second order differential

equation using ode45 in Matlab

Page 17: first order system

Department of Mechanical Engineering, LSU Session V

Problem….

m = 5 kg

k = 100N/mc = 1 kg/s

The following figure shows a spring-mass-damper system. Plot the response of the system when the initial displacement of mass m is 0.1 meters.

Page 18: first order system

Department of Mechanical Engineering, LSU Session V

Equation of motion….

The equation of motion is as follows:

Now we need to change it to first order equation to solve it.

Rewriting the equation we get,

1.0)0(

0...

tx

kxxcxm

1.0)0(

tx

xm

kx

m

cx

Page 19: first order system

Department of Mechanical Engineering, LSU Session V

Cont….

Consider the fact that is just velocity. So we can rewrite the equation as two first order differential equations

vx .

1.0)0(

0)0(

tx

tv

vx

xm

kv

m

cv

Page 20: first order system

Department of Mechanical Engineering, LSU Session V

Cont….

Or in general form we get:

1.0)0(

0)0(

2

1

12

211

tx

tx

xx

xm

kx

m

cx

Page 21: first order system

Department of Mechanical Engineering, LSU Session V

Cont….

Write the function as follows in Matlab editor and save it as ode2.m

Page 22: first order system

Department of Mechanical Engineering, LSU Session V

Cont….

Write the main program naming it as sorDiff.m

Note that we have two initial conditions here.

Page 23: first order system

Department of Mechanical Engineering, LSU Session V

Velocity Response….

Page 24: first order system

Department of Mechanical Engineering, LSU Session V

Displacement Response….

Page 25: first order system

Department of Mechanical Engineering, LSU Session V

Write a Matlab program to determine the time-temperature history of a sphere of radius r=5mm, initially at a uniform temperature of 4000C. The sphere is exposed to 2000C air with a convection coefficient of h=10 W/m^2-K. The thermophysical properties of the sphere material are:

=Density=3000kg/m^3

k=Thermal conductivity=20 W/m-K

c=specific heat=1000J/kg-K

Exercise….

Page 26: first order system

Department of Mechanical Engineering, LSU Session V

The relation between the sphere temperature and time is given by an energy balance on the sphere, which results in the following differential equation

where

H = convective heat transfer coefficient

T = temperature of the sphere at any time

A = surface area of the sphere = 4r2

V = volume of the sphere = 4/3 r3

T = time

dtdT

cVTThA )(

Exercise cont….

Page 27: first order system

Department of Mechanical Engineering, LSU Session V

This differential equation has the following exact solution which can be used to check the accuracy of the numerical solution provided by Matlab

)exp( tcVhA

TTTT

i

Exercise cont….

Page 28: first order system

Department of Mechanical Engineering, LSU Session V

Exact Temperature code….

Page 29: first order system

Department of Mechanical Engineering, LSU Session V

Using as function….

Page 30: first order system

Department of Mechanical Engineering, LSU Session V

MATLAB main code….

Page 31: first order system

Department of Mechanical Engineering, LSU Session V

Result and plot….

Page 32: first order system

Department of Mechanical Engineering, LSU Session V

Delay Differential Equations…

Ordinary differential equations (ODEs) and delay differential equations (DDEs) are used to describe many phenomena of physical interest.

While ODEs contain derivatives which depend on the solution at the present value of the independent variable (“time”), DDEs contain in addition, derivatives which depend on the solution at previous times.

DDEs are a better approximation than ODEs to many physical systems.

Page 33: first order system

Department of Mechanical Engineering, LSU Session V

Consider a system of delay differential equations of the form:

y(t) = f(t, y(t), y(t - τ1), y(t - τ2), . . . , y(t - τk))

that are solved on a ≤ t ≤ b with given history y(t) = S(t) for t ≤ a.

Cont….

Page 34: first order system

Department of Mechanical Engineering, LSU Session V

Function code….

Page 35: first order system

Department of Mechanical Engineering, LSU Session V

Main program….

Page 36: first order system

Department of Mechanical Engineering, LSU Session V

Output….

Page 37: first order system

Department of Mechanical Engineering, LSU Session V

http://www.radford.edu/~thompson/webddes/

Website where you could obtain

The dde23.m file…..

Page 38: first order system

Department of Mechanical Engineering, LSU Session V

Recap….

Solving Double Integrals

Ordinary Differential Equations

Examples of ODE using MATLAB….

Mention of DDE’s

Page 39: first order system

Department of Mechanical Engineering, LSU Session V

Next Session….

Engineering Applications using MATLAB….

Solving non linear differential equations

Algorithm analysis

Common mechanical problems

a) four bar linkage

b) vibrations

c) thermal and fluids

Page 40: first order system

Department of Mechanical Engineering, LSU Session V

Thank You