KTH – ROYAL INSTITUTE OF TECHNOLOGY School of Engineering Sciences Course: Applied Numerical Methods Course code: SF2520 Authors: 1) Andreas Angelou 2) Vasileios Papadimitriou 3) Dionysios Zelios Lab name: Partial Differential Equation of Parabolic Type Date of submission: 5/12/2013
We have a metallic rod that is isolated on the right end. At time t=0 we heat the left end. After some time, the right end will be warmer and then it cools off again. The density of the rod is given as ρ[kg/m3]. The heat capacity is Cp[J/(kg*C)] and k[J/(m*s*C)] is the thermal conductivity.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
KTH – ROYAL INSTITUTE OF TECHNOLOGY
School of Engineering Sciences
Course: Applied Numerical Methods
Course code: SF2520
Authors: 1) Andreas Angelou
2) Vasileios Papadimitriou
3) Dionysios Zelios
Lab name: Partial Differential Equation of Parabolic Type
Date of submission: 5/12/2013
CONTENTS
Part A ……………………………………………………………………………………………………………….3
Part B………………………………………………………………………………………………………………..4 Part C………………………………………………………………………………………………………………..6 Part D………………………………………………………………………………………………………………..8 Part E………………………………………………………………………………………………………………...8 Part F……………………………………………………………………………………………………………….…9 Appendix……………………………………………………………………………………………………………13
Initial Condition is given u(ξ,0)=1 for ξ=0, and u(ξ,0)=0 for 0<ξ<=1 . The above ODEs can be
written in the matrix form θu/θτ=A*u+b(τ) (stiff system of ODEs), u(0)=u0, where u0 is the
zero vector.
A=(1/hξ2)*
2 01 0
1 2 1
0 0
11 2
0 20 1
b(τ)= =(1/hξ2)*
1
1
1
1
0
and u(0)=
1
0
0
0
0
Part C
We discretize the ODE with the Euler’s explicit method using constant stepsize Δt. In order to
make our calculations efficient we write our code so that the vector Au+b is formed directly.
We store the whole approximate solution (including initial and boundary condition) in a
large matrix U, where the first column is the initial condition while the first and the last row is
the boundary condition.
We use ‘surf’ to draw a 3D plot of the solution. We make a graph showing a stable solution
and one graph with an unstable solution.
Stable solution
h Δτ Δτ/h²
0.2 0.004 0.1
Unstable solution
h Δτ Δτ/h²
0.2 0.013 0.325
Part D
In this part of the lab we compare the explicit method in ode23 and the implicit method in
ode23s, suitable for stiff problems, in the Matlab library. The two functions run under the
similar conditions (same problem, same tolerance) and for three values of the stepsize h
corresponding to N=10, N=20, N=40 grid points on the ξ-axis.
The comparison comprises:
i. The number of time steps needed to reach τ=2
ii. The cpu-time needed to do each computation
iii. The maximal stepsize that each method could take
The results are presented in the following table:
N Time steps Cpu-time (sec) hmax
Ode23 | Ode23s Ode23 | Ode23s Ode23 | Ode23s
10 458 | 252 0.562 | 0.807 0.0053 | 0.0456
20 1477 | 298 0.754 | 1.055 0.0006 | 0.0456
40 5424 | 347 1.440 | 1.610 0.0004 | 0.0434
We conclude that the number of time steps is considerably smaller when using a stiff
method.
Part E
With the Malab function odeset , options can be set up by the user in order to make the
computation more efficient. By activating the options ‘Jacobian’, ‘Jconstant’ and ‘Jpattern’,
we see that we can smooth out the graph for ode-23s and we have the following table:
N Time steps Cpu-time (sec) hmax
Ode23 | Ode23s Ode23 | Ode23s Ode23 | Ode23s
10 458 | 876 0.562 | 0.710 0.0053 | 0.0046
20 1477 | 2099 0.754 | 1.019 0.0006 | 0.0012
40 5424 | 6892 1.440 | 2.396 0.0004 | 0.0003
Part F
We visualize the result of a successful computation from part D in graphs.
The following graphs show two-dimensional plots of u(t,ξ), 0<ξ,=1 at four timepoints:
τ=0.5, 1, 1.5, 2.
Ode23:
Ode23s
The following graphs show three-dimensional plots of u as a function of τ and ξ.
Ode23:
Ode23s:
We conclude that if we want efficient numerical calculations for parabolic problems we
should use non-stiff solver (ode-23) for time efficiency. However, after using the Jacobian
matrix properties in the odeset the stiff solver (ode-23s)becomes equally efficient but with
less time efficiency. The structure of the Jacobian is sparse. The type of the linear equation
solver that we used in the implicit ODE method was solver for full matrices.
Appendix
clear all close all clc
%========= Solution of parabolic model problem with the Mol:
===========
%Solution of u_t=u_xx, u(x,0)=0 , u(0,t)=1, u_x(1,t)=0 using the
MoL.
%================ discretization parameters
============================= dx=0.2; %stepsize in x direction x=0:dx:1; %inner boundary points N=1/dx; %total number of stepsizes dt=0.013; % timestep T=10; %Total number of timesteps c=(2*dt)/((dx)^2); %constant given that a=1
%=============== initialize arrays of boundary and initial conditions
==== u0=[]; b=[]; %initiating initial and boundary
values u0(1)=1; %setting the initial value for
ξ=0 for i=2:N+1 %setting the initial values for
ξ>0 u0(i)=0; end for j=1:T %setting the boundary values for
t<1 b0(j)=1; end
u=u0'; % initial value matrix
b=b0; %upper boundary condition matrix
upast = zeros(1,N+1); %initiating the backwards time line U=zeros(N+1,T); %initiating the solution matrix U
U(:,1)=u; %adding initial condition to the
solution matrix U(1,:)=b; %adding boundary condition to the
solution matrix
%==================== Creating the rest matrix
========================== for i=2:T upast=u; %condition for saving the backwards
time line if (dt*i)>1 %setting the boundary values for
t>1 u(1)=0;
end for j=2:N %creating the rest of the solution
matrix u(j)=c*upast(j+1)-(2*c-1)*upast(j)+c*upast(j-1); U(:,i)=u; end u(N+1)=u(N-1); %setting the lower boundary condition end
%3-D plot surf(U) title('solution of u_t=u_xx, u(x,0)=[1,0,....,0],
u(0,t<1)=[1,1,....,1] u(0,t=1)=0 using the MoL.') xlabel('space variable x') ylabel('time variable y') zlabel('solution variable u(x,t)')
%========= Solution of parabolic model problem with the Mol:
===========
%Solution of u_t=u_xx, u(x,0)=[1,0,....,0], u(0,t<1)=[1,1,....,1]
u(0,t=1)=0 using the MoL. Discretized system store in heatflow.m
clear all clc
global N hx %discretization parameters N=40; %number of inner x points hx=1/(N+1); %stepsize in x direction x=hx:hx:1-hx; %inner points u0(1)=1; for i=2:N u0(i)=0; % initial values end t0=0; tend=2; %time interval options = odeset('RelTol',1e-6, 'AbsTol',1e-
stiff ode-solver resultp=[zeros(size(time)) result zeros(size(time))]; %add
BCs xp=0:hx:1;
%add boundary points mesh(xp,time,resultp) title('solution of u_t=u_xx, u(x,0)=[1,0,....,0],
u(0,t<1)=[1,1,....,1] u(0,t=1)=0 using the MoL.') xlabel('space variable x') ylabel('time variable y') zlabel('solution variable u(x,t)')
%Function used in the parabolic solver for creating the solution
matrix function rhs=heatflow(t,u) global N hx %discretization parameters rhs=zeros(N,1); rhs(1)=(-2*u(1)+u(2)+1)/(hx*hx); rhs(2:N-1)=(u(1:N-2)-2*u(2:N-1)+u(3:N))/(hx*hx); rhs(N)=(u(N-1)-u(N))/(hx*hx); end
References
Introduction to computation and modeling for differential equations,