一维热传导方程求数值解

一维热传到方程求数值解

本文主要利用泰勒展开将方程中的一阶还有二阶偏导数进行离散化,推导出一种可以用程序求解的形式

求解原理

一维热传导方程

{ ∂ u ∂ x ( x , t ) = a 2 ∂ 2 u ∂ x 2 u ( x , t ) + f ( x , t ) u ( x , 0 ) = φ ( x ) u ( a , t ) = γ 1 ( t ) u ( b , t ) = γ 2 ( t ) \begin{align} \begin{cases} \frac{\partial u}{\partial x} \left ( x,t \right ) &=a^{2} \frac{\partial^{2}u}{\partial x^2}u(x,t)+f(x,t)\\ u(x,0)&=\varphi({x})\\ u(a,t)&=\gamma_{1}(t)\\ u(b,t)&=\gamma_2(t) \end{cases} \end{align} xu(x,t)u(x,0)u(a,t)u(b,t)=a2x22uu(x,t)+f(x,t)=φ(x)=γ1(t)=γ2(t)
由于热传导方程较为复杂,只能将方程中的一阶和二阶偏导进行离散化。和欧拉法采用相同的思路,下面进行推导:

  1. x x x​与 t t t​分别在横坐标与纵坐标上进行划分

    x x x步长: Δ x = b − a N \Delta{x}= \frac{b-a}{N} Δx=Nba​​​,得到关于 x j x_j xj t n t_n tn的表达式:

    x j = a + ( j − 1 ) Δ x t n = 0 + ( n − 1 ) Δ t \begin{aligned} x_j &= a + (j-1)\Delta{x} \\ t_n &= 0 + (n-1)\Delta{t} \\ \end{aligned} xjtn=a+(j1)Δx=0+(n1)Δt
    将函数进行近似替换 u j n ≈ u ( x j , t n ) u_j^n\approx u(x_j,t_n) ujnu(xj,tn)

  2. 根据泰勒展开将公式进行代换

    对于任意一个 x j x_j xj t t t进行展开:

    u ( x j , t n + Δ t ) = u ( x j , t n ) + ∂ u ∂ t ( x j , t n ) Δ t + ⋅ ⋅ ⋅ u(x_j,t_n+\Delta{t})=u(x_j,t_n)+\frac{\partial u}{\partial t} (x_j,t_n)\Delta{t}+··· u(xj,tn+Δt)=u(xj,tn)+tu(xj,tn)Δt+⋅⋅⋅
    由于很难求出函数的偏导,所以需要将其所有偏导形式转换成容易求解出来的离散形式首先用一维热传导方程进行替换

    ∂ u ∂ t ( x j , t n ) = a 2 ∂ 2 u ∂ x 2 ( x j , t n ) + f ( x j , t n ) \frac{\partial u}{\partial t} (x_j,t_n) = a^2 \frac{\partial^{2}u}{\partial x^2}(x_j,t_n)+f(x_j,t_n) tu(xj,tn)=a2x22u(xj,tn)+f(xj,tn)
    利用上式联立下面两个式子

    u ( x j + Δ x , t n ) = u ( x j , t n ) + ∂ u ∂ x ( x j , t n ) Δ x + 1 / 2 ∂ 2 u ∂ x 2 ( x j , t n ) Δ x 2 + ⋅ ⋅ ⋅ u ( x j − Δ x , t n ) = u ( x j , t n ) − ∂ u ∂ x ( x j , t n ) Δ x + 1 / 2 ∂ 2 u ∂ x 2 ( x j , t n ) Δ x 2 − ⋅ ⋅ ⋅ ∂ 2 u ∂ x 2 ( x j , t n ) ≈ u j + 1 n + u j − 1 n − 2 u j n Δ x 2 \begin{aligned} u(x_j+\Delta{x},t_n) &= u(x_j,t_n)+\frac{\partial u}{\partial x} (x_j,t_n)\Delta{x}+1/2\frac{\partial^{2}u}{\partial x^2}(x_j,t_n)\Delta{x}^2+···\\ u(x_j-\Delta{x},t_n) &= u(x_j,t_n)-\frac{\partial u}{\partial x} (x_j,t_n)\Delta{x}+1/2\frac{\partial^{2}u}{\partial x^2}(x_j,t_n)\Delta{x}^2-··· \\ \frac{\partial^{2}u}{\partial x^2}(x_j,t_n) &\approx \frac{u_{j+1}^n+u_{j-1}^n-2u_j^n}{\Delta{x}^2} \end{aligned} u(xj+Δx,tn)u(xjΔx,tn)x22u(xj,tn)=u(xj,tn)+xu(xj,tn)Δx+1/2x22u(xj,tn)Δx2+⋅⋅⋅=u(xj,tn)xu(xj,tn)Δx+1/2x22u(xj,tn)Δx2⋅⋅⋅Δx2uj+1n+uj1n2ujn

    最后得到递推关系式
    u j n + 1 = u j n + [ a 2 u j + 1 n + u j − 1 n − 2 u j n Δ x 2 + f j n ] Δ t u_j^{n+1}=u_j^n+[a^2\frac{u_{j+1}^n+u_{j-1}^n-2u_j^n}{\Delta{x}^2}+f_j^n]\Delta{t} ujn+1=ujn+[a2Δx2uj+1n+uj1n2ujn+fjn]Δt

化成易于用程序求解的形式
  1. 在时间维度上进行递推

    首先设置两个时间向量,将所有的位置包括其中

    u n = ( u 1 n ⋮ ⋮ u N + 1 n ) u n + 1 = ( u 1 n + 1 ⋮ ⋮ u N + 1 n + 1 ) u^n= \begin{pmatrix} u_1^n\\ \vdots\\ \vdots\\ u_{N+1}^n \end{pmatrix} \qquad u^{n+1}= \begin{pmatrix} u_1^{n+1}\\ \vdots\\ \vdots\\ u_{N+1}^{n+1} \end{pmatrix} un= u1nuN+1n un+1= u1n+1uN+1n+1

  2. 建立系数矩阵

    ( ϕ 第一取值 ⋮ 第 N 取值 ϕ ) = ( − 2 1 0 0 ⋅ ⋅ ⋅ 1 − 2 1 0 ⋅ ⋅ ⋅ ⋮ ⋅ ⋅ ⋅ 0 1 − 2 1 ⋅ ⋅ ⋅ 0 0 1 − 2 ) ( u 1 n u 2 n ⋮ ⋮ u N + 1 n ) \begin{pmatrix} \phi \\ 第一取值 \\ \vdots \\ 第N取值 \\ \phi \end{pmatrix}= \begin{pmatrix}-2\quad1\quad0\quad0\quad··· \\1\quad-2\quad1\quad0\quad··· \\\vdots \\···\quad0\quad1\quad-2\quad1 \\···\quad0\quad0\quad1\quad-2 \end{pmatrix} \begin{pmatrix}u_1^n \\u_2^n \\\vdots \\\vdots \\u_{N+1}^n \end{pmatrix} ϕ第一取值N取值ϕ = 2100⋅⋅⋅1210⋅⋅⋅⋅⋅⋅0121⋅⋅⋅0012 u1nu2nuN+1n

    为何矩阵要这么建立,系数矩阵 A A A​的第二行为例,与右边的列向量相乘得到结果 u 1 n − 2 u 2 n + u 3 n u_1^n - 2u_2^n + u_3^n u1n2u2n+u3n​ 将结果表示成以下列向量。由于初值和末值原方程会给出,所以开始两个值可能不正确,所以先不用管。
    ( ϕ u 1 n − 2 u 2 n + u 3 n u 2 n − 2 u 3 n + u 4 n ⋮ u N − 1 n − 2 u N n + u N + 1 n ϕ ) \begin{pmatrix} \phi \\ u_1^n - 2u_2^n + u_3^n \\ u_2^n - 2u_3^n + u_4^n \\ \vdots \\ u_{N - 1}^n - 2u_N^n + u_{N + 1}^n \\ \phi \\ \end{pmatrix} ϕu1n2u2n+u3nu2n2u3n+u4nuN1n2uNn+uN+1nϕ

  3. 扩散源或热源表示
    f n = ( f 1 n ⋮ ⋮ f N + 1 n ) f^n= \begin{pmatrix} f_1^n\\ \vdots\\ \vdots\\ f_{N+1}^n \end{pmatrix} fn= f1nfN+1n

  4. 得到最终表达式
    u n + 1 = u n + ( a 2 1 Δ x 2 A u n + f n ) Δ t u^{n+1}=u^n+(a^2\frac{1}{\Delta{x}^{2}}Au^n+f^n)\Delta{t}\\ un+1=un+(a2Δx21Aun+fn)Δt

    以下为初始条件:
    u 1 n + 1 = γ 1 n + 1 = γ ( t n + 1 ) u N + 1 n + 1 = γ 2 n + 1 u 1 = γ γ j = γ ( x j ) \begin{aligned} u_1^{n+1} &= \gamma_1^{n+1} = \gamma(t_{n+1}) \\ u_{N+1}^{n+1} &= \gamma_2^{n+1} \\ u^1 &= \gamma \\ \gamma_j &= \gamma(x_j) \\ \end{aligned} u1n+1uN+1n+1u1γj=γ1n+1=γ(tn+1)=γ2n+1=γ=γ(xj)
    通过程序可以设定步长 Δ x \Delta x Δx Δ t \Delta t Δt 其它量就可以通过边界条件推出。

示例与代码

设方程如下:
∂ u ∂ x ( x , t ) = a 2 ∂ 2 u ∂ x 2 u ( x , t ) + f ( x , t ) u ( x , 0 ) = 0 u ( a , t ) = 0 + 0.0 × s i n ( t ) u ( b , t ) = 0 − 0.0 × s i n ( t ) \begin{align} \frac{\partial u}{\partial x} \left ( x,t \right ) &=a^{2} \frac{\partial^{2}u}{\partial x^2}u(x,t)+f(x,t)\\ u(x,0) &= 0\\ u(a,t) &= 0 + 0.0 \times sin(t)\\ u(b,t) &= 0 - 0.0 \times sin(t)\\ \end{align} xu(x,t)u(x,0)u(a,t)u(b,t)=a2x22uu(x,t)+f(x,t)=0=0+0.0×sin(t)=00.0×sin(t)
求解 m a t l a b matlab matlab代码如下:

clc; clear

a = 1; 
dx = 0.01;
x = 0 : dx : 1;
dt = 0.00005;
t = 0 : dt : 1;

u = zeros(length(x), length(t));
u(:,1) = 0;
f = 5 * exp(-20 * (x - 1 / 2) .^ 2);
m1 = 0 + 0.0 * sin(t);
m2 = 0 - 0.0 * sin(t);

A = -2 * eye(length(x)) + diag(ones(1,length(x)-1),1) + diag(ones(1,length(x)-1),-1)

for n = 1 : length(t)-1
    u(:, n+1) = u(:,n) + (a^2 / dx^2 * A * u(:,n) + f') * dt;
    u(1, n+1) = m1(n+1);
    u(end, n+1) = m2(n+1);
    plot(x, u(:,end))
    axis([x(1) x(end) 0 1])
    getframe;
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值