-
Notifications
You must be signed in to change notification settings - Fork 0
/
CBYSHV_heat_equation.m
54 lines (40 loc) · 1.2 KB
/
CBYSHV_heat_equation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function CBYSHV_heat_equation
% 1D-Heat Equation: Chebyshev-PS
% RBF Course: HW#2
% Demo code of ode45/Chebyshev-PS solution of
% PDE u_t = u_xx
% IC u(x,0) = 0.05/(1.05-cos(pi*x))
% for time t=0 to t=0.2
clear all
close all
clc
t0 = 0;
tf = 0.2;
n = 32; % set space resolution
% obtain 2nd-Derivative Matrix
g = [1 0 0; 1 0 0];
[x, D2t] = cheb2bc(n+1,g);
fprintf('Size x: %f %f\n', size(x))
CDM = D2t;
fprintf('Size CDM: %f %f\n', size(CDM))
% % Layout the Chebyshev Points
u0 = (0.05./(1.05-cos(pi*x)))'; % give Init. cond.
u0(end) = u0(1);
fprintf('Size u0: %f %f\n', size(u0))
fig1 = figure(1);
plot(x,u0) % determine how function varies
% use ode45 to advance in time
[t,u] = ode45(@dudt, t0:0.001:tf, u0, [], CDM, x);
% Verify the following
% u(:,n+1) = u(:,1); % Fill in right-edge in graphics.
fig2 = figure(2);
fprintf('Figure BEGINS ================================= \n')
fprintf('size u: %f %f \n', size(u))
fprintf('size t: %f %f \n', size(t))
fprintf('size x: %f %f \n', size(x))
mesh(x',t,u); colormap([0,0,0]) %Plot result
function uxx = dudt(t,u,DM, x)
%{
Calculate uxx by Chebyshev Pseudospectral Method
%}
uxx = DM*u;