Professional Documents
Culture Documents
1 Instructions
Make a pdf report including the solution to each point of the practice with name
Lab8 name lastname.pdf.
Send the report and all created files in a rar or zip file with name Lab8 name lastname.rar in
the Moodle.
You are allowed to use internet, notes, and .m files that you have created before.
2 Purposes
To apply numerical differentiation methods.
3 Practice
3.1 Applying
(1.5 points) Let f (x) = cos(x) and carry eight or nine decimal places.
(1.0 point) The following Table presents some values of f (x) rounded to six decimal places. Use the
numerical differentiation forward-formula of order O(h2 ) with h = 0.05 to find an approximation of
f 00 (−3.5) by assuming f 00 (x) = f 00 (−x + 0.5). Hint. Recall that f 00 (x0 ) ≈ 2f0 −5f1h+4f
2
2 −f3
.
1
3.2 Implementing
(2.5 points) Use the Program 1 to approximate the derivatives of each of the following functions at
the given value of x. Approximations should be accurate to 13 decimal places.
Note. It may be necessary to change the values of max1 and the initial value of h in the program.
√
a) f (x) = 60x45 − 32x33 + 233x5 − 47x2 − 77; x = 1/ 3
√ !! √
5 + sin(x) 1+ 5
b) f (x) = tan cos ; x=
1 + x2 3
√
1− 5
c) f (x) = sin(x3 − 7x2 + 6x + 8); x = 2
4 Appendices
Equation (6)
f1 − 2f0 + f−1
f 00 (x0 ) = + E(f, h)
h2
2 (4)
4ε h f (c)
E(f, h) = 2 +
h 12
Equation (12)
−f2 + 16f1 − 30f0 + 16ff −1 − f−2
f 00 (x0 ) = + E(f, h)
12h2
4 (6)
16ε h f (c)
E(f, h) = 2 +
3h 90
2
Listing 1: Program 1 (Differentiation using Limits)
function [ L , n]= d i f f l i m ( f , x , t o l e r )
%I n p u t − f i s the
f u n c t i o n i n p u t as a s t r i n g ’ f ’
% − x is thed i f f e r e n t i a t i o n point
% − toler isthe desired tolerance
%Output − L=[H’ D’E ’ ] : H i s the vector of step s i z e s
% D i s the v e c t o r of approximate d e r i v a t i v e s
% E i s t h e v e c t o r o f e r r o r bounds
% − n i s the coordinate of the ” b e s t approimation ”
max1=15;
h =1/10;
H(1)=h ;
D(1)=( f e v a l ( f , x+h)− f e v a l ( f , x−h ) ) / ( 2 * h ) ;
E( 1 ) = 0 ;
R( 1 ) = 0 ;
f o r n=1:2
h=h / 1 0 ;
H( n+1)=h ;
D( n+1)=( f e v a l ( f , x+h)− f e v a l ( f , x−h ) ) / ( 2 * h ) ;
E( n+1)=abs (D( n+1)−D( n ) ) ;
R( n+1)=2*E( n+1) * ( abs (D( n+1))+abs (D( n))+ eps ) ;
end
n=2;