Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

%%Unsteady state solution of U with Crank-Nicolson scheme (f=0.

5)
clc;
unew=zeros(1,11);
%TDMA CODE variable initialization
P=zeros(1,11);
Q=zeros(1,11);
Q(1)=0;
P(1)=0;
%Boundary condition
up(1)=0;
up(11)=0;
x(1)=0;
x(10)=1;
y=0.1;
n=11;
%Initial Value of Up for delta x=0.1 delta t=0.01
for i=2:10
if (i<=6)
up(i)=2*y;
end
if (i>=7)
up(i)=(2*(1-y));
end
y=y+0.1;
end
ufinal(1,:)=up;
counter=2;
for ts=0.01:0.01:0.2
for i=2:10
ae=0.5;
aw=0.5;
ap=2;
%TDMA Code that calculates every timestep
b(i)=0.5*up(i-1)+0.5*up(i+1);%B matrix
P(i)=(ae/(ap-(aw*P(i-1))));
Q(i)=(b(i)+(aw*Q(i-1)))/(ap-(aw*P(i-1)));
end
Q(11)=unew(11);
for i=10:-1:1
unew(i)=(P(i)*unew(i+1))+Q(i);
end
up=unew;
ufinal(counter,:)=unew;
counter=counter+1;
end

x=0:0.1:1;% Grid Spacing vector


disp(ufinal);
Columns 1 through 7
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0.2000
0.1989
0.1936
0.1826
0.1683
0.1538
0.1399
0.1270
0.1153
0.1045
0.0948
0.0860
0.0779
0.0707
0.0641
0.0581
0.0527
0.0478
0.0433
0.0393
0.0356

0.4000
0.3956
0.3789
0.3515
0.3218
0.2932
0.2664
0.2418
0.2193
0.1989
0.1803
0.1635
0.1483
0.1344
0.1219
0.1105
0.1002
0.0908
0.0824
0.0747
0.0677

0.6000
0.5834
0.5397
0.4902
0.4461
0.4047
0.3672
0.3330
0.3019
0.2738
0.2482
0.2251
0.2041
0.1850
0.1678
0.1521
0.1379
0.1250
0.1134
0.1028
0.0932

0.2000
0.1989
0.1936
0.1826
0.1683
0.1538
0.1399
0.1270
0.1153
0.1045
0.0948
0.0860
0.0779
0.0707
0.0641
0.0581
0.0527
0.0478
0.0433
0.0393
0.0356

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

Columns 8 through 11
0.6000
0.5834
0.5397
0.4902
0.4461
0.4047
0.3672
0.3330
0.3019
0.2738
0.2482
0.2251
0.2041
0.1850
0.1678
0.1521
0.1379
0.1250
0.1134
0.1028
0.0932

0.4000
0.3956
0.3789
0.3515
0.3218
0.2932
0.2664
0.2418
0.2193
0.1989
0.1803
0.1635
0.1483
0.1344
0.1219
0.1105
0.1002
0.0908
0.0824
0.0747
0.0677

0.8000
0.7381
0.6461
0.5843
0.5267
0.4770
0.4321
0.3916
0.3550
0.3219
0.2918
0.2646
0.2399
0.2175
0.1972
0.1788
0.1621
0.1470
0.1333
0.1208
0.1096

1.0000
0.7691
0.6921
0.6152
0.5555
0.5019
0.4546
0.4119
0.3733
0.3385
0.3069
0.2782
0.2522
0.2287
0.2074
0.1880
0.1705
0.1546
0.1401
0.1271
0.1152

0.8000
0.7381
0.6461
0.5843
0.5267
0.4770
0.4321
0.3916
0.3550
0.3219
0.2918
0.2646
0.2399
0.2175
0.1972
0.1788
0.1621
0.1470
0.1333
0.1208
0.1096

Published with MATLAB R2015b

You might also like