c c c c
SOLUTIONS
, SOLUTIONMANUAL c
NUMERICALANDANALYTICALMETHODSWITH
c c c c
MATLAB
Table of Contents
c c
Page
Chapter 2 c 1
Chapter 3 c 46
Chapter 4 c 58
Chapter 5 c 98
Chapter 6 c 107
Chapter 7 c 176
Chapter 8 c 180
Chapter 9 c 188
Chapter 10 c 214
Chapter 11 c 271
Chapter 12 c 303
Chapter 13 c 309
Chapter 14 c 339
@@SSee
isis
mmiciicsis
oolala
titoionn
, CHAPTER 2 c
P2.1. Taylor series expansion of f (x) about x = 0 is:
c c c c c c c c c c c c
f''(0) 2 f'''(0) 3 f 1V 4
f (x) = f (0)+ f '(0) x+ x + x + x +...
c c c c c c c c
c c c c c c c c c c c c c
4!
c c
2! 3! c c
For f (x)=cos(x), c c c c c c c f (0) =1,
c c c
f (x) =−sin(x), f '(0)=0,
c c c c c c c c c c c
f ''(x) = −cos(x), f ''(0)=−1,
c c c c c c c c c c c c c c
f '''(x) = +sin(x), f '''(0)=0,
c c c c c c c c c c c c c c c c
f1V(x)=+cos(x), f 1V(0)=1
c c c c c c c c c c c c
We can see that c c c
x x 4 x6 8 2
cos(x) =1− + − + x −+−+...
c c c
c c c c c
2! 4! 6! 8! c c c
c
and that c
x2
term(k)=−term(k −1)
c
2k (2k −1)
c c c c c c c c
c c c c
The following program evaluates cos(x)by both an arithmetic statement and bythe above
c c c c c c c c c c c c c c
c series for -π ≤ x ≤ π in step of 0.1 .
c c c c c c c c c c c c
% cosf.m
c
% This program evaluates cos(x) by both arithmetic statement and by
c c c c c c c c c c
% series for -π ≤ x ≤ π in steps of 0.1 π
c c c c c c c c c c c c
clear; clc; c
xi=-pi;dx=0.1*pi; c
c for j=1:21
c
x(j)=xi+(j-1)*dx;
cos_arith(j)= cos(x(j)); c
1iciicsisoolalatitoionn
@@SSeeisismm
, sum=1.0;term=1.0; c
for k=1:50
c c
den=2*k*(2*k-1);
term=-term*x(j)^2/den;
sum=sum+term;
c
test=abs(sum*1.0e-6);
c
if abs(term) <= test;
c c c c
break;
end
end
cos_ser(j)=sum;
c
nterms(j)=k;
c
end
fo=fopen('output.dat','w');
c
fprintf(fo,'x cos(x) cos (x) c terms inc c \n');
fprintf(fo,'
c by arith stm
c c by series
c the series
c c \n');
fprintf(fo,'=====================================================\n');
c
for j=1:21
c
fprintf(fo,'%10.5f %10.5f %10.5f %3i\n',...
c
x(j),cos_arith(j),cos_ser(j),nterms(j));
c
fprintf(fo,' \n');
end
fclose(fo);
c
plot(x,cos_arith),xlabel('x'),ylabel('cos(x)'),
title('cos(x) vs. x'),grid;
c c c
2iciicsisoolalatitoionn
@@SSeeisismm