Tartalomjegyzék

Heat equation with ode45

Teljes Matlab script kiegészítő függvényekkel.

Approximate solution of the heat equation with |ode45| by considering the discretization along the spacial coordinate.

File: ccs_TG_hovezetes_PDE_megoldas_ode45.m
Directory: 4_gyujtemegy/11_CCS/_1_ccs/ccs_2017b/dynamic_system_simulations
Author: Peter Polcz (ppolcz@gmail.com)
Created on 2018. September 17.

Heat equation with a simple initial condition

$u'_t = k u''_{xx}$, where $k=1$. Initial condition: $u(x,0) = 1;

Let me discretize this equation about the spatial parameter $x$:

$$u''_{xx}[k] \simeq \frac{u[k+1] - 2 u[k] + u[k-1]}{(\Delta x)^2}$$

Therefore the PDE can be approximated by the following finite number of ordinary differential equations:

$$\pmqty{u'_t[0] \\ ... \\ u'_t[N-1]} = \pmqty{ -2 & 1 & 0 & ... & 0 \\ 1 & -2 & 1 & ... & 0 \\ ... & ... & ... & ... & ... \\ 0 & ... & 0 & -2 & 1 } \pmqty{u[0] \\ ... \\ u[N-1]}$$

Let the state vector $x$ be:

$$x = \pmqty{u[0] \\ ... \\ u[N-1]}, ~~\text{ and }~~ A = \pmqty{ -2 & 1 & 0 & ... & 0 \\ 1 & -2 & 1 & ... & 0 \\ ... & ... & ... & ... & ... \\ 0 & ... & 0 & -2 & 1 }$$

Then we have a linear autonomous system of ODEs: $\dot x = A x$. Note that matrix $A$ is a Toeplitz matrix due to its special diagonal structure.

% Nr of sample points;
N = 50;

% L = 10 meters long;
L = 10;

Dx = L / (N-1);

T = toeplitz([-2 1 zeros(1,N-2)],[-2 1 zeros(1,N-2)]) / Dx^2;

f = @(t,x) T*x;

[t,y] = ode45(f, linspace(0,10,70), ones(N,1));

surf(y)