Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

CHE338_Lecture#10

Ordinary differential equations II

For reading Reference Chapra Chapter 25,26,27 Page 697-804

Objectives

To solve a set of ODEs

To solve ODEs using Matlab built-in functions

To illustrate stiffness

System of equations

dy1 f1 (t , y1 , y2 , , yn ) dt dy2 f 2 (t , y1 , y2 , , yn ) dt dyn f n (t , y1 , y2 , , yn ) dt


With n numbers of initial conditions
3

Solving a first-order ODE using a Matlab built-in function Lets consider:

dy f ( x, y ); y ( x1 ) y1 dx

ode45 : Based on fourth and fifth-order explicit RungeKutta method.

[x,y]=ode45(dxdyfun,interval,initial)

Note: Step size is automatically optimized

Example

dy 1.2 y 7e 0.3 x for 0 x 2.5; dx


>>xx=[0:0.5:2.5] >>yinit=3 >>dxdy=@(x,y) 1.2y+7e-0.3x >>[x,y]=ode45(dxdy,xx,yinit)

y ( x 0) 3

Other ODE Matlab built-in solver ode23 based on second and third-order explicit RungeKutta method

ode113 based on Adams-Bashforth-Moulton methods


ode15s

ode23s
ode23t

ode23tb based on an implicit Runge-Kutta method

Example: Predator-prey model

dN L bL N L N G d L N L dt dN G bG N G d G N G N L dt

N are the number of prey and predators B and d= the birth rate and death rate

NG and NL are 2000 and 500. bL=0.00025/year bG=1.1/year, dL=0.7/year and dG=0.0005/year

Example: Predator-prey model

clear all tt=[0:0.5:25]; function dydt=setode(t,y) bg=1.1;bl=0.00025;dg=0.0005; tini=[500; 2000]; dl=0.7; [t y]=ode23tb(@setode,tt,tini); f1=bl*y(1)*y(2)-dl*y(1); f2=bg*y(2)-dg*y(2)*y(1); plot(t,y(:,1),'--r',t,y(:,2)) dydt=[f1;f2]; xlabel('t'); end ylabel('y');

Stiffness

dy 1000 y 3000 2000e t dx


9

Solving a stiff higher-order ODE

d 2 y1 2 dy1 1000(1 y1 ) y1 0; 2 dt dt

dy1 y1 (0) 1 dt

function dydt=stiffode(t,y) mu=1000 f1=y(2); f2=mu*(1-y(1)^2)*y(2)-y(1); dydt=[f1;f2]; end

clear all tt=[0 6000]; tini=[1 1]; [t,y]=ode23s(@stiff,tt,tini);

plot(t,y(:,1))

10

Summary

A set of ODEs

Matlab built-in functions

Stiffness

11

You might also like