• Tidak ada hasil yang ditemukan

Solve ode Solve ode, dde & pde using using matlab

N/A
N/A
Protected

Academic year: 2025

Membagikan "Solve ode Solve ode, dde & pde using using matlab"

Copied!
27
0
0

Teks penuh

(1)

Solve ode Solve ode Solve ode

Solve ode, , , , dde dde dde & dde & & pde & pde pde pde using using using using

Farida Mosally

Mathematics Department King Abdulaziz University

2014

using using using

using matlab matlab matlab matlab

(2)

Outline

1. Ordinary Differential Equations (ode)

1.1 Analytic Solutions 1.2 Numerical Solutions

2. Delay Differential Equations (dde 3. Partial Differential Equations (pde

Ordinary Differential Equations (ode)

dde)

pde)

(3)

Ordinary Differential Equations

Analytic Solutions

Ordinary Differential Equations

Analytic Solutions

(4)

First Order Differential Equation

First Order Differential Equation

(5)

Suppose

get a rough idea

To solve an initial value problem, say,

Initial Value Problem

Suppose we want to plot the solution to get a rough idea of its behavior.

To solve an initial value problem, say,

Initial Value Problem

(6)

Second and Higher Order Equations

Suppose we want to solve and plot the solution to the second order equation

and Higher Order Equations

Suppose we want to solve and plot the solution to the second order

(7)

Numerical Solutions

Ordinary Differential Equations

Numerical Solutions

MATLAB has a number of tools for numerically solving ordinary differential equations. In the following table we display

Numerical Solutions

Ordinary Differential Equations

Numerical Solutions

MATLAB has a number of tools for numerically solving ordinary

. In the following table we display some of them.

(8)

Solver Method used

ode45 Runge-Kutta (4,5) formula ode23 Runge-Kutta (2, 3) formula

ode initial value problem

ode113 Adams-Bashforth-Moulton solver

ode15s Solver based on the numerical differentiation formulas

ode23s Solver based on a modified Rosenbrock formula of order 2

Order of Accuracy

When to Use

Medium Most of the time. This should be the first solver you try.

Low For problems with crude error

tolerances or for solving moderately stiff problems.

initial value problem solvers

Low to high For problems with stringent error tolerances or for solving

computationally intensive problems.

Low to medium

If ode45 is slow because the problem is stiff.

Solver based on a modified Rosenbrock Low If using crude error tolerances to solve stiff systems and the mass matrix is constant.

(9)

Defining an ODE function function

(10)

sol = solver(odefun,[t

Defining an ODE function

Example 1

,[t0 tf],y0,options)

function

1.7 1.8 1.9

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5

1 1.1 1.2 1.3 1.4 1.5 1.6 1.7

(11)

First Order Equations with M

function out = example xspan = [0,.5];

Example 2

xspan = [0,.5];

y0 = 1;

[x,y]=ode23(@firstode,xspan,y plot(x,y)

function yprime = firstode yprime = x*y^2 + y;

First Order Equations with M-files

out = example2()

(@firstode,xspan,y0);

firstode(x,y);

(12)

Solving systems of first

Example 3

function example3 tspan = [0 12];

tspan = [0 12];

y0 = [0; 1; 1];

% Solve the problem using ode45 ode45(@f,tspan,y0);

% --- function dydt = f(t,y)

dydt = [ y(2)*y(3) -y(1)*y(3)

-0.51*y(1)*y(2) ];

Solving systems of first-order ODEs

0.6 0.8 1

0 2 4 6 8 10 12

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4

(13)

… Solving systems of first

To define each curve

function example3 tspan = [0 12];

y0 = [0; 1; 1];

% Solve the problem using ode45 [t,y] = ode45(@f,tspan,y0);

plot(t,y(:,1),':r',t,y(:,2),'-.',t,y(:, legend('y_1','y_2','y_3',3)

% --- function dydt = f(t,y)

dydt = [ y(2)*y(3) -y(1)*y(3)

-0.51*y(1)*y(2) ];

systems of first-order ODEs

0.6 0.8 1

(:,3))

0 2 4 6 8 10 12

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6

y1 y2 y3

(14)

Boundary Value Problems

sol = bvp4c(odefun,bcfun,solinit

Value Problems

odefun,bcfun,solinit)

(15)

Delay Differential Equations

Functions

dde23 Solve delay differential equations (DDEs) with constant delays ddesd Solve delay differential equations (DDEs) with general delays ddesd Solve delay differential equations (DDEs) with general delays ddensd Solve delay differential equations (DDEs) of neutral type

Equations

Solve delay differential equations (DDEs) with constant delays

Solve delay differential equations (DDEs) with general delays

Solve delay differential equations (DDEs) with general delays

Solve delay differential equations (DDEs) of neutral type

(16)

dde23

Solve delay differential equations (DDEs) with constant delays sol = dde23(ddefun,lags,history,tspan

Example 4

Solve delay differential equations (DDEs) with constant delays ddefun,lags,history,tspan)

for t ≤ 0.

(17)

function ddex1

sol = dde23(@ddex1de,[1, 0.2],@ddex1hist,[

figure;

plot(sol.x,sol.y)

title('An example of Wille'' and Baker.' xlabel('time t');

ylabel('solution y');

function s = ddex1hist(t)

% Constant history function for DDEX1.

function dydt = ddex1de(t,y,Z)

% Differential equations function for DDEX ylag1 = Z(:,1);

ylag2 = Z(:,2);

dydt = [ ylag1(1)

ylag1(1) + ylag2(2) y(2) ];

s = ones(3,1);

hist,[0, 5]);

'' and Baker.');

% Differential equations function for DDEX1.

(18)
(19)

Partial Differential Equations (

pdepe

Solve initial-boundary value problems for parabolic-elliptic PDEs in

Syntax

sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan)

sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan,OPTIONS

[sol,tsol,sole,te,ie] = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan,OPTIONS

Partial Differential Equations (pde)

elliptic PDEs in 1-D

m,pdefun,icfun,bcfun,xmesh,tspan,OPTIONS)

m,pdefun,icfun,bcfun,xmesh,tspan,OPTIONS)

(20)

Arguments

m A parameter corresponding to the symmetry of the problem.

cylindrical =1, or spherical = 2.

pdefun A handle to a function that defines the components of the PDE.

icfun A handle to a function that defines the initial conditions.

sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan

bcfun A handle to a function that defines the boundary conditions.

xmesh A vector [x0, x1, ..., xn], x0 < x1 < ... < xn.

tspan A vector [t0, t1, ..., tf] , t0 < t1 < ... < tf.

options Some OPTIONS of the underlying ODE solver are

A parameter corresponding to the symmetry of the problem. m can be slab = 0,

A handle to a function that defines the components of the PDE.

A handle to a function that defines the initial conditions.

m,pdefun,icfun,bcfun,xmesh,tspan)

A handle to a function that defines the boundary conditions.

.

of the underlying ODE solver are available, See odeset for details.

(21)

Description

PDE

IC

BC

(22)
(23)

Example 1.

This example illustrates the straightforward formulation, computation, and plotting of the solution of a single PDE.

Single PDE

example illustrates the straightforward formulation, computation, and plotting of the

(24)

function pdex1 m = 0;

x = linspace(0,1,20);

t = linspace(0,2,5);

sol = pdepe(m,@pdecfs,@ic,@bc,x,t);

u = sol(:,:,1);

% A solution profile can also be illuminating.

figure;

plot(x,u(end,:),'o',x,exp(-t(end))*sin(pi*x));

title('Solutions at t = 2.');

legend('Numerical, 20 mesh points','Analytical', xlabel('Distance x');

ylabel('u(x,2)');

function [c,f,s] = pdecfs(x,t,u,DuDx) c = pi^2;

f = DuDx;

s = 0;

% ---

function u0 = ic(x) u0 = sin(pi*x);

,0);

% ---

function [pl,ql,pr,qr] = bc(xl,ul,xr,ur,t pl = ul;

ql = 0;

pr = pi * exp(-t);

qr = 1;

(25)

0.06 0.08 0.1 0.12 0.14

Solutions at t

(x,2)

Numerical Analytical

0 0.1 0.2 0.3 0.4

-0.02 0 0.02 0.04

Distance x

u(x

Solutions at t = 2.

Numerical, 20 mesh points Analytical

0.5 0.6 0.7 0.8 0.9 1

Distance x

(26)

References

1. http://www.mathworks.com/help/matlab/ref/pdepe.html ://www.mathworks.com/help/matlab/ref/pdepe.html

(27)

ﰐﺪﻔﺘﺳﺇ ﱐﻮﻜﺗ ﻥﺍ ﲎﲤﺍ

Referensi

Dokumen terkait

In the present paper we obtain sufficient conditions for the oscillation of bounded solutions of a class of impulsive differential equations of second order with a constant delay

In contrast with the stability of these equations, there are no absolute (delay- independent) oscillation criteria for first order delay differential equations.. Although

Oscillatory behaviour of higher order neutral type nonlinear forced differential equation with oscillating coefficients.. Oscillation Theory of Delay Differential Equations:

• Introduction to MATLAB • Root Approximations • Sinusoids and Complex Numbers • Matrices and Determinants • Review of Differential Equations • Fourier, Taylor, and

Ordinary differential equations are used to model continuous dynamical systems later in the book.. The bulk of this chapter is concerned with a linear discrete dynamical system that

SOME THE EQUATIONS WITH RESPECT TO THE NEW VARIABLES SYSTEM OF EQUATIONS TO SOLVE Ahmedova Gavhar Kokand State Pedagogical Institute Meliboyeva Yulduzxon Kokand State Pedagogical

Delay-Dependent Stabilization of Linear Input-Delayed Systems with Composite State-Derivative Feedback: Constant and Time-Varying Delays Abstract: This paper considers stability

Substitutions - Picard's methods - Linear differential equations of higher-order - Homogeneous equations with constant coefficients, Method of undetermined coefficients, Method of