0% found this document useful (0 votes)
125 views7 pages

Set6s 03

The document contains 6 problems related to numerical methods. Problem 1 asks to solve a 2D steady-state heat conduction problem using the ADI method. Problem 2 solves a 2D diffusion equation using finite differences and Gauss-Seidel iteration. Problem 3 similarly solves a 2D diffusion equation with specified boundary conditions. Problem 4 determines temperatures and heat transfer for a rectangular bar using Gauss-Seidel iteration. Problem 5 calculates a stiffness ratio for a system of equations. Problem 6 fits different functions to data using least squares regression and nonlinear regression.

Uploaded by

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

Set6s 03

The document contains 6 problems related to numerical methods. Problem 1 asks to solve a 2D steady-state heat conduction problem using the ADI method. Problem 2 solves a 2D diffusion equation using finite differences and Gauss-Seidel iteration. Problem 3 similarly solves a 2D diffusion equation with specified boundary conditions. Problem 4 determines temperatures and heat transfer for a rectangular bar using Gauss-Seidel iteration. Problem 5 calculates a stiffness ratio for a system of equations. Problem 6 fits different functions to data using least squares regression and nonlinear regression.

Uploaded by

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

EGR511 NUMERICALMETHODS_______________________

LAST NAME, FIRST


Problem set #6

1. Considertwodimensional,steadystateconductioninasquarecross
sectionshown.Thetopsurfaceisat50 oC,therightsurfaceisat100oC,
thebottomsurfaceisat150oC,andtheleftsurfaceisat200oC.Assume
T1=75oC,T2=100oC,T3=125oC,andT4=150oCatlevelm.Determine
thenextvaluesofT'susingADImethod(iteratefromlevelmtom+1/2
andm+1).

Ans:

50 50 50 50
200 120.49 95.081 100
200 149.22 123.2 100
200 150 150 100

2.Solvethefollowingequation
2T 2T
+ =0
x 2 y 2
when the boundaries are held as shown

% Problem 2, set 6
T=zeros(5,6);
T(1,:)=[0 60 120 180 240 300];
T(:,6)=[300 225 150 75 0]';
for n=1:100
Tsave=T;
for i=2:4
for j=2:5
T(i,j)=.25*(T(i,j-1)+T(i,j+1)+T(i-1,j)+T(i+1,j));
end
end
if max(abs(T-Tsave))<.0001, break, end
end
fprintf('# of iterations = %g\n',n)
disp('T =');disp(T)

# of iterations = 26
T =
0 60.0000 120.0000 180.0000 240.0000 300.0000
0 44.9999 89.9999 134.9999 180.0000 225.0000
0 29.9999 59.9999 89.9999 120.0000 150.0000
0 15.0000 30.0000 45.0000 60.0000 75.0000
0 0 0 0 0 0
3. Solve the following equation
2T 2T
+ =0 x = 0, T = 500 x = 1, T = 400
x 2 y 2
T
y = 0, y = 10(T - 300) y = 1, T = 500

by finite difference (x = y = 0.25), using Gauss-Seidel method. Error tolerance = 0.0001

% Problem 3 set 6
T=450*ones(5,5);
T(1,:)=400;T(5,:)=500;T(:,5)=500;
for n=1:100
Tsave=T;
for i=2:4
T(i,1)=(T(i-1,1)+T(i+1,1)+2*T(i,2)+1500)/9;
for j=2:4
T(i,j)=.25*(T(i,j-1)+T(i,j+1)+T(i-1,j)+T(i+1,j));
end
end
if max(abs(T-Tsave))<.0001, break, end
end
fprintf('# of iterations = %g\n',n)
disp('T =');disp(T)

# of iterations = 13
T =
400.0000 400.0000 400.0000 400.0000 500.0000
333.6889 386.2133 416.4985 445.4567 500.0000
330.7737 394.6658 434.3237 465.3283 500.0000
353.9421 427.3525 460.8022 481.5326 500.0000
500.0000 500.0000 500.0000 500.0000 500.0000
4. A long bar of rectangular cross section is 60 mm by 90 mm on a side
and have a thermal conductivity of 1 W/moK. The top surface is exposed
to a convection process with air at 100oC and a convection coefficient of
100 W/m2oK, while the remaining surfaces are maintained at 50oC. Using
a grid spacing of 30 mm and the Gauss-Seidel iteration method, determine
the nodal temperatures and the heat transfer rate per unit length normal to
the page into the bar from the air.
T 1

T 2

T 3

T1 = 81.69oC, T2 = 58.45oC, T3 = 52.11oC, q = 205 W/m

5. Determine the stiffness ratio for the following set of equations


u1 = 32u1 + 66u2 and u2 = - 66u1 - 133u2

Ans: SR = 100

6. (P. Chapra 17.13) Given the data

x 5 10 15 20 25 30 35 40 45 50
y 16 25 32 33 38 36 39 40 42 42

use least-squares regression to fit


(a) a straight line, y = a + bx,
(b) a power equation, y = axb,
x
(c) a saturation-growth-rate equation, y = a , and
b x
(d) a parabola, y = a + bx + cx2.
Plot the data along with all the curves in (a), (b), (c) and (d). Is any one of the curves superior? If
so, justify.

x
(e) Use nonlinear regression to fit a saturation-growth-rate equation, y = a , to the data.
b x

Solution

% Problem 6.6
x=[5 10 15 20 25 30 35 40 45 50];
y=[16 25 32 33 38 36 39 40 42 42];
n=length(x);
coef=polyfit(x,y,1);
ycal=polyval(coef,x);
S=sum((ycal-y).^2);
yave=mean(y);
Sdev=sum((y-yave).^2);
stde=sqrt(S/(n-2));
cor=sqrt(1-S/Sdev);
coef1=coef;
fprintf('y = a+bx, a = %8.5f, b = %8.5f\n',coef(2),coef(1))
fprintf('Standard error = %8.4f\n',stde)
fprintf('Correlation coefficient = %8.4f\n',cor)
disp(' ')
xlog=log(x);ylog=log(y);
coef=polyfit(xlog,ylog,1);
a=exp(coef(2));b=coef(1);
ycal=a*x.^b;
S=sum((ycal-y).^2);
stde=sqrt(S/(n-2));
cor=sqrt(1-S/Sdev);
a2=a;b2=b;
fprintf('y = ax^b, a = %8.5f, b = %8.5f\n',a,b)
fprintf('Standard error = %8.4f\n',stde)
fprintf('Correlation coefficient = %8.4f\n',cor)
disp(' ')
xi=1.0./x;yi=1.0./y;
coef=polyfit(xi,yi,1);
a=1/coef(2);b=a*coef(1);
ycal=a*x./(b+x);
S=sum((ycal-y).^2);
stde=sqrt(S/(n-2));
cor=sqrt(1-S/Sdev);
a3=a;b3=b;
fprintf('y = ax/(b+x), a = %8.5f, b = %8.5f\n',a,b)
fprintf('Standard error = %8.4f\n',stde)
fprintf('Correlation coefficient = %8.4f\n',cor)
disp(' ')
coef=polyfit(x,y,2);
ycal=polyval(coef,x);
S=sum((ycal-y).^2);
stde=sqrt(S/(n-2));
cor=sqrt(1-S/Sdev);
fprintf('y = a+bx+cx^2, a = %8.5f, b = %8.5f, c = %8.5f\n',coef(3),coef(2),coef(1))
fprintf('Standard error = %8.4f\n',stde)
fprintf('Correlation coefficient = %8.4f\n',cor)
xmax=max(x);xmin=min(x);
x1=[xmin xmax];
y1=polyval(coef1,x1);
dx=(xmax-xmin)/50;
x2=xmin:dx:xmax;
y2=a2*x2.^b2;
y3=a3*x2./(b3+x2);
y4=polyval(coef,x2);
plot(x,y,'o',x1,y1,'k',x2,y2,'r:',x2,y3,'g-.',x2,y4,'b--')
xlabel('x');ylabel('y')
legend('data','y=a+bx','y=ax^b','y=ax/(b+x)','y=a+bx+cx^2',4)

>> s5d10
y = a+bx, a = 20.66667, b = 0.49576
Standard error = 3.7281
Correlation coefficient = 0.9056

y = ax^b, a = 9.65828, b = 0.39503


Standard error = 2.5472
Correlation coefficient = 0.9571

y = ax/(b+x), a = 52.24201, b = 11.14680


Standard error = 1.3251
Correlation coefficient = 0.9886

y = a+bx+cx^2, a = 12.16667, b = 1.34576, c = -0.01545


Standard error = 2.0115
Correlation coefficient = 0.9735
>>
(c) is best because standard error is smallest.

50

45

40

35
y

30

25

data
y=a+bx
20
y=axb
y=ax/(b+x)
2
y=a+bx+cx
15
5 10 15 20 25 30 35 40 45 50
x
x
(e) Use nonlinear regression to fit a saturation-growth-rate equation, y = a , to the data.
b x

% Gauss-Newton method
%
x=[5 10 15 20 25 30 35 40 45 50]';
y=[16 25 32 33 38 36 39 40 42 42]';
n=length(x);
a=50;b=10;
ymodel='a*x./(b+x)';
dyda='x./(b+x)';dydb='-a*x./(b+x).^2';
for i=1:2
Zj=[eval(dyda) eval(dydb)];
ZjTZj=Zj'*Zj
D=y-eval(ymodel)
ZjTD=Zj'*D
dA=ZjTZj\ZjTD
a=a+dA(1);
b=b+dA(2);
fprintf('Iteration #%g: a = %8.4f, b = %8.4f\n',i,a,b)
end

>> s5p10e
ZjTZj =
4.8471 -6.3875
-6.3875 9.8141
D=
-0.6667
0
2.0000
-0.3333
2.2857
-1.5000
0.1111
0
1.0909
0.3333
ZjTD =
2.5200
-3.3539
dA =
0.4887
-0.0237
Iteration #1: a = 50.4887, b = 9.9763
ZjTZj =
4.8531 -6.4641
-6.4641 10.0416
D=
-0.8562
-0.2743
1.6781
-0.6857
1.9122
-1.8889
-0.2897
-0.4101
0.6733
-0.0905
ZjTD =
-0.0016
0.0034
dA =
1.0e-003 *
0.8300
0.8694
Iteration #2: a = 50.4895, b = 9.9772
>>

You might also like