SOLUTIONS
, @LECTJULIESOLUTIONSSTUVIA
SOLUTION MANUAL
NUMERICAL AND ANALYTICAL METHODS WITH
MATLAB
Table of Contents
Page
Chapter 2 1
Chapter 3 46
Chapter 4 58
Chapter 5 98
Chapter 6 107
Chapter 7 176
Chapter 8 180
Chapter 9 188
Chapter 10 214
Chapter 11 271
Chapter 12 303
Chapter 13 309
Chapter 14 339
, CHAPTER 2
P2.1. Taylor series expansion of f ( x) about x = 0 is:
f ' ' (0) f ' ' ' (0) f
f ( x) f (0) f ' (0) x x2 x3 1V x 4 ...
2! 3!
4!
For f ( x) cos ( x) f (0) 1,
,
f ( x) sin( x), f ' (0) 0,
f ' ' ( x) cos( x), f ' ' (0) 1,
f ' ' ' ( x) sin( x), f ' ' ' (0) 0,
f 1V ( x) cos( x), f 1V (0) 1
We can see that
x2 x4 x6 8
cos( x) 1 x
... 8!
2! 4! 6!
and that
x2
term (k) term (k 1)
2 k (2 k
1)
The following program evaluates cos( x) by both an arithmetic statement and
by the above series for -π ≤ x ≤ π in step of 0.1 .
% cosf.m
% This program evaluates cos(x) by both arithmetic statement and by
% series for -π ≤ x ≤ π in steps of 0.1 π
clear; clc;
xi=-pi; dx=0.1*pi; for j=1:21
, @LECTJULIESOLUTIONSSTUVIA
x(j)=xi+(j-1)*dx;
cos_arith(j)= cos(x(j));
, sum=1.0; term=1.0; for
k=1:50
den=2*k*(2*k-1);
term=-term*x(j)^2/den;
sum=sum+term;
test=abs(sum*1.0e-6); if
abs(term) <= test;
break;
end
end cos_ser(j)=sum;
nterms(j)=k;
end fo=fopen('output.dat','w');
fprintf(fo,'x cos(x) cos (x) terms in \n'); fprintf(fo,'
by arith stm by series the series \n');
fprintf(fo,'=====================================================\n');
for j=1:21
fprintf(fo,'%10.5f %10.5f %10.5f %3i \n',...
x(j),cos_arith(j),cos_ser(j),nterms(j));
fprintf(fo,' \n');
end fclose(fo);
plot(x,cos_arith),xlabel('x'),ylabel('cos(x)'), title('cos(x) vs. x'),grid;
, @LECTJULIESOLUTIONSSTUVIA
Program result:
x cos(x) cos (x) by terms in the
by arith stm series series
=====================================================
-3.14159 -1.00000 -1.00000 9
-2.82743 -0.95106 -0.95106 8
-2.51327 -0.80902 -0.80902 8
-2.19911 -0.58779 -0.58779 8
-1.88496 -0.30902 -0.30902 7
-1.57080 0.00000 0.00000 14
-1.25664 0.30902 0.30902 6
-0.94248 0.58779 0.58779 5
-0.62832 0.80902 0.80902 4
-0.31416 0.95106 0.95106 4
0.00000 1.00000 1.00000 1
0.31416 0.95106 0.95106 4
0.62832 0.80902 0.80902 4
0.94248 0.58779 0.58779 5
1.25664 0.30902 0.30902 6
1.57080 0.00000 0.00000 14
1.88496 -0.30902 -0.30902 7
2.19911 -0.58779 -0.58779 8
2.51327 -0.80902 -0.80902 8
2.82743 -0.95106 -0.95106 8
3.14159 -1.00000 -1.00000 9
, cos(x) vs. x
1
0.8
0.6
0.4
0.2
cos(x)
0
-0.2
-0.4
-0.6
-0.8
-1
-4 -3 -2 -1 0 1 2 3 4
x
P2.2. Taylor series expansion of f ( x) about x = 0 is:
f ' ' (0) f ' ' ' (0) f
f ( x) f (0) f ' (0) x x2 x3 1V x4 ...
2! 3!
4!
For f ( x) sin ( x) f (0) 0
,
f ( x) cos( x), f ' (0) 1
f ' ' ( x) sin ( x), f ' ' (0) 0
f ' ' ' ( x) cos ( x), f ' ' ' (0) 1
f 1V ( x) sin ( x), f 1V (0) 0
f V ( x) cos ( x), f V (0) 1
, @LECTJULIESOLUTIONSSTUVIA
We can see that
, x x5
3 x7 9
sin ( x) x x
... 9!
3! 5! 7!
and that
x2
term (k) term (k 1)
2 k (2 k
1)
The following program evaluates sin ( x) by both an arithmetic statement
and by the above series for -π ≤ x ≤ π in step of 0.1 .
Program
% sinf.m
% This program evaluates sin(x) by both arithmetic statement and by
% series for -π ≤ x ≤ π in steps of 0.1π
clear; clc;
xi=-pi; dx=0.1*pi; for j=1:21
x(j)=xi+(j-1)*dx;
sin_arith(j)= sin(x(j));
sum=x(j); term=x(j); for
k=1:50
den=2*k*(2*k+1);
term=-term*x(j)^2/den;
sum=sum+term;
test=abs(sum*1.0e-6); if
abs(term) <= test;
break;
, @LECTJULIESOLUTIONSSTUVIA
end