0% found this document useful (0 votes)
1 views1 page

Mod 1 Assign

The document outlines a MATLAB implementation of the Finite Difference Method (FDM) to solve a heat conduction problem in a rod. It defines parameters such as length, total time, and thermal diffusivity, and initializes a solution matrix for temperature distribution over time. The algorithm iteratively updates the temperature values until the residual error is below a specified threshold.

Uploaded by

akhileshpandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

Mod 1 Assign

The document outlines a MATLAB implementation of the Finite Difference Method (FDM) to solve a heat conduction problem in a rod. It defines parameters such as length, total time, and thermal diffusivity, and initializes a solution matrix for temperature distribution over time. The algorithm iteratively updates the temperature values until the residual error is below a specified threshold.

Uploaded by

akhileshpandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

%% Implementation of FDM to solve above statement

clc;clear;close
% L = 1 Normalised length corresponding to L = 1 m
% T0 initial temperatre at x = 0 , t = 0
% Tf final temperature at x = L , t = tf
L=1; % Length on the rod
T=1;% Total time
alpha = 0.01;% Thermal diffusivity constant
% Discretization
Nx=5;% Number of spatial grid points
Nt=15;% Number of time step size
dt=T/Nt; % Time step size
dx=L/Nx;
x= linspace(0,L,Nx+1); % Spatial Grid
t=linspace(0,T,Nt+1); % Time Grid
% Initial condition:u(x,0)=T0 + (TL-T0)*(x/L)^2;
U0=0;
% Initialize solution matrix
U = zeros(Nx,Nt);
U(Nx,:) = 100;% Initial condition
U_new = U;
epsilon = 0.0000001; %
Residual = 1;
while Residual > epsilon
% Finite Difference Mehtod
for n=1:Nt
for i = 2:Nx-1
U_new(i,n+1)=U(i,n)+alpha*dt/(dx)^2*(U(i+1,n)-2*U(i,n)+U(i-1,n));
end
end
% Calculate the error/residual
Residual = sum(sum(abs(U_new(i,n) - U(i,n))));
% Transfer the new values into older variable
U = U_new; % Iterations can take place
end

You might also like