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