Вы находитесь на странице: 1из 6

EE 231 Winter 2004

Numerical Analysis for Electrical and Computer Engineers


Solutions to Assignment 1
Due: Friday January 30, 2004
Department of Electrical and Computer Engineering
University of Alberta

Question 1. [Exercise Set 3, #3.6] Evaluate e8.3 using two approaches


ex = 1 x +
and
ex =

x3
x2

+
2!
3!

1
=
ex
1+x+

1
+

x2
2!

x3
3!

and compare with the true value of 2.485168 104 and discuss your results. Use 25 terms to evaluate each
series.
Solution: The true value (correct to 6 decimal places) of e8.3 is 2.485168 104 . The C program on the
following page was used to calculate the partial sums of the Maclaurin series for e8.3 and e8.3 , and then
calculate the reciprocals of the partial sums for e8.3 . The output is shown below:

>>cc -o exp exp.c -lm


>>exp
Enter N:
25
Enter x:
8.3
exp[1] =
-7.3000000000
exp[2] = -41.7450000000
exp[3] =
53.5528333333
exp[4] = 251.2958375000
exp[5] = -76.9575494167
exp[6] = -531.0414013181
exp[7] =
7.3723087936
exp[8] = 565.9765330344
exp[9] =
50.8193040123
exp[10] = -376.7611960760
exp[11] = -54.1322732821
exp[12] = 169.0193983170
exp[13] =
26.5456387576
exp[14] = -57.9209472669
exp[15] = -11.1827696667
exp[16] =
13.0626599634
exp[17] =
1.2251854970
exp[18] =
-4.2332055070
exp[19] =
-1.8487504895
exp[20] =
-0.8592016572
exp[21] =
-1.2503090528
exp[22] =
-1.3978632066
exp[23] =
-1.3446154033
exp[24] =
-1.3262005380
exp[25] =
-1.3323142733

1/exp[1]
1/exp[2]
1/exp[3]
1/exp[4]
1/exp[5]
1/exp[6]
1/exp[7]
1/exp[8]
1/exp[9]
1/exp[10]
1/exp[11]
1/exp[12]
1/exp[13]
1/exp[14]
1/exp[15]
1/exp[16]
1/exp[17]
1/exp[18]
1/exp[19]
1/exp[20]
1/exp[21]
1/exp[22]
1/exp[23]
1/exp[24]
1/exp[25]

=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=

0.1075268817
0.0228597554
0.0071920284
0.0029692460
0.0015036707
0.0008935568
0.0006033049
0.0004512348
0.0003661263
0.0003165680
0.0002872319
0.0002699304
0.0002599338
0.0002543494
0.0002513613
0.0002498386
0.0002491019
0.0002487637
0.0002486162
0.0002485551
0.0002485309
0.0002485218
0.0002485185
0.0002485174
0.0002485170

As is obvious from the output, the first approximation fails because of catastrophic cancellation and roundoff errors, while the second approximation is good to approximately 5 significant figures. Usually, Taylor
series approximations are notoriously bad unless the function is being evaluated near the point about which
the expansion is done.

#include <stdio.h>
#include <math.h>
double expa(double x, int N)
{
int k;
double sum;
sum = 1.0;
for (k = N;
{
if (k%2
sum
else
sum
}
return sum;

k > 0; k--)
== 1)
= 1 - sum*x/(double)k;
= 1 + sum*x/(double)k;

}
double expb(double x, int N)
{
int k;
double sum;
sum = 1.0;
for (k = N; k > 0; k--)
sum = 1 + sum*x/(double)k;
return sum;
}
int main()
{
int k, N;
double x;
printf("Enter N:\n");
scanf("%d",&N);
printf("Enter x:\n");
scanf("%lf",&x);
for (k = 1; k <= N; k++)
printf("exp[%d] = %.10lf
return 0;

1/exp[%d] = %.10lf\n",k,expa(x,k),k,1.0/expb(x,k));

Question 2. [Exercise Set 3, #3.8]

(a) Evaluate the polynomial


y = x3 5x2 + 6x + 0.55
at x = 2.73. Use 3digit arithmetic with chopping. Evaluate the error.
(b) Repeat (a) but express y as
y = [(x 5)x + 6] x + 0.55
Evaluate the percent relative error and compare it with part (a).

Solution:
(a) Using 3-digit arithmetic with chopping, we have
x3 = 20.3
5x2 = 37.2
6x = 16.3
0.55 = 0.55
so that y = x3 5x2 + 6x 0.55 = 0.05. Comparing this with the true value y = 0.011917, the
relative error is
er (y) =

0.011917 (0.05)
= 5.1957,
0.011917

or 519.57%.
(b) Again, using 3-digit arithmetic, we have
x 5 = 2.73 5.00 = 2.27
(x 5)x = 2.73 (2.27) = 6.19
(x 5)x + 6 = 0.19
[(x 5)x + 6]x = 0.19 2.73 = 0.518
[(x 5)x + 6]x + 0.55 = 0.032
so that in this case, y = 0.032. Comparing this with the true value y = 0.011917, the relative error is
er (y) =

0.011917 0.032
= 1.6852,
0.011917

or 168.52%. Thus, using Horners method to evaluate the polynomial has reduced the error quite a
bit.

Question 3. [Exercise Set 4, #4.5] Use zero- through fourth-order Taylor series expansions to predict
f (3) for f (x) = ln x using a base point at x = 1. Compute the true percent relative error t for each
approximation. Discuss the meaning of the results.
Solution: We have the Maclaurin series expansion
Z x
1
x2
x3
xn
1
ln
=
dt = x +
+
+ +
+
1x
2
3
n
0 1t
and the series converges for all x in the interval 1 x < 1. Replacing x by 1 x, we have
ln x = 1 x +

(1 x)2
(1 x)3
(1 x)4
(1 x)n
+
+
+ +
+ ,
2
3
4
n

that is,

(x 1)3
(x 1)4
(x 1)n
(x 1)2
+

+ + (1)n1
+ ,
2
3
4
n
and the series converges for 0 < x 2. As we noted in class, since Taylor series expansions are unique, it
doesnt matter how you find it, this is the Taylor series expansion for f (x) = ln x about the base point x = 1.
Note that the series diverges for x = 3. It is now an easy matter to calculate the zero- through fourth-order
Taylor polynomials to predict f (3) = ln 3.
ln x = x 1

Zero-Order:
f (3) = f (1) = ln 1 = 0,
er (ln 3) = 100%.
First-Order:
31
= 2,
1
er (ln 3) = 82.05%.
f (3) = 0 +

Second-Order:
(3 1)2
= 0,
2
er (ln 3) = 100%.
f (3) = 2

Third-Order:
8
(3 1)3
= ,
3
3
er (ln 3) = 142.7%.
f (3) = 0 +

Fourth-Order:
8 (3 1)4
4

= ,
3
4
3
er (ln 3) = 221.36%.
f (3) =

Question 4. [Exercise Set 4, #4.7] Use a centered difference approximation of O(h2 ) to estimate the
second derivative of the function examined in problem 4.4, namely,
f (x) = 25x3 6x2 + 7x 88.
Perform the evaluation at x = 2 using step sizes of h = 0.2 and 0.1. Compare your estimates with the true
value of the second derivative. Interpret your results on the basis of the remainder term of the Taylor series
expansion.
Solution: Since f (x) = 75x2 12x + 7, then
f (x) = 150x 12,
and the true value of the second derivative at x = 2 is f (2) = 150 2 12 = 288.
For h = 0.2, we have
f (2)
For h = 0.1, we have
f (2)

164.56 2 102 + 50.92


= 288
(0.2)2

131.765 2 102 + 75.115


= 288
(0.1)2

Both answers are exact, since as we showed in class, the error in the 3-point approximation to the second
derivative is proportional to the 4th derivative, which is identically zero for a polynomial of degree 3.

Question 5. [Exercise Set 4, #4.11] The Stefan-Boltzmann law can be employed to estimate the rate
of radiation of energy H from a surface, as in
H = AeT 4
where H is in watts, A = the surface area (m2 ), e = the emissivity that characterizes the emitting properties
of the surface (dimensionless), = a universal constant called the Stefan-Boltzmann constant (= 5.67 108
W m2 K4 ), and T = absolute temperature (K). Determine the error of H for a copper sphere with raduis
= 0.15 0.02 m, e = 0.90 0.05, and T = 550 25. Compare your results with the exact error. Repeat the
computation but with T = 550 50. Interpret your results.
Solution: For a sphere of radius r the surface area is given by A = 4r2 , and we have
H = 4r2 eT 4 .
Retaining only the linear terms in the Taylor series expansion, the change in H is approximately
H

H
H
H
r +
e +
T
r
e
T

Now, at the nominal values r = 0.15, e = 0.90, and T = 550, we have


H
= 8reT 4 = 17604
r
H
= 4r2 T 4 = 1467
e
H
= 16r2 eT 3 = 9.6,
T
and since r = 0.02, e = 0.05, and T = 25, then
H 17604 0.02 + 1467 0.05 + 9.6 25 = 665.4.

The value of H at the extreme upper values of the interval of uncertainty is


H(0.17, 0.95, 575) = 2138.4,
while the value of H at the extreme lower values of the interval of uncertainty is
H(0.13, 0.85, 525) = 777.6.
Thus, the interval of uncertainty in H is [777.6, 2138.4], and the true error, that is, the absolute error, is
therefore half the length of this interval
HTrue =

2138.4 777.6
= 680.4,
2

which is close to the estimated error.

Question 6. [Exercise Set 4, #4.12(d)] Evaluate and interpret the condition number for
f (x) =

ex 1
x

for x = 0.01.
Solution: The condition number for the problem of evaluating f (x) =

ex 1
at x = 0.01 is given by
x



ex (x 1) + 1
xf (x)
=
= 0.0050
CN =

f (x) x=0.01
ex 1
x=0.01

so that |CN | << 1, and therefore the problem is well-conditioned, that is, a small change in the input x will
cause a relatively small change in the output f (x).

Question 7. [Exercise Set 4, #4.12(e)] Evaluate and interpret the condition number for
f (x) =

sin x
1 + cos x

for x = 1.001.
Solution: The condition number for the problem of evaluating f (x) =

sin x
at x = 1.001 is
1 + cos x


xf (x)
CN =
,
f (x) x=1.001

and
f (x) =
so that
CN =

(1 + cos x) cos x + sin x sin x


,
(1 + cos x)2

1.001f (1.001)
3.144 202642
=
= 1001,
f (1.001)
636.6

and |CN | >> 1. Therefore, the problem of evaluating f (x) at x = 1.001 is ill-conditioned, that is, a small
change in x may cause a relatively large change in f (x). The problem arises because 1 + cos(1.001) 0.

Вам также может понравиться