# Solving a PDE using Matlab (with varying initial conditions)

I want to solve a 1-D heat conduction PDE using Matlab which looks like $$\rho c_p \dfrac{\partial T}{\partial t} = \dfrac{\partial}{\partial z}\left( \lambda \dfrac{\partial T}{\partial z} \right),$$ where the initial condition is T1 (in Kelvin) and the final condition is T2 (also in Kelvin), the difference being T1 takes different values from t=0 hours to t=24 hours (t being time) and T2 being constant (say 200 K)

I checked the pdepe toolbox in Matlab and I felt the conditions that I wanted to implement might not be possible through the toolbox.

Can anyone suggest a way to create a loop through which T1 can read values from an array so that a diurnal plot can be created ?

• I think you are confused about the terms "initial" and "final" conditions. These would refer to $t=0$ and $t=T$ in common usage of the words. I suppose you probably meant "left" and "right" boundary conditions at $z=0$ and $z=L$. Apr 17, 2015 at 22:31

this problem can be solved using the pdepe solver in Matlab.

If I understand well, T1 and T2 represent your left and right boundary conditions for the spatial domain : $$T(z=0,\,t) = T_1( t ) \\ T(z=L,\,t) = Const. = T_2$$

'Initial' and 'final' terms are usualy related to the time domaine.

The initial (i.e. at time t=0) temperature field could be, for instance, uniform in $z$: $T(z,\, t=0 ) = Const.$ (specified using the icfun function).

And there is no final condition in time.

Spatial boundary conditions are specified by the bcfun function, which return values of the $p$ and $q$ coefficients for the left and right boundaries (see eq. 1-6 in the matlab doc). These coefficients can be function of time. In your case it will be something like:

function [pl, ql, pr, qr] = bcfun(xl, ul, xr, ur, t)
pl = T1( t );
pr = T2;
ql = 0;
qr = 0;

function T = T1( t )
T = ...

• For icfun, I wrote this code: function [u] = icfun1( x ) u = 190; %%% Device measured temperature end While for pdefun, this is the code: function [c, f, s] = pdefun1(x, t, u, dudx) c = 1; f = dudx; s = 0; end The main conduction code is:clear all; close all; clc; m = 0; x = linspace(0,1,100); t = linspace(0,2,5); sol = pdepe(m, pdefun1, icfun1, bcfun1, x, t); (Pl check and suggest) Apr 18, 2015 at 18:39