The document describes two numerical schemes for solving the heat equation:
1) The implicit scheme involves inverting a matrix A at each time step to solve for the unknowns. Boundary conditions are applied and the solution plotted over time.
2) The Crank-Nicolson scheme similarly inverts matrices A and B at each time step, but uses the average of the implicit and explicit forms. It also applies boundary conditions and plots the evolving solution over time.
Both schemes are implemented in MATLAB code that discretizes the heat equation in space and time to iteratively solve for the temperature distribution.
The document describes two numerical schemes for solving the heat equation:
1) The implicit scheme involves inverting a matrix A at each time step to solve for the unknowns. Boundary conditions are applied and the solution plotted over time.
2) The Crank-Nicolson scheme similarly inverts matrices A and B at each time step, but uses the average of the implicit and explicit forms. It also applies boundary conditions and plots the evolving solution over time.
Both schemes are implemented in MATLAB code that discretizes the heat equation in space and time to iteratively solve for the temperature distribution.
The document describes two numerical schemes for solving the heat equation:
1) The implicit scheme involves inverting a matrix A at each time step to solve for the unknowns. Boundary conditions are applied and the solution plotted over time.
2) The Crank-Nicolson scheme similarly inverts matrices A and B at each time step, but uses the average of the implicit and explicit forms. It also applies boundary conditions and plots the evolving solution over time.
Both schemes are implemented in MATLAB code that discretizes the heat equation in space and time to iteratively solve for the temperature distribution.
The document describes two numerical schemes for solving the heat equation:
1) The implicit scheme involves inverting a matrix A at each time step to solve for the unknowns. Boundary conditions are applied and the solution plotted over time.
2) The Crank-Nicolson scheme similarly inverts matrices A and B at each time step, but uses the average of the implicit and explicit forms. It also applies boundary conditions and plots the evolving solution over time.
Both schemes are implemented in MATLAB code that discretizes the heat equation in space and time to iteratively solve for the temperature distribution.
a. Listing Program % Implicit scheme for Heat equation
close clear
P = 10; h = 0.2; g = 0.2; tau = g * h^2; T = 1; m = length(0:tau:T)
xl = 0;xr = 1; x = xl:h:xr; n = length(x);
% initial condition u = x; %u(1:round(n/2))=.5 ;u(round(n/2):end)=0;
U = u;
t = 0; ctr = 0; set(figure,'backingstore','off','doublebuffer','on'); u0 =u;
Temp = zeros(length(0:tau:T),n); Temp(1,:) = u0;
A=zeros(n-2,n-2) for i=1:n-2 if (i==1) A (i,i)=1+g A (i,i+1)=-g elseif (i==n-2) A (i,i)=1+g A (i,i-1)=-g else A (i,i)=1+2*g A (i,i-1)=-g A (i,i+1)=-g end end
C = zeros(m,n) for i = 1:m t = (i-1)*m for j = 1:n x=(j-1)*(n) C(i,j)=(P/2)-((4*P/pi^2)*(cos((pi*x)/P))*(exp((-pi^2*t)/P^2))) end end
error = C-Temp
surf(Temp); shading interp colorbar
b. Tampilan Program
Keterangan: hasil tampilan program hanya ditampilkan sebagian, tidak keseluruhan.
2. Skema Crank Nicolson Pada Heat Equation a. Listing Program % Crank Nilson scheme for Heat equation
close clear
P = 10; h = 0.2; g = 0.2; tau = g*(h^2); T = 1; m = length(0:tau:T)
xl = 0;xr = 1; % boundaries x = xl:h:xr; n = length(x); % number of spatial grids
% initial condition u = x; %u(1:round(n/2))=.5 ;u(round(n/2):end)=0;
U = u;
t = 0; ctr = 0; set(figure,'backingstore','off','doublebuffer','on'); % to avoid blinking on the screen u0 =u;
Temp = zeros(length(0:tau:T),n); Temp(1,:) = u0;
A=zeros(n-2,n-2) for i=1:n-2 if (i==1) A (i,i)=2+g A (i,i+1)=-g elseif (i==n-2) A (i,i)=2+g A (i,i-1)=-g else A (i,i)=2*(1+g) A (i,i-1)=-g A (i,i+1)=-g end end
B=zeros(n-2,n-2) for i=1:n-2 if (i==1) B (i,i)=2-g B (i,i+1)=-g elseif (i==n-2) B (i,i)=2-g B (i,i-1)=-g else B (i,i)=2*(1-g) B (i,i-1)=-g B (i,i+1)=-g end end