Download Set 5

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Horner's method wikipedia , lookup

Newton's method wikipedia , lookup

System of linear equations wikipedia , lookup

Root-finding algorithm wikipedia , lookup

System of polynomial equations wikipedia , lookup

Least squares wikipedia , lookup

Coefficient of determination wikipedia , lookup

False position method wikipedia , lookup

Transcript
EGR 511
NUMERICAL METHODS
_______________________
LAST NAME, FIRST
Problem set #5
1. Determine the stiffness ratio for the following set of equations
dy1
dy 2
= -600y1 + 550y2;
= 550y1 – 600y2
dx
dx
SR = __________
Ans: SR = 23
2. Express the third-order equation
''
'
y''' + ty - ty - 2y = t, y(0) = y''(0) = 0, y'(0) = 1,
as a set of first-order equations and solve at t = 0.2, 0.4, 0.6 by the Fourth-order Runge-Kutta
method (h = 0.2).
Ans: t = 0.6, y = 0.62097, y’ = 1.1379, y” = 0.67326
3. Use the Runge-Kutta method with h = 0.2 for to approximate the solutions of the following
systems of first-order differential equations and compare the results to the actual solutions.
u1’ = 3u1 + 2u2 – (2t2 + 1)e2t, for 0  t  1 with u1(0) = 1;
u2’ = 4u1 + u2 + (t2 + 2t - 4)e2t, for 0  t  1 with u2(0) = 1;
1
1
1
2
actual solutions u1(t) = e5t - e-t + e2t and u2(t) = e5t + e-t + t2e2t
3
3
3
3
Fourth-order Runge-Kutta method (h = 0.2)
u1p='3*u1+2*u2-(2*t*t+1)*exp(2*t)';
u2p='4*u1+u2+(t*t+2*t-4)*exp(2*t)';
h=0.2;t=0;u1=1;u2=1;hs=h/2;
for i=1:5
u1s=u1;u2s=u2;
k11=eval(u1p);k12=eval(u2p);
t=t+hs;u1=u1s+hs*k11;u2=u2s+hs*k12;
k21=eval(u1p);k22=eval(u2p);
u1=u1s+hs*k21;u2=u2s+hs*k22;
k31=eval(u1p);k32=eval(u2p);
t=t+hs;u1=u1s+h*k31;u2=u2s+h*k32;
k41=eval(u1p);k42=eval(u2p);
u1=u1s+h*(k11+2*k21+2*k31+k41)/6;
u2=u2s+h*(k12+2*k22+2*k32+k42)/6;
end
fprintf('Calculated u1(1) = %8.6f , u2(1) = %8.6f\n',u1,u2)
u1c=exp(5)/3-exp(-1)/3+exp(2);
u2c=exp(5)/3+2*exp(-1)+exp(2);
fprintf('Actual u1(1) = %8.6f , u2(1) = %8.6f\n',u1c,u2c)
>> s5p3
Calculated u1(1) = 55.661181 , u2(1) = 56.030503
Actual u1(1) = 56.737483 , u2(1) = 57.595868
4. a) Solve the following stiff initial-value problems using Euler’s method and compare the
results with the actual solution.
i) y’ = - 9y, for 0  t  1 with y(0) = e and h = 0.1; actual solution y(t) = e1-9t.
1
ii) y’ = - 20(y – t2) + 2t, for 0  t  1 with y(0) = and h = 0.1;
3
1
actual solution y(t) = t2 + e-20t.
3
b) Repeat Exercise (a) using the Runge-Kutta Fourth-Order method.
y1p='-9*y1';
y2p='-20*(y2-t*t)+2*t';
h=.1;t=0;y1=exp(1);y2=1/3;
for i=1:10
y1=y1+h*eval(y1p);y2=y2+h*eval(y2p);
t=t+h;
end
disp('Euler method')
fprintf('Calculated y1(1) = %8.6f , y2(1) = %8.6f\n',y1,y2)
t=0;y1=exp(1);y2=1/3;hs=h/2;
for i=1:10
y1s=y1;y2s=y2;
k11=eval(y1p);k12=eval(y2p);
t=t+hs;y1=y1s+hs*k11;y2=y2s+hs*k12;
k21=eval(y1p);k22=eval(y2p);
y1=y1s+hs*k21;y2=y2s+hs*k22;
k31=eval(y1p);k32=eval(y2p);
t=t+hs;y1=y1s+h*k31;y2=y2s+h*k32;
k41=eval(y1p);k42=eval(y2p);
y1=y1s+h*(k11+2*k21+2*k31+k41)/6;
y2=y2s+h*(k12+2*k22+2*k32+k42)/6;
end
disp('Runge-Kutta 4th order')
fprintf('Calculated y1(1) = %8.6f , y2(1) = %8.6f\n',y1,y2)
y1c=exp(-8);
y2c=t*t+exp(-20)/3;
fprintf('Actual y1(1) = %8.6f , y2(1) = %8.6f\n',y1c,y2c)
>> s5p4
Euler method
Calculated y1(1) = 0.000000 , y2(1) = 1.333333
Runge-Kutta 4th order
Calculated y1(1) = 0.000372 , y2(1) = 1.002506
Actual y1(1) = 0.000335 , y2(1) = 1.000000
5. The temperatures (K) at the nodal points of a two dimensional system are
shown. The left-side surface is held at a uniform temperature of 500oK, while
the surface A is subjected to a convection boundary condition with a fluid
temperature of 500oK and a heat transfer coefficient of 10 W/m2oK. Calculate
the heat rate leaving the surface A per unit thickness normal to the page.
Estimate the thermal conductivity of the material.
Ans: Heat rate 349 W/m, thermal conductivity 0.77 W/mK
6. The steady state temperature (oC) associated with selected
nodal points of a two-dimensional system having a thermal
conductivity of 1.5 W/moK are shown. The isothermal
boundary is at 200oC.
a) Determine the temperature at nodes 1, 2, and 3.
b) Calculate the heat transfer rate per unit thickness normal to
the page from the system to the fluid.
Ans: a) Node 1: 160.7 oC, node 2: 95.6 oC, node 3: 48.73 oC
b) 743 W/m
7.
a) Show that the Implicit Trapezoidal method, yn+1 = yn + h*(f(xn, yn) + f(xn+1, yn+1))/2, is
A-stable (Stable with any h).
b) Show that the Backward Euler, yn+1 = yn + h* f(xn+1, yn+1) , method is A-stable.
8. Determine the stiffness ratio at x = 1, y1 = 1, y2 = -1 for the following set of equations
dy2
dy1
= - 90xy1 – 100y2;
= 200y1y2 – 90xy2
dx
dx
Ans: SR = 1.123
9. (P. Chapra 17.6) Use least-squares regression to fit a straight line, y = a + bx, to
x
y
2
9
3
6
4
5
7
10
8
9
9
11
5
2
5
3
(a) Along with the slope and intercept, compute the standard error of the estimate and the
correlation coefficient. Plot the data and the straight line. Assess the fit.
(b) Recompute (a), but use polynomial to fit a parabola, y = a + bx + cx2, to the data. Compare
the results with those of (a).
Solution
% Problem 5.9
x=[2 3 4 7 8 9 5 5];
y=[9 6 5 10 9 11 2 3];
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)
coef=polyfit(x,y,2);
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);
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=polyval(coef,x2);
plot(x,y,'o',x1,y1,x2,y2)
xlabel('x');ylabel('y')
>> s5d9
y = a+bx, a = 3.48955, b = 0.62985
Standard error = 3.2214
Correlation coefficient = 0.4589
y = a+bx+cx^2, a = 16.02696, b = -4.80692, c = 0.48894
Standard error = 1.9254
Correlation coefficient = 0.8474
14
12
y
10
8
6
4
2
2
3
4
5
6
x
7
8
9