Matlab偏微分方程求解方法

Matlab偏微分方程求解方法
Matlab偏微分方程求解方法

Matlab 偏微分方程求解方法

目录:

§1 Function Summary on page 10-87

§2 Initial Value Problems on page 10-88

§3 PDE Solver on page 10-89

§4 Integrator Options on page 10-92

§5 Examples” on page 10-93

§1 Function Summary

1.1 PDE Solver” on page 10-87

1,2 PDE Helper Functi on” on page 10-87

1.3 PDE Solver

This is the MATLAB PDE solver.

PDE Helper Function

§2 Initial Value Problems

pdepe solves systems of parabolic and elliptic PDEs in one spatial variable x and time t, of the form

)x

u ,u ,t ,x (s ))x u ,u ,t ,x (f x (x x t u )x u ,u ,t ,x (c m m ??+????=????- (10-2) The PDEs hold for b x a ,t t t f 0≤≤≤≤.The interval [a, b] must be finite. m

can be 0, 1, or 2, corresponding to slab, cylindrical, or spherical symmetry,respectively. If m > 0, thena ≥0 must also hold.

In Equation 10-2,)x /u ,u ,t ,x (f ?? is a flux term and )x /u ,u ,t ,x (s ?? is a source term. The flux term must depend on x /u ??. The coupling of the partial derivatives with respect to time is restricted to multiplication by a diagonal matrix )x /u ,u ,t ,x (c ??. The diagonal elements of this matrix are either identically zero or positive. An element that is identically zero corresponds to an elliptic equation and otherwise to a parabolic equation. There must be at least one parabolic equation. An element of c that corresponds to a parabolic equation can vanish at isolated values of x if they are mesh points.Discontinuities in c and/or s due to material interfaces are permitted provided that a mesh point is placed at each interface.

At the initial time t = t0, for all x the solution components satisfy initial conditions of the form

)x (u )t ,x (u 00= (10-3)

At the boundary x = a or x = b, for all t the solution components satisfy a boundary condition of the form

0)x

u ,u ,t ,x (f )t ,x (q )u ,t ,x (p =??+ (10-4) q(x, t) is a diagonal matrix with elements that are either identically zero or never zero. Note that the boundary conditions are expressed in terms of the f rather than partial derivative of u with respect to x-x /u ??. Also, of

the two coefficients, only p can depend on u.

§3 PDE Solver

3.1 The PDE Solver

The MATLAB PDE solver, pdepe, solves initial-boundary value problems for systems of parabolic and elliptic PDEs in the one space variable x and time t.There must be at least one parabolic equation in the system.

The pdepe solver converts the PDEs to ODEs using a second-order accurate spatial discretization based on a fixed set of user-specified nodes. The discretization method is described in [9]. The time integration is done with ode15s. The pdepe solver exploits the capabilities of ode15s for solving the differential-algebraic equations that arise when Equation 10-2 contains elliptic equations, and for handling Jacobians with a specified sparsity pattern. ode15s changes both the time step and the formula dynamically.

After discretization, elliptic equations give rise to algebraic equations. If the elements of the initial conditions vector that correspond to elliptic equations are not “consistent” with the discretization, pdepe tries to adjust them before eginning the time integration. For this reason, the solution returned for the initial time may have a discretization error comparable to that at any other time. If the mesh is sufficiently fine, pdepe can find consistent initial conditions close to the given ones. If pdepe displays a

message that it has difficulty finding consistent initial conditions, try refining the mesh. No adjustment is necessary for elements of the initial conditions vector that correspond to parabolic equations.

PDE Solver Syntax

The basic syntax of the solver is:

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

Note Correspondences given are to terms used in “Initial Value Problems” on page 10-88.

The input arguments are

m: Specifies the symmetry of the problem. m can be 0 =slab, 1 = cylindrical, or 2 = spherical. It corresponds to m in Equation 10-2. pdefun: Function that defines the components of the PDE. It

computes the terms f,c and s in Equation 10-2, and has the form

[c,f,s] = pdefun(x,t,u,dudx)

where x and t are scalars, and u and dudx are vectors that approximate the solution and its partial derivative with respect to . c, f, and s are column vectors. c stores the diagonal elements of the matrix .

icfun: Function that evaluates the initial conditions. It has the form

u = icfun(x)

When called with an argument x, icfun evaluates and returns the initial values of the solution components at x in the column vector u.

bcfun:Function that evaluates the terms and of the boundary conditions. It

has the form

[pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t)

where ul is the approximate solution at the left boundary xl = a and ur is the approximate solution at the right boundary xr = b. pl and ql are column vectors corresponding to p and the diagonal of q evaluated at xl. Similarly, pr and qr correspond to xr. When m>0 and a = 0, boundedness of the solution near x = 0 requires that the f vanish at a = 0. pdepe imposes this boundary condition automatically and it ignores values returned in pl and ql.

xmesh:Vector [x0, x1, ..., xn] specifying the points at which a numerical solution is requested for every value in tspan. x0 and xn correspond to a and b , respectively. Second-order approximation to the solution is made on the mesh specified in xmesh. Generally, it is best to use closely spaced mesh points where the solution changes rapidly. pdepe does not select the mesh in automatically. You must provide an appropriate fixed mesh in xmesh. The cost depends strongly on the length of xmesh. When , it is not necessary to use a fine mesh near to x=0 account for the coordinate singularity.

The elements of xmesh must satisfy x0 < x1 < ... < xn.

The length of xmesh must be ≥3.

tspan:Vector [t0, t1, ..., tf] specifying the points at which a solution is requested for every value in xmesh. t0 and tf correspond to

t and f t,

respectively.

pdepe performs the time integration with an ODE solver that selects both the time step and formula dynamically. The solutions at the points specified in tspan are obtained using the natural continuous extension of the integration formulas. The elements of tspan merely specify where you want answers and the cost depends weakly on the length of tspan.

The elements of tspan must satisfy t0 < t1 < ... < tf.

The length of tspan must be ≥3.

The output argument sol is a three-dimensional array, such that

?sol(:,:,k) approximates component k of the solution .

?sol(i,:,k) approximates component k of the solution at time tspan(i) and mesh points xmesh(:).

?sol(i,j,k) approximates component k of the solution at time tspan(i) and the mesh point xmesh(j).

4.2 PDE Solver Options

For more advanced applications, you can also specify as input arguments solver options and additional parameters that are passed to the PDE functions.

options:Structure of optional parameters that change the default integration properties. This is the seventh input argument.

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

See “Integrator Options” on page 10-92 for more information.

Integrator Options

The default integration properties in the MATLAB PDE solver are selected to handle common problems. In some cases, you can improve solver performance by overriding these defaults. You do this by supplying pdepe with one or more property values in an options structure.

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

Use odeset to create the options structure. Only those options of the underlying ODE solver shown in the following table are available for pdepe.

The defaults obtained by leaving off the input argument options are generally satisfactory. “Integrator Options” on page 10-9 tells you how to create the structure and describes the properties.

PDE Properties

§4 Examples

?“Single PDE” on page 10-93

?“System of PDEs” on page 10-98

?“Additional Examples” on page 10-103

1.Single PDE

? “Solving the Equation” on page 10-93

? “Evaluating the Solution” on page 10-98

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

222

x u t u ??=??π This equation holds on an interval 1x 0≤≤ for times t ≥ 0. At 0t = the solution satisfies the initial condition x sin )0,x (u π=.At 0x =and 1x = , the solution satisfies the boundary conditions

0)t ,1(x

u e ,0)t ,0(u t =??+π=- Note The demo pdex1 contains the complete code for this example. The demo uses subfunctions to place all functions it requires in a single MATLAB file.To run the demo type pdex1 at the command line. See “PDE Solver Syntax” on page 10-89 for more information. 1 Rewrite the PDE. Write the PDE in the form

)x

u ,u ,t ,x (s ))x u ,u ,t ,x (f x (x x t u )x u ,u ,t ,x (c m m ??+????=????- This is the form shown in Equation 10-2 and expected by pdepe. For this example, the resulting equation is

0x u x x x t u 002+??

? ??????=??π with parameter and the terms 0m = and the term

0s ,x

u f ,c 2=??=π=

2 Code the PDE. Once you rewrite the PDE in the form shown above (Equation 10-2) and identify the terms, you can code the PDE in a function that pdepe can use. The function must be of the form

[c,f,s] = pdefun(x,t,u,dudx)

where c, f, and s correspond to the f ,c and s terms. The code below computes c, f, and s for the example problem.

function [c,f,s] = pdex1pde(x,t,u,DuDx)

c = pi^2;

f = DuDx;

s = 0;

3 Code the initial conditions function. You must code the initial conditions in a function of the form

u = icfun(x)

The code below represents the initial conditions in the function pdex1ic. Partial Differential Equations

function u0 = pdex1ic(x)

u0 = sin(pi*x);

4 Code the boundary conditions function. You must also code the boundary conditions in a function of the form

[pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t) The boundary conditions, written in the same form as Equation 10-4, are

0x ,0)t ,0(x u .0)t ,0(u ==??+

and

1x ,0)t ,1(x

u .1e t ==??+π- The code below evaluates the components )u ,t ,x (p and )u ,t ,x (q of the boundary conditions in the function pdex1bc.

function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)

pl = ul;

ql = 0;

pr = pi * exp(-t);

qr = 1;

In the function pdex1bc, pl and ql correspond to the left boundary conditions (x=0 ), and pr and qr correspond to the right boundary condition (x=1).

5 Select mesh points for the solution. Before you use the MATLAB PDE solver, you need to specify the mesh points at which you want pdepe to evaluate the solution. Specify the points as vectors t and x.

The vectors t and x play different roles in the solver (see “PDE Solver” on page 10-89). In particular, the cost and the accuracy of the solution depend strongly on the length of the vector x. However, the computation is much less sensitive to the values in the vector t.

10 Calculus

This example requests the solution on the mesh produced by 20 equally spaced points from the spatial interval [0,1] and five values of t from the

time interval [0,2].

x = linspace(0,1,20);

t = linspace(0,2,5);

6 Apply the PDE solver. The example calls pdepe with m = 0, the functions pdex1pde, pdex1ic, and pdex1bc, and the mesh defined by x and t at which pdepe is to evaluate the solution. The pdepe function returns the numerical solution in a three-dimensional array sol, where

sol(i,j,k) approximates the kth component of the solution,

u, evaluated at

k

t(i) and x(j).

m = 0;

sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);

This example uses @ to pass pdex1pde, pdex1ic, and pdex1bc as function handles to pdepe.

Note See the function_handle (@), func2str, and str2func reference pages, and the @ section of MATLAB Programming Fundamentals for information about function handles.

7 View the results. Complete the example by displaying the results:

a Extract and display the first solution component. In this example, the solution has only one component, but for illustrative purposes, the example “extracts” it from the three-dimensional array. The surface plot shows the behavior of the solution.

u = sol(:,:,1);

surf(x,t,u)

title('Numerical solution computed with 20 mesh points')

xlabel('Distance x')

ylabel('Time t')

Distance x Numerical solution computed with 20 mesh points.

Time t

b Display a solution profile at f t , the final value of . In this example,

2t t f ==.

figure

plot(x,u(end,:))

title('Solution at t = 2')

xlabel('Distance x')

ylabel('u(x,2)')

Solutions at t = 2.

Distance x u (x ,2)

Evaluating the Solution. After obtaining and plotting the solution above, you might be interested in a solution profile for a particular value of t, or the time changes of the solution at a particular point x. The kth column u(:,k)(of the solution extracted in step 7) contains the time history of the solution at x(k). The jth row u(j,:) contains the solution profile at t(j). Using the vectors x and u(j,:), and the helper function pdeval, you can evaluate the solution u and its derivative at any set of points xout

[uout,DuoutDx] = pdeval(m,x,u(j,:),xout)

The example pdex3 uses pdeval to evaluate the derivative of the solution at xout = 0. See pdeval for details. 2. System of PDEs

This example illustrates the solution of a system of partial differential equations. The problem is taken from electrodynamics. It has boundary layers at both ends of the interval, and the solution changes rapidly for small .

The PDEs are

)u u (F x

u 017.0t u )u u (F x u 024.0t u 212222212121-+??=??--??=?? where )y 46.11exp()y 73.5exp()y (F --=. The equations hold on an interval 1x 0≤≤ for times 0t ≥.

The solution satisfies the initial conditions

0)0,x (u ,1)0,x (u 21≡≡ and boundary conditions

0)t ,1(x

u ,0)t ,1(u ,0)t ,0(u ,0)t ,0(x u 2121=??===?? Note The demo pdex4 contains the complete code for this example. The demo uses subfunctions to place all required functions in a single MATLAB file. To run this example type pdex4 at the command line. 1 Rewrite the PDE. In the form expected by pdepe, the equations are

?????

?---+????????????=??????????????)u u (F )u u (F )x /u 170.0)x /u (024.0x u u t *.1121212121 The boundary conditions on the partial derivatives of have to be written in terms of the flux. In the form expected by pdepe, the left boundary condition is

??

????=????????????????+??????00)x /u (170.0)x /u (024.0*.01u 0212

and the right boundary condition is

??

????=????????????????+??????-00)x /u (170.0)x /u (024.0*.1001u 211

2 Code the PDE. After you rewrite the PDE in the form shown above, you can code it as a function that pdepe can use. The function must be of the form

[c,f,s] = pdefun(x,t,u,dudx)

where c, f, and s correspond to the , , and terms in Equation 10-2. function [c,f,s] = pdex4pde(x,t,u,DuDx)

c = [1; 1];

f = [0.024; 0.17] .* DuDx;

y = u(1) - u(2);

F = exp(5.73*y)-exp(-11.47*y);

s = [-F; F];

3 Code the initial conditions function. The initial conditions function must be of the form

u = icfun(x)

The code below represents the initial conditions in the function pdex4ic. function u0 = pdex4ic(x);

u0 = [1; 0];

4 Code the boundary conditions function. The boundary conditions functions must be of the form

[pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t)

The code below evaluates the components p(x,t,u) and q(x,t) (Equation 10-4) of the boundary conditions in the function pdex4bc.

function [pl,ql,pr,qr] = pdex4bc(xl,ul,xr,ur,t)

pl = [0; ul(2)];

ql = [1; 0];

pr = [ur(1)-1; 0];

qr = [0; 1];

5 Select mesh points for the solution. The solution changes rapidly for small t . The program selects the step size in time to resolve this sharp change, but to see this behavior in the plots, output times must be selected accordingly. There are boundary layers in the solution at both ends of [0,1], so mesh points must be placed there to resolve these sharp changes. Often some experimentation is needed to select the mesh that reveals the behavior of the solution.

x = [0 0.005 0.01 0.05 0.1 0.2 0.5 0.7 0.9 0.95 0.99 0.995 1];

t = [0 0.005 0.01 0.05 0.1 0.5 1 1.5 2];

6 Apply the PDE solver. The example calls pdepe with m = 0, the functions pdex4pde, pdex4ic, and pdex4bc, and the mesh defined by x and t at which pdepe is to evaluate the solution. The pdepe function returns the numerical solution in a three-dimensional array sol, where

sol(i,j,k) approximates the kth component of the solution, μk, evaluated at t(i) and x(j).

m = 0;

sol = pdepe(m,@pdex4pde,@pdex4ic,@pdex4bc,x,t);

7 View the results. The surface plots show the behavior of the solution components.

u1 = sol(:,:,1);

u2 = sol(:,:,2);

figure

surf(x,t,u1)

title('u1(x,t)')

xlabel('Distance x')

其输出图形为

Distance x u1(x,t)

Time t

figure

surf(x,t,u2)

title('u2(x,t)')

xlabel('Distance x')

ylabel('Time t')

Distance x u2(x,t)

Time t

Additional Examples

The following additional examples are available. Type

edit examplename to view the code and

examplename

to run the example.

(完整版)偏微分方程的MATLAB解法

引言 偏微分方程定解问题有着广泛的应用背景。人们用偏微分方程来描述、解释或者预见各种自然现象,并用于科学和工程技术的各个领域fll。然而,对于广大应用工作者来说,从偏微分方程模型出发,使用有限元法或有限差分法求解都要耗费很大的工作量,才能得到数值解。现在,MATLAB PDEToolbox已实现对于空间二维问题高速、准确的求解过程。 偏微分方程 如果一个微分方程中出现的未知函数只含一个自变量,这个方程叫做常微分方程,也简称微分方程;如果一个微分方程中出现多元函数的偏导数,或者说如果未知函数和几个变量有关,而且方程中出现未知函数对几个变量的导数,那么这种微分方程就是偏微分方程。 常用的方法有变分法和有限差分法。变分法是把定解问题转化成变分问题,再求变分问题的近似解;有限差分法是把定解问题转化成代数方程,然后用计算机进行计算;还有一种更有意义的模拟法,它用另一个物理的问题实验研究来代替所研究某个物理问题的定解。虽然物理现象本质不同,但是抽象地表示在数学上是同一个定解问题,如研究某个不规则形状的物体里的稳定温度分布问题,由于求解比较困难,可作相应的静电场或稳恒电流场实验研究,测定场中各处的电势,从而也解决了所研究的稳定温度场中的温度分布问题。 随着物理科学所研究的现象在广度和深度两方面的扩展,偏微分方程的应用范围更广泛。从数学自身的角度看,偏微分方程的求解促使数学在函数论、变分法、级数展开、常微分方程、代数、微分几何等各方面进行发展。从这个角度说,偏微分方程变成了数学的中心。

一、MATLAB方法简介及应用 1.1 MATLAB简介 MATLAB是美国MathWorks公司出品的商业数学软件,用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境,主要包括MATLAB和Simulink两大部分。 1.2 Matlab主要功能 数值分析 数值和符号计算 工程与科学绘图 控制系统的设计与仿真 数字图像处理 数字信号处理 通讯系统设计与仿真 财务与金融工程 1.3 优势特点 1) 高效的数值计算及符号计算功能,能使用户从繁杂的数学运算分析中解脱出来; 2) 具有完备的图形处理功能,实现计算结果和编程的可视化; 3) 友好的用户界面及接近数学表达式的自然化语言,使学者易于学习和掌握; 4) 功能丰富的应用工具箱(如信号处理工具箱、通信工具箱等) ,

Matlab求解微分方程(组)及偏微分方程(组)

第四讲 Matlab 求解微分方程(组) 理论介绍:Matlab 求解微分方程(组)命令 求解实例:Matlab 求解微分方程(组)实例 实际应用问题通过数学建模所归纳得到的方程,绝大多数都是微分方程,真正能得到代数方程的机会很少.另一方面,能够求解的微分方程也是十分有限的,特别是高阶方程和偏微分方程(组).这就要求我们必须研究微分方程(组)的解法:解析解法和数值解法. 一.相关函数、命令及简介 1.在Matlab 中,用大写字母D 表示导数,Dy 表示y 关于自变量的一阶导数,D2y 表示y 关于自变量的二阶导数,依此类推.函数dsolve 用来解决常微分方程(组)的求解问题,调用格式为: X=dsolve(‘eqn1’,’eqn2’,…) 函数dsolve 用来解符号常微分方程、方程组,如果没有初始条件,则求出通解,如果有初始条件,则求出特解. 注意,系统缺省的自变量为t 2.函数dsolve 求解的是常微分方程的精确解法,也称为常微分方程的符号解.但是,有大量的常微分方程虽然从理论上讲,其解是存在的,但我们却无法求出其解析解,此时,我们需要寻求方程的数值解,在求常微分方程数值解方面,MATLAB 具有丰富的函数,我们将其统称为solver ,其一般格式为: [T,Y]=solver(odefun,tspan,y0) 说明:(1)solver 为命令ode45、ode23、ode113、ode15s 、ode23s 、ode23t 、ode23tb 、ode15i 之一. (2)odefun 是显示微分方程'(,)y f t y =在积分区间tspan 0[,]f t t =上从0t 到f t

Matlab求解微分方程(组)及偏微分方程(组)

第四讲Matlab求解微分方程(组) 理论介绍:Matlab求解微分方程(组)命令 求解实例:Matlab求解微分方程(组)实例 实际应用问题通过数学建模所归纳得到得方程,绝大多数都就是微分方程,真正能得到代数方程得机会很少、另一方面,能够求解得微分方程也就是十分有限得,特别就是高阶方程与偏微分方程(组)、这就要求我们必须研究微分方程(组)得解法:解析解法与数值解法、 一.相关函数、命令及简介 1、在Matlab中,用大写字母D表示导数,Dy表示y关于自变量得一阶导数,D2y 表示y关于自变量得二阶导数,依此类推、函数dsolve用来解决常微分方程(组)得求解问题,调用格式为: X=dsolve(‘eqn1’,’eqn2’,…) 函数dsolve用来解符号常微分方程、方程组,如果没有初始条件,则求出通解,如果有初始条件,则求出特解、 注意,系统缺省得自变量为t 2、函数dsolve求解得就是常微分方程得精确解法,也称为常微分方程得符号解、但就是,有大量得常微分方程虽然从理论上讲,其解就是存在得,但我们却无法求出其解析解,此时,我们需要寻求方程得数值解,在求常微分方程数值解方 面,MATLAB具有丰富得函数,我们将其统称为solver,其一般格式为: [T,Y]=solver(odefun,tspan,y0) 说明:(1)solver为命令ode45、ode23、ode113、ode15s、ode23s、ode23t、ode23tb、ode15i之一、 (2)odefun就是显示微分方程在积分区间tspan上从到用初始条件求解、 (3)如果要获得微分方程问题在其她指定时间点上得解,则令tspan(要求就是单调得)、 (4)因为没有一种算法可以有效得解决所有得ODE问题,为此,Matlab提供了多种求解器solver,对于不同得ODE问题,采用不同得solver、 表1 Matlab中文本文件读写函数

MatlabPDE工具箱有限元法求解偏微分方程

在科学技术各领域中,有很多问题都可以归结为偏微分方程问题。在物理专业的力学、热学、电学、光学、近代物理课程中都可遇见偏微分方程。 偏微分方程,再加上边界条件、初始条件构成的数学模型,只有在很特殊情况下才可求得解析解。随着计算机技术的发展,采用数值计算方法,可以得到其数值解。 偏微分方程基本形式 而以上的偏微分方程都能利用PDE工具箱求解。 PDE工具箱 PDE工具箱的使用步骤体现了有限元法求解问题的基本思路,包括如下基本步骤: 1) 建立几何模型 2) 定义边界条件 3) 定义PDE类型和PDE系数 4) 三角形网格划分

5) 有限元求解 6) 解的图形表达 以上步骤充分体现在PDE工具箱的菜单栏和工具栏顺序上,如下 具体实现如下。 打开工具箱 输入pdetool可以打开偏微分方程求解工具箱,如下 首先需要选择应用模式,工具箱根据实际问题的不同提供了很多应用模式,用户可以基于适

当的模式进行建模和分析。 在Options菜单的Application菜单项下可以做选择,如下 或者直接在工具栏上选择,如下 列表框中各应用模式的意义为: ① Generic Scalar:一般标量模式(为默认选项)。 ② Generic System:一般系统模式。 ③ Structural Mech.,Plane Stress:结构力学平面应力。

④ Structural Mech.,Plane Strain:结构力学平面应变。 ⑤ Electrostatics:静电学。 ⑥ Magnetostatics:电磁学。 ⑦ Ac Power Electromagnetics:交流电电磁学。 ⑧ Conductive Media DC:直流导电介质。 ⑨ Heat Tranfer:热传导。 ⑩ Diffusion:扩散。 可以根据自己的具体问题做相应的选择,这里要求解偏微分方程,故使用默认值。此外,对于其他具体的工程应用模式,此工具箱已经发展到了Comsol Multiphysics软件,它提供了更强大的建模、求解功能。 另外,可以在菜单Options下做一些全局的设置,如下 l Grid:显示网格 l Grid Spacing…:控制网格的显示位置 l Snap:建模时捕捉网格节点,建模时可以打开 l Axes Limits…:设置坐标系范围 l Axes Equal:同Matlab的命令axes equal命令

有限差分法求解偏微分方程MATLAB

南京理工大学 课程考核论文 课程名称:高等数值分析 论文题目:有限差分法求解偏微分方程姓名:罗晨 学号: 成绩: 有限差分法求解偏微分方程

一、主要内容 1.有限差分法求解偏微分方程,偏微分方程如一般形式的一维抛物线型方程: 22(,)()u u f x t t x αα??-=??其中为常数 具体求解的偏微分方程如下: 22001 (,0)sin()(0,)(1,)00 u u x t x u x x u t u t t π???-=≤≤?????? =??? ==≥??? 2.推导五种差分格式、截断误差并分析其稳定性; 3.编写MATLAB 程序实现五种差分格式对偏微分方程的求解及误差分析; 4.结论及完成本次实验报告的感想。 二、推导几种差分格式的过程: 有限差分法(finite-difference methods )是一种数值方法通过有限个微分方程近似求导从而寻求微分方程的近似解。有限差分法的基本思想是把连续的定解区域用有限个离散点构成的网格来代替;把连续定解区域上的连续变量的函数用在网格上定义的离散变量函数来近似;把原方程和定解条件中的微商用差商来近似,积分用积分和来近似,于是原微分方程和定解条件就近似地代之以代数方程组,即有限差分方程组,解此方程组就可以得到原问题在离散点上的近似解。 推导差分方程的过程中需要用到的泰勒展开公式如下: ()2100000000()()()()()()()......()(()) 1!2!! n n n f x f x f x f x f x x x x x x x o x x n +'''=+-+-++-+- (2-1) 求解区域的网格划分步长参数如下:

Matlab求解微分方程(组)及偏微分方程(组)

第四讲 Matlab 求解微分方程(组) 理论介绍:Matlab 求解微分方程(组)命令 求解实例:Matlab 求解微分方程(组)实例 实际应用问题通过数学建模所归纳得到的方程,绝大多数都是微分方程,真正能得到代数方程的机会很少.另一方面,能够求解的微分方程也是十分有限的,特别是高阶方程和偏微分方程(组).这就要求我们必须研究微分方程(组)的解法:解析解法和数值解法. 一.相关函数、命令及简介 1.在Matlab 中,用大写字母D 表示导数,Dy 表示y 关于自变量的一阶导数,D2y 表示y 关于自变量的二阶导数,依此类推.函数dsolve 用来解决常微分方程(组)的求解问题,调用格式为: X=dsolve(‘eqn1’,’eqn2’,…) 函数dsolve 用来解符号常微分方程、方程组,如果没有初始条件,则求出通解,如果有初始条件,则求出特解. 注意,系统缺省的自变量为t 2.函数dsolve 求解的是常微分方程的精确解法,也称为常微分方程的符号解.但是,有大量的常微分方程虽然从理论上讲,其解是存在的,但我们却无法求出其解析解,此时,我们需要寻求方程的数值解,在求常微分方程数值解方面,MATLAB 具有丰富的函数,我们将其统称为solver ,其一般格式为: [T,Y]=solver(odefun,tspan,y0) 说明:(1)solver 为命令ode45、ode23、ode113、ode15s 、ode23s 、ode23t 、ode23tb 、ode15i 之一. (2)odefun 是显示微分方程'(,)y f t y =在积分区间tspan 0[,]f t t =上从0t 到f t 用初始条件0y 求解. (3)如果要获得微分方程问题在其他指定时间点012,,, ,f t t t t 上的解,则令 tspan 012[,,,]f t t t t =(要求是单调的). (4)因为没有一种算法可以有效的解决所有的ODE 问题,为此,Matlab 提供

《偏微分方程概述及运用matlab求解偏微分方程常见问题》要点

北京航空航天大学 偏微分方程概述及运用matlab求解微分方 程求解常见问题 姓名徐敏 学号57000211 班级380911班 2011年6月

偏微分方程概述及运用matlab求解偏微分 方程常见问题 徐敏 摘要偏微分方程简介,matlab偏微分方程工具箱应用简介,用这个工具箱解方程的过程是:确定待解的偏微分方程;确定边界条件;确定方程所在域的几何形状;划分有限元;解方程 关键词MATLAB 偏微分方程程序 如果一个微分方程中出现的未知函数只含有一个自变量,这个方程叫做常微分方程,也简称微分方程:如果一个微分方程中出现多元函数的偏导数,或者说如果未知函数和几个变量有关,而且方程中出现未知函数对几个变量的导数,那么这种微分方程就是偏微分方程。 一,偏微分方程概述 偏微分方程是反映有关的未知变量关于时间的导数和关于空间变量的导数之间制约关系的等式。许多领域中的数学模型都可以用偏微分方程来描述,很多重要的物理、力学等学科的基本方程本身就是偏微分方程。早在微积分理论刚形成后不久,人们就开始用偏微分方程来描述、解释或预见各种自然现象,并将所得到的研究方法和研究成果运用于各门科学和工程技术中,不断地取得了显著的成效,显示了偏微分方程对于人类认识自然界基本规律的重要性。逐渐地,以物

理、力学等各门科学中的实际问题为背景的偏微分方程的研究成为传统应用数学中的一个最主要的内容,它直接联系着众多自然现象和实际问题,不断地提出和产生出需要解决的新课题和新方法,不断地促进着许多相关数学分支(如泛函分析、微分几何、计算数学等)的发展,并从它们之中引进许多有力的解决问题的工具。偏微分方程已经成为当代数学中的一个重要的组成部分,是纯粹数学的许多分支和自然科学及工程技术等领域之间的一座重要的桥梁。 在国外,对偏微分方程的应用发展是相当重视的。很多大学和研究单位都有应用偏微分方程的研究集体,并得到国家工业、科学部门及军方、航空航天等方面的大力资助。比如在国际上有重大影响的美国的Courant研究所、法国的信息与自动化国立研究所等都集中了相当多的偏微分方程的研究人员,并把数学模型、数学方法、应用软件及实际应用融为一体,在解决实际课题、推动学科发展及加速培养人才等方面都起了很大的作用。 在我国,偏微分方程的研究起步较晚。但解放后,在党和国家的大力号召和积极支持下,我国偏微分方程的研究工作发展比较迅速,涌现出一批在这一领域中做出杰出工作的数学家,如谷超豪院士、李大潜院士等,并在一些研究方向上达到了国际先进水平。但总体来说,偏微分方程的研究队伍的组织和水平、研究工作的广度和深度与世界先进水平相比还有很大的差距。因此,我们必须继续努力,大力加强应用偏微分方程的研究,逐步缩小与世界先进水平的差距 二,偏微分方程的内容

Matlab解微分方程(ODE+PDE)

常微分方程: 1 ODE解算器简介(ode**) 2 微分方程转换 3 刚性/非刚性问题(Stiff/Nonstiff) 4 隐式微分方程(IDE) 5 微分代数方程(DAE) 6 延迟微分方程(DDE) 7 边值问题(BVP) 偏微分方程(PDEs)Matlab解法 偏微分方程: 1 一般偏微分方程组(PDEs)的命令行求解 2 特殊偏微分方程(PDEs)的PDEtool求解 3 陆君安《偏微分方程的MATLAB解法 先来认识下常微分方程(ODE)初值问题解算器(solver) [T,Y,TE,YE,IE] = odesolver(odefun,tspan,y0,options) sxint = deval(sol,xint) Matlab中提供了以下解算器: 输入参数: odefun:微分方程的Matlab语言描述函数,必须是函数句柄或者字符串,必须写成Matlab

规范格式(也就是一阶显示微分方程组),这个具体在后面讲解 tspan=[t0 tf]或者[t0,t1,…tf]:微分变量的范围,两者都是根据t0和tf的值自动选择步长,只是前者返回所有计算点的微分值,而后者只返回指定的点的微分值,一定要注意对于后者tspan必须严格单调,还有就是两者数据存储时使用的内存不同(明显前者多),其它没有任何本质的区别 y0=[y(0),y’(0),y’’(0)…]:微分方程初值,依次输入所有状态变量的初值,什么是状态变量在后面有介绍 options:微分优化参数,是一个结构体,使用odeset可以设置具体参数,详细内容查看帮助 输出参数: T:时间列向量,也就是ode**计算微分方程的值的点 Y:二维数组,第i列表示第i个状态变量的值,行数与T一致 在求解ODE时,我们还会用到deval()函数,deval的作用就是通过结构体solution计算t 对应x值,和polyval之类的很相似! 参数格式如下: sol:就是上次调用ode**函数得道的结构体解 xint:需要计算的点,可以是标量或者向量,但是必须在tspan范围内 该函数的好处就是如果我想知道t=t0时的y值,不需要重新使用ode计算,而直接使用上次计算的得道solution就可以 [教程] 微分方程转换为一阶显示微分方程组方法 好,上面我们把Matlab中的常微分方程(ODE)的解算器讲解的差不多了,下面我们就具体开始介绍如何使用上面的知识吧! 现实总是残酷的,要得到就必须先付出,不可能所有的ODE一拿来就可以直接使用,因此,在使用ODE解算器之前,我们需要做的第一步,也是最重要的一步,借助状态变量将微分

Matlab偏微分方程求解方法

Matlab 偏微分方程求解方法 目录: §1 Function Summary on page 10-87 §2 Initial Value Problems on page 10-88 §3 PDE Solver on page 10-89 §4 Integrator Options on page 10-92 §5 Examples” on page 10-93 §1 Function Summary 1.1 PDE Solver” on page 10-87 1,2 PDE Helper Functi on” on page 10-87 1.3 PDE Solver This is the MATLAB PDE solver. PDE Helper Function §2 Initial Value Problems pdepe solves systems of parabolic and elliptic PDEs in one spatial variable x and time t, of the form )x u ,u ,t ,x (s ))x u ,u ,t ,x (f x (x x t u )x u ,u ,t ,x (c m m ??+????=????- (10-2) The PDEs hold for b x a ,t t t f 0≤≤≤≤.The interval [a, b] must be finite. m

can be 0, 1, or 2, corresponding to slab, cylindrical, or spherical symmetry,respectively. If m > 0, thena ≥0 must also hold. In Equation 10-2,)x /u ,u ,t ,x (f ?? is a flux term and )x /u ,u ,t ,x (s ?? is a source term. The flux term must depend on x /u ??. The coupling of the partial derivatives with respect to time is restricted to multiplication by a diagonal matrix )x /u ,u ,t ,x (c ??. The diagonal elements of this matrix are either identically zero or positive. An element that is identically zero corresponds to an elliptic equation and otherwise to a parabolic equation. There must be at least one parabolic equation. An element of c that corresponds to a parabolic equation can vanish at isolated values of x if they are mesh points.Discontinuities in c and/or s due to material interfaces are permitted provided that a mesh point is placed at each interface. At the initial time t = t0, for all x the solution components satisfy initial conditions of the form )x (u )t ,x (u 00= (10-3) At the boundary x = a or x = b, for all t the solution components satisfy a boundary condition of the form 0)x u ,u ,t ,x (f )t ,x (q )u ,t ,x (p =??+ (10-4) q(x, t) is a diagonal matrix with elements that are either identically zero or never zero. Note that the boundary conditions are expressed in terms of the f rather than partial derivative of u with respect to x-x /u ??. Also, of

五点差分法(matlab)解椭圆型偏微分方程

用差分法解椭圆型偏微分方程 U(0,y)=si n(pi*y),U(2,y)=eA2si n( pi*y); 先自己去看一下关于五点差分法的理论书籍 Matlab 程序: unction [p e u x y k]=wudianchafenfa(h,m,n,kmax,ep) % g-s 迭代法解五点差分法问题 %kmax 为最大迭代次数 %m,n 为x,y 方向的网格数,例如(2-0 ) /0.01=200; %e 为误差,p 为精确解 syms temp ; u=zeros(n+1,m+1); x=0+(0:m)*h; y=0+(0:n)*h; for (i=1:n+1) u(i,1)=sin(pi*y(i)); u(i,m+1)=exp(1)*exp(1)*sin(pi*y(i)); end for (i=1:n) for ( j=1:m) f(i,j)=(pi*pi-1)*exp(x(j))*sin(pi*y(i)); end -(Uxx+Uyy)=(pi*pi-1)eAxsin(pi*y) 0

end t=zeros(n-1,m-1); for (k=1:kmax) for (i=2:n) for ( j=2:m) temp=h*h*f(i,j)/4+(u(i,j+1)+u(i,j-1)+u(i+1,j)+u(i- 1,j))/4; t(i,j)=(temp-u(i,j))*(temp-u(i,j)); u(i,j)=temp; end end t(i,j)=sqrt(t(i,j)); if (k>kmax) break ; end if (max(max(t))

《matlab求解偏微分方程常见问题》

偏微分方程概述及运用matlab求解偏微分 方程常见问题 徐敏 摘要偏微分方程简介,matlab偏微分方程工具箱应用简介,用这个工具箱解方程的过程是:确定待解的偏微分方程;确定边界条件;确定方程所在域的几何形状;划分有限元;解方程 关键词MATLAB 偏微分方程程序 如果一个微分方程中出现的未知函数只含有一个自变量,这个方程叫做常微分方程,也简称微分方程:如果一个微分方程中出现多元函数的偏导数,或者说如果未知函数和几个变量有关,而且方程中出现未知函数对几个变量的导数,那么这种微分方程就是偏微分方程。 一,偏微分方程概述 偏微分方程是反映有关的未知变量关于时间的导数和关于空间变量的导数之间制约关系的等式。许多领域中的数学模型都可以用偏微分方程来描述,很多重要的物理、力学等学科的基本方程本身就是偏微分方程。早在微积分理论刚形成后不久,人们就开始用偏微分方程来描述、解释或预见各种自然现象,并将所得到的研究方法和研究成果运用于各门科学和工程技术中,不断地取得了显著的成效,显示

了偏微分方程对于人类认识自然界基本规律的重要性。逐渐地,以物理、力学等各门科学中的实际问题为背景的偏微分方程的研究成为传统应用数学中的一个最主要的内容,它直接联系着众多自然现象和实际问题,不断地提出和产生出需要解决的新课题和新方法,不断地促进着许多相关数学分支(如泛函分析、微分几何、计算数学等)的发展,并从它们之中引进许多有力的解决问题的工具。偏微分方程已经成为当代数学中的一个重要的组成部分,是纯粹数学的许多分支和自然科学及工程技术等领域之间的一座重要的桥梁。 在国外,对偏微分方程的应用发展是相当重视的。很多大学和研究单位都有应用偏微分方程的研究集体,并得到国家工业、科学部门及军方、航空航天等方面的大力资助。比如在国际上有重大影响的美国的Courant研究所、法国的信息与自动化国立研究所等都集中了相当多的偏微分方程的研究人员,并把数学模型、数学方法、应用软件及实际应用融为一体,在解决实际课题、推动学科发展及加速培养人才等方面都起了很大的作用。 在我国,偏微分方程的研究起步较晚。但解放后,在党和国家的大力号召和积极支持下,我国偏微分方程的研究工作发展比较迅速,涌现出一批在这一领域中做出杰出工作的数学家,如谷超豪院士、李大潜院士等,并在一些研究方向上达到了国际先进水平。但总体来说,偏微分方程的研究队伍的组织和水平、研究工作的广度和深度与世界先进水平相比还有很大的差距。因此,我们必须继续努力,大力加强应用偏微分方程的研究,逐步缩小与世界先进水平的差距

微分方程在MATLAB中的实现

微分方程在MATLAB中的实现 作者:吴建宏 时间:2011.09.20 ********************************************* 作者简介: 吴建宏,男,毕业于哈尔滨工业大学(威海),现就读于同济大学,攻读汽车电子方向,有两年的MATLAB实践经验,个人喜欢建模,编程和电控方面的。真诚愿意和各位志同道合的朋友一起探讨交流,一起搭建广阔的知识平台。 *********************************************

PART ONE 微分方程简介 一、微分方程基本概念 微分方程:未知函数以及它们的某些阶的导数连同自变量都由一已知方程联系在一起的方程称为微分方程。其中,未知函数的最高阶数称为微分方程的阶。 偏微分方程:如果未知函数是多元函数,那么这个微分方程就是偏微分方程。常微分方程:如果未知函数是一元函数,那么这个微分方程就是常微分方程。 二、微分方程的解法 高等数学里讲过,微分方程的解法有分离变量法,常数变易法,特征值法……而在解决工程实际问题时候,利用MATLAB 求解微分方程的方法主要有符号解法和数值解法。其中,符号解法主要可以求解可以用特征值法求解的常系数微分方程和少数特殊的微分方程,有很大的局限性,而且运行时间较长,优点就是可以得到精确的数学表达式。大部分实际的微分方程不得不通过数值解法来求解,优点就是运行时间快,可以解决复杂的线性或者非线性微分方程。缺点就是解是近似值。 PART TWO 微分方程的符号解法(dsolve ) 微分方程的符号解法主要是函数dsolve ,这个函数用起来很简单,最重要的是要知道神马时候能够用dsolve ,神马时候不能用,当运行出错的时候,该怎么处理。接下来进入正文。 一、语法 r =dsolve('eq1,eq2,...','cond1,cond2,...','v') r =dsolve('eq1','eq2',...,'cond1','cond2',...,'v') 二、语法详解 1.eq1,eq2……用来代表看上去能够用高等数学介绍过的手段求解出来的微分方程,如果实在不太熟悉或者忘了,没关系,后面会提供出现错误时候的处理措施;v 代表自变量,默认值为时间t 。边界条件/初始值用cond1,cond2,...来表示。 2.在eq1,eq2……中,用D 来代表变量的微分,例如?y 用Dy 表示,而? ?y 用y D 2来表示。 3.初始值的边界条件用b a y =)(或者b a Dy =)(来表示。如果初始值的个数小于变量的个数,输出的结果中就会出现待定系数。 4.Dsolve 能够接受的最大输入初始条件是12个 5.如果是一个等式一个输出,输出的结果是非线性的符号表达式;如果是多个等式和多个输出,将会按照左边输出参数[y1,y2……]中的顺序输出相应的符号表达式;如果是多等式,单输出,返回一个结构体数组。 出现错误时候怎么处理?如果dsolve 不能找到有限解,它会试图去找方程的隐式解,当找到隐式解得时候,就会返回警告标志;如果既找不到有限解,也找不到隐式解,就会返回empty 的错误警告"warning Warning:explicit solution could not be found"。在这两种情况下都只能通过使用数值解法来解决。

MATLAB精通科学计算-偏微分方程求解

一、Maple V 系统 Maple V是由Waterloo大学开发的数学系统软件,它不但具有精确的数值处理功能,而且具有无以伦比的符号计算功能。Maple V的符号计算能力还是MathCAD和MATLAB等软件的符号处理的核心。Maple提供了2000余种数学函数,涉及范围包括:普通数学、高等数学、线性代数、数论、离散数学、图形学。它还提供了一套内置的编程语言,用户可以开发自己的应用程序,而且Maple自身的2000多种函数,基本上是用此语言开发的。 Maple采用字符行输入方式,输入时需要按照规定的格式输入,虽然与一般常见的数学格式不同,但灵活方便,也很容易理解。输出则可以选择字符方式和图形方式,产生的图形结果可以很方便地剪贴到Windows应用程序内。 二、MATLAB 系统 MATLAB原是矩阵实验室(Matrix Laboratory)在70年代用来提供Linpack和Eispack 软件包的接口程序,采用C语言编写。从80年代出现3.0的DOS版本,逐渐成为科技计算、视图交互系统和程序语言。MATLAB可以运行在十几个操作平台上,比较常见的有基于Wi ndows 9X/NT、OS/2、Macintosh、Sun、Unix、Linux等平台的系统。 MATLAB程序主要由主程序和各种工具包组成,其中主程序包含数百个内部核心函数,工具包则包括复杂系统仿真、信号处理工具包、系统识别工具包、优化工具包、神经网络工具包、控制系统工具包、μ分析和综合工具包、样条工具包、符号数学工具包、图像处理工具包、统计工具包等。而且5.x版本还包含一套几十个的PDF文件,从MATLAB的使用入门到其他专题应用均有详细的介绍。 MATLAB是数值计算的先锋,它以矩阵作为基本数据单位,在应用线性代数、数理统计、自动控制、数字信号处理、动态系统仿真方面已经成为首选工具,同时也是科研工作人员和大学生、研究生进行科学研究的得力工具。MATLAB在输入方面也很方便,可以使用内部的Editor或者其他任何字符处理器,同时它还可以与Word6.0/7.0结合在一起,在Word的页面里直接调用MATLAB的大部分功能,使Word具有特殊的计算能力。 三、MathCAD 系统 MathCAD是美国Mathsoft公司推出的一个交互式的数学系统软件。从早期的DOS下的1.0和Windows下的4.0版本,到今日的8.0版本,功能也从简单的数值计算,直至引用Maple强大的符号计算能力,使得它发生了一个质的飞跃。 MathCAD是集文本编辑、数学计算、程序编辑和仿真于一体的软件。MathCAD7.0 Pro fessional(专业版)运行在Win9X/NT下,它的主要特点是输入格式与人们习惯的数学书写格式很近似,采用WYSWYG(所见所得)界面,特别适合一般无须进行复杂编程或要求比较特殊的计算。MathCAD 7.0 Professional 还带有一个程序编辑器,对于一般比较短小,或者要求计算速度比较低时,采用它也是可以的。这个程序编辑器的优点是语法特别简单。 MathCAD可以看作是一个功能强大的计算器,没有很复杂的规则;同时它也可以和W ord、Lotus、WPS2000等字处理软件很好地配合使用,可以把它当作一个出色的全屏幕数学公式编辑器。 四、Mathematica 系统 Mathematica是由美国物理学家Stephen Wolfram领导的Wolfram Research开发的数学系统软件。它拥有强大的数值计算和符号计算能力,在这一方面与Maple类似,但它的

(整理)Matlab解微分方程.

第十六章 偏微分方程的数值解法 科学研究和工程技术中的许多问题可建立偏微分方程的数学模型。包含多个自变量的微分方程称为偏微分方程(partial differential equation),简称PDE 。偏微分方程问题,其求解是十分困难的。除少数特殊情况外,绝大多数情况均难以求出精确解。因此,近似解法就显得更为重要。本章仅介绍求解各类典型偏微分方程定解问题的差分方法。 16.1 几类偏微分方程的定解问题 一个偏微分方程的表示通常如下: (,,,,)x x x y y y x y A B C f x y Φ+Φ+Φ=ΦΦΦ (16.1.1) 式中,,,A B C 是常数,称为拟线性(quasilinear)数。通常,存在3种拟线性方程: 双曲型(hyperbolic)方程:240B AC ->; 抛物线型(parabolic)方程:240B AC -=; 椭圆型(ellliptic)方程:240B AC -<。 16.1.2 双曲型方程 最简单形式为一阶双曲型方程: 0u u a t x ??+=?? (16.1.2) 物理中常见的一维振动与波动问题可用二阶波动方程: 22222u u a t x ??=?? (16.1.3) 描述,它是双曲型方程的典型形式。方程的初值问题为:

222220 0,(,0)()()t u u a t x t x u x x u x x t ?ψ=???=>-∞<<+∞ ????? =?? ??=-∞<<+∞ ??? (16.1.4) 边界条件一般有三类,最简单的初边值问题为: 22222120 00,0(,0)(0,)(),(,)()0()t u u a t T x l t x u x l u t g t u l t g t t T u x x t ?ψ=???==<<<?? (16.1.8) 方程可以有两种不同类型的定解问题: (1) 初值问题: 2200,(,0)()u u a t x t x u x x x ????-=>-∞<<+∞? ????=-∞<<+∞ ? (16.1.6) (2) 初边值问题: 2212 00,0(,0)()0(0,)(),(,)()0u u a t T x l t x u x x x l u t g t u l t g t t T ????-=<<<

五点差分法(matlab)解椭圆型偏微分方程

用差分法解椭圆型偏微分方程 -(Uxx+Uyy)=(pi*pi-1)e^xsin(pi*y) 0kmax) break; end if(max(max(t))

偏微分方程数值解法的MATLAB源码

[原创]偏微分方程数值解法的MATLAB源码【更新完毕】 说明:由于偏微分的程序都比较长,比其他的算法稍复杂一些,所以另开一贴,专门上传偏微分的程序谢谢大家的支持! 其他的数值算法见: ..//Announce/Announce.asp?BoardID=209&id=8245004 1、古典显式格式求解抛物型偏微分方程(一维热传导方程) function [U x t]=PDEParabolicClassicalExplicit(uX,uT,phi,psi1,psi2,M,N,C) %古典显式格式求解抛物型偏微分方程 %[U x t]=PDEParabolicClassicalExplicit(uX,uT,phi,psi1,psi2,M,N,C) % %方程:u_t=C*u_xx 0 <= x <= uX,0 <= t <= uT %初值条件:u(x,0)=phi(x) %边值条件:u(0,t)=psi1(t), u(uX,t)=psi2(t) % %输出参数:U -解矩阵,第一行表示初值,第一列和最后一列表示边值,第二行表示第2层…… % x -空间变量 % t -时间变量 %输入参数:uX -空间变量x的取值上限 % uT -时间变量t的取值上限 % phi -初值条件,定义为内联函数 % psi1 -边值条件,定义为内联函数 % psi2 -边值条件,定义为内联函数 % M -沿x轴的等分区间数 % N -沿t轴的等分区间数 % C -系数,默认情况下C=1 % %应用举例: %uX=1;uT=0.2;M=15;N=100;C=1; %phi=inline('sin(pi*x)');psi1=inline('0');psi2=inline('0'); %[U x t]=PDEParabolicClassicalExplicit(uX,uT,phi,psi1,psi2,M,N,C); %设置参数C的默认值 if nargin==7 C=1; end %计算步长 dx=uX/M;%x的步长 dt=uT/N;%t的步长

Matlab求解微分方程组及偏微分方程

第四讲 Matlab 求解微分方程(组) 理论介绍:Matlab 求解微分方程(组)命令 求解实例:Matlab 求解微分方程(组)实例 实际应用问题通过数学建模所归纳得到的方程,绝大多数都就是微分方程,真正能得到代数方程的机会很少、另一方面,能够求解的微分方程也就是十分有限的,特别就是高阶方程与偏微分方程(组)、这就要求我们必须研究微分方程(组)的解法:解析解法与数值解法、 一.相关函数、命令及简介 1、在Matlab 中,用大写字母D 表示导数,Dy 表示y 关于自变量的一阶导数,D2y 表示y 关于自变量的二阶导数,依此类推、函数dsolve 用来解决常微分方程(组)的求解问题,调用格式为: X=dsolve(‘eqn1’,’eqn2’,…) 函数dsolve 用来解符号常微分方程、方程组,如果没有初始条件,则求出通解,如果有初始条件,则求出特解、 注意,系统缺省的自变量为t 2、函数dsolve 求解的就是常微分方程的精确解法,也称为常微分方程的符号解、但就是,有大量的常微分方程虽然从理论上讲,其解就是存在的,但我们却无法求出其解析解,此时,我们需要寻求方程的数值解,在求常微分方程数值解方面,MATLAB 具有丰富的函数,我们将其统称为solver,其一般格式为: [T,Y]=solver(odefun,tspan,y0) 说明:(1)solver 为命令ode45、ode23、ode113、ode15s 、ode23s 、ode23t 、ode23tb 、ode15i 之一、 (2)odefun 就是显示微分方程'(,)y f t y =在积分区间tspan 0[,]f t t =上从0t 到f t 用初始条件0y 求解、 (3)如果要获得微分方程问题在其她指定时间点012,,,,f t t t t L 上的解,则令tspan 012[,,,]f t t t t =L (要求就是单调的)、 (4)因为没有一种算法可以有效的解决所有的ODE 问题,为此,Matlab 提供了多种求解器solver,对于不同的ODE 问题,采用不同的solver 、

相关文档
最新文档