Академический Документы
Профессиональный Документы
Культура Документы
Technology
Course Number: EEE 212
Course Name: Numerical Techniques Laboratory.
Department: EEE
1206054
Exercise 1:
Statement:
Given f(x) =ex , find f(1) using h=10-1, 10-2,,,, upto 10-10. Find out the error in
each case by comparing the calculated value with exact value.
M File:
close all;
clear all;
clc;
x=1;
for i=1:10
h=10^(-i);
fd=(exp(x+h)-exp(x))/h; //finding Derivetive
err=abs(exp(x)-fd); //error respect to exact value
disp(fd);
disp(err);
end
Output:
2.8588 // value of f(1)
2.7319
0.0136
2.7196
0.0014
2.7184
1.3592e-04
2.7183
1.3591e-05
2.7183
1.3585e-06
2.7183
1.3551e-07
2.7183
5.1012e-08
2.7183
2.2865e-07
2.7183
2.8932e-06
>>
Exercise 2:
Statement:
Given f(x) =ex , find f(1) using h=10-1, 10-2 ,,,, up to 10-10 . Use equation (5).
Find out the error in each case by comparing the calculated value with exact
value.
M File:
close all;
clear all;
clc;
x=1;
for i=1:10
h=10^(-i);
fd=(exp(x+h)-exp(x-h))/(2*h);// finding Derivetive
err=abs(exp(x)-fd);// error respect to exact value
disp(fd);
disp(err);
end
Output:
2.7228 // value of f(1)
2.7183
4.5305e-05
2.7183
4.5305e-07
2.7183
4.5306e-09
2.7183
5.8587e-11
2.7183
1.6346e-10
2.7183
5.8587e-11
2.7183
6.6028e-09
2.7183
6.6028e-09
2.7183
6.7274e-07
>>
Exercise 3:
Statement:
Given f(x) =sin (cos (1/x)) evaluate ( ) . Start with h =1 and reduce h to
1/10 of previous step in each step. If Dn+1 is the result in (n+1) th step and
Dn is the result in nth step then continue iteration until |Dn+1-Dn|>=|Dn-
Dn-1| or |Dn-Dn-1| <tolerance. Use equation (6) for finding D.
Function M File:
function [ y ] = fsc( x )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
y=sin(cos(1/x));
end
M File:
close all;
clear all;
clc;
x=(1/sqrt(2));
Dn=0;
Dnpi=0;
Dnmi=0;
h=1;
while abs(Dnpi-Dn)>=abs(Dn-Dnmi)
h=(h/10);
Dnpi=(-fsc(x+2*h)+8*fsc(x+h)-8*fsc(x-h)+fsc(x-2*h))/(12*h);
Dnmi=Dn;
Dn=Dnpi;
end
disp(Dnpi);
Output:
1
1.9608 // value of ( )
2