0% found this document useful (0 votes)
18 views8 pages

CMTFE Assigment 2 Solution

The document presents a numerical solution to a boundary value problem using the Tri-Diagonal Matrix Algorithm (TDMA) for temperature distribution with specified boundary conditions. It includes multiple implementations of the TDMA method with different functions for calculating coefficients, as well as a Gauss-Seidel iteration for refining the temperature values. The results are plotted to compare the numerical solution with an analytical solution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views8 pages

CMTFE Assigment 2 Solution

The document presents a numerical solution to a boundary value problem using the Tri-Diagonal Matrix Algorithm (TDMA) for temperature distribution with specified boundary conditions. It includes multiple implementations of the TDMA method with different functions for calculating coefficients, as well as a Gauss-Seidel iteration for refining the temperature values. The results are plotted to compare the numerical solution with an analytical solution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Name: Prince Roll: A24ME09010

Solution:

Boundary Condition: T(1)=100 degree Celsius, T(n)=25 degree Celsius

Below is the code of TDMA for the above problem


function f=AE(x,h)
f=((4-(4.*x)-(2.*h)+(x.^2)+(x.*h))/(4-(2.*x)-h))/(0.5*h*(0.5*(h+h)));
end

function f=AW(x,h)
f=(((4-(4.*x)+(2.*h)+(x.^2)-(x.*h)))/(4-(2.*x)+h))/(0.5*h*(0.5*(h+h)));
end

h=0.1;
n=0:h:1;
a=zeros(1,length(n));
b=zeros(1,length(n));
c=zeros(1,length(n));
d=zeros(1,length(n));
AT=zeros(1,length(n));
Fi=zeros(1,length(n));
P=zeros(1,length(n));
Q=zeros(1,length(n));
T=zeros(1,length(n));
c(1)=0;
b(end)=0;
A=54.10106;
B=25;

for i=1:length(n)
b(i)=AE(n(i),h);
c(i)=AW(n(i),h);
a(i)=b(i)+c(i);
end
for i=1:length(n)

if i==1
P(i)=0;
Q(i)=100;
elseif i==length(n)
Q(i)=25;
else
P(i)=(b(i)/(a(i)-(c(i)*P(i-1))));
Q(i)=((c(i)*Q(i-1)))/(a(i)-(c(i)*P(i-1)));
end
end
for i=length(n):-1:1
if i==length(n)
T(i)=Q(i);
else
T(i)=P(i)*T(i+1) + Q(i);
end
end
%disp(a)
%disp(c)
%disp(b)
%disp(P)
%disp(Q)
disp(T)

for i=1:length(n)
AT(i)=(2*A*log(2-n(i))) +B;
end

disp(AT)

T0=100;
T1=25;
n=0:0.1:1;
error=1;
tol=0.001;
iter=0;
Tx=zeros(1,length(n));
Tx(1)=T0;
Tx(length(n))=T0;
Told=Tx;
while (error>tol)
for i=1:length(n)
if i==1
Tx(i)=T0;
elseif i==length(n)
Tx(i)=T1;
else
Tx(i)=0.5.*(Told(i-1)+Told(i+1));
end
end
error=max(abs(Tx-Told));
Told=Tx;
iter=iter+1;
if mod(iter,50)==0
plot(n,Tx)

end
end
hold on
plot(n,T)
plot(n,AT)
xlabel("Nodes")
ylabel("Temperature")
legend('GS Iteration','Numerical Solution', 'Analytical Solution')
Solution:

Boundary Condition: T(1)=100 degree Celsius, T(n)=25 degree Celsius

Below is the code of TDMA for the above problem


function f=AE2(x,h)
f=((4+(4.*x)+(x.^2)+(2.*h)+(h.*x))/(4+(2.*x)+h)/(0.5*h*(0.5*(h+h))));

function f=AW2(x,h)
f=((4+(4.*x)+(x.^2)-(2.*h)-(h.*x))/(4+(2.*x)-h))/(0.5*h*(0.5*(h+h)));

end

h=0.1;
n=0:h:1;
a=zeros(1,length(n));
b=zeros(1,length(n));
c=zeros(1,length(n));
d=zeros(1,length(n));
AT=zeros(1,length(n));
Fi=zeros(1,length(n));
P=zeros(1,length(n));
Q=zeros(1,length(n));
T=zeros(1,length(n));
c(1)=0;
b(end)=0;
A=-92.486;
B=228.21;

for i=1:length(n)
b(i)=AE2(n(i),h);
c(i)=AW2(n(i),h);
a(i)=b(i)+c(i);
end
for i=1:length(n)

if i==1
P(i)=0;
Q(i)=100;
elseif i==length(n)
Q(i)=25;
else
P(i)=(b(i)/(a(i)-(c(i)*P(i-1))));
Q(i)=((c(i)*Q(i-1)))/(a(i)-(c(i)*P(i-1)));
end
end

for i=length(n):-1:1
if i==length(n)
T(i)=Q(i);
else
T(i)=P(i)*T(i+1) + Q(i);
end
end
%disp(a)
%disp(c)
%disp(b)
%disp(P)
%disp(Q)
disp(T)

T0=100;
T1=25;
n=0:0.1:1;
error=1;
tol=0.001;
iter=0;
Tx=zeros(1,length(n));
Tx(1)=T0;
Tx(length(n))=T0;
Told=Tx;
while (error>tol)
for i=1:length(n)
if i==1
Tx(i)=T0;
elseif i==length(n)
Tx(i)=T1;
else
Tx(i)=0.5.*(Told(i-1)+Told(i+1));
end
end
error=max(abs(Tx-Told));
Told=Tx;
iter=iter+1;
if mod(iter,50)==0
plot(n,Tx)

end
end

hold on
plot(n,T)
for i=1:length(n)
AT(i)=(2*A*log(2+n(i))) +B;
end
plot(n,AT)
disp(AT)
xlabel("Nodes")
ylabel("Temperature")
legend('GS Iteration','Numerical Solution', 'Analytical Solution')
Solution:

Boundary Condition: T(1)=100 degree Celsius, T(n)=25 degree Celsius

Below is the code of TDMA for the above problem


function f=AE3(h)
f=1/(0.5*h*(0.5*(h+h)));
end

function f=AW3(h)
f=1/(0.5*h*(0.5*(h+h)));
end

h=0.1;
n=0:h:1;
a=zeros(1,length(n));
b=zeros(1,length(n));
c=zeros(1,length(n));
d=zeros(1,length(n));
AT=zeros(1,length(n));
Fi=zeros(1,length(n));
P=zeros(1,length(n));
Q=zeros(1,length(n));
T=zeros(1,length(n));
c(1)=0;
b(end)=0;
A=-75;
B=100;

for i=1:length(n)
b(i)=AE3(h);
c(i)=AW3(h);
a(i)=b(i)+c(i);
end
for i=1:length(n)

if i==1
P(i)=0;
Q(i)=100;
elseif i==length(n)
Q(i)=25;
else
P(i)=(b(i)/(a(i)-(c(i)*P(i-1))));
Q(i)=((c(i)*Q(i-1)))/(a(i)-(c(i)*P(i-1)));
end
end

for i=length(n):-1:1
if i==length(n)
T(i)=Q(i);
else
T(i)=P(i)*T(i+1) + Q(i);
end
end
%disp(a)
%disp(c)
%disp(b)
%disp(P)
%disp(Q)
disp(T)
for i=1:length(n)
AT(i)=(A*n(i))+B;
end

disp(AT)

T0=100;
T1=25;
n=0:0.1:1;
error=1;
tol=0.001;
iter=0;
Tx=zeros(1,length(n));
Tx(1)=T0;
Tx(length(n))=T0;
Told=Tx;
while (error>tol)
for i=1:length(n)
if i==1
Tx(i)=T0;
elseif i==length(n)
Tx(i)=T1;
else
Tx(i)=0.5.*(Told(i-1)+Told(i+1));
end
end
error=max(abs(Tx-Told));
Told=Tx;
iter=iter+1;
if mod(iter,50)==0
plot(n,Tx)

end
end
hold on
plot(n,T)
plot(n,AT)
xlabel("Nodes")
ylabel("Temperature")
legend('GS Iteration','Numerical Solution', 'Analytical Solution')

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy