Solving PDE problem with ODE functions in MATLAB®

Solving PDE problem with ODE functions in MATLAB®

PDE is Partial Differential Equation for short. Similarly, ODE is Ordinary Differential Equation for short. There are several ODE functions in MATLAB®1 using numerical methods to approximate the result of ODE problems.

ODE functions in MATLAB

ODE functions in MATLAB are list as follow:

solver Problem type Order of Accuracy When to use
ode45 Nonstiff Medium Most of the time. This should be the first solver you try.
ode15s stiff Low to medium If ode45 is slow because the problem is stiff.

Table 1. ODE function list in MATLAB

Usage of ode45 and ode15s

As is illustrated in MATLAB help and documentations, ode45 and ode15s are similar in usage and basic structure, while the benefits and efficiency may differ when applied to different problems. The following is taking ode45 for instance, followed by comparison between ode45 and ode15s.

Basic structure of ode45

Basic structure of ode45 is

% basic structure of ode45 in MATLAB
[TOUT,YOUT] = ode45(ODEFUN,TSPAN,Y0);

An example is as follow:

[t, y] = ode45(@func, [0 4], 1);

where func refer to a differential function

dydt=yt+1

as is shown in MATLAB script

function dy = func(t, y)
% demo function of ode45
dy = y/t + 1; % function y with regard to t
end

Then, we plot this figure out.

demo function of ode45

Figure 1. Demo function of ode45

Let we think of some situation that parameters are given to ODEFUN. We take func for instance.
Consider the differential function with two parameters a and b ,

dydt=ayt+b

the function in MATLAB script is supposed to be

function dy = func(t, y, a, b)
% demo function of ode45
dy = a*y/t + b; % function y with regard to t
end

which calls for adapt to this function with parameters.

Parameter of ODEFUN in ode45

Let us look into ODEFUN in ode45 function, we can see the original usage of ODEFUN goes to @(t,y) func(t,y) which is shorted by @func with default no extra parameters. And in such case that parameters are demanded, we can use

[t, y] = ode45(@(t,y) func(t,y,a,b), [0 4], 1);

with a and b defined ahead.
And we can do parameter sweeping to see how parameters a and b influence the distribution of the differential function.

parameter sweep of a and b

Figure 2. Parameter sweep of a and b

Nonstiff and stiff problem

As is shown in Table 1, ode45 is applied to solve nonstiff problems, while ode15s is applied to solve stiff problems. So what is a stiff problem?

In mathematics, a stiff equation is a differential equation for which certain numerical methods for solving the equation are numerically unstable, unless the step size is taken to be extremely small. It has proven difficult to formulate a precise definition of stiffness, but the main idea is that the equation includes some terms that can lead to rapid variation in the solution. – [Wikipedia Stiff equation]

Thus we can see a nonstiff problem is the one that is not stiff. The following examples which is based on MATLAB documentation from Department of Radio Engineering, Czech Technical University will show the characteristic of nonstiff and stiff problems.

Nonstiff problem using ode45

A typical example in MATLAB is rigidode, which is first illustrated in Shampine and Gordon’s book Computer Solution of Ordinary Differential Equations, 1975 solves the Euler equaions of a rigid body without external forces.

y1=y2y3,y2=y1y3,y3=0.51y1y2.

The solution of the ploblem is shown in rigidode in MATLAB. The simplified implement is as follow:

tspan = [0 12];
y0 = [0; 1; 1];
% solve the problem using ODE45
figure;
ode45(@f,tspan,y0);

function dydt = f(t,y)
dydt = [      y(2)*y(3)
             -y(1)*y(3)
        -0.51*y(1)*y(2) ];

As is shown in this MATLAB script, ode45 is used to solve this equation numerically. If we just type rigidode in MATLAB command line, the following figure will appear.

rigidode in MATLAB using <code>ode45</code>

Figure 3. rigidode in MATLAB using ode45

Stiff problem using ode15s

Van der Pol equation is a typical stiff problem. The differential equations are as follow

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值