Professional Documents
Culture Documents
Xavier University - Ateneo de Cagayan University College of Engineering Electronics Engineering Department
Xavier University - Ateneo de Cagayan University College of Engineering Electronics Engineering Department
Xavier University - Ateneo de Cagayan University College of Engineering Electronics Engineering Department
College of Engineering
Electronics Engineering Department
MACHINE PROBLEM #1
APPROXIMATE RELATIVE ERROR
Submitted by:
Instructor:
ROMMEL PEDRAZA
BSEcE 5
(05):____
(20):____
Observation, Analysis
(30):____
Conclusion
(25):____
Tardiness
(10):____
Presentation, Neatness
(20):____
Total
(100):____
INTRODUCTION
The approximation error in some data is the discrepancy between an exact value and some
approximation to it. An approximation error can occur because
The measurement of the data is not precise due to the instruments.
approximations are used instead of the real data .
In the mathematical field of numerical analysis, the numerical stability of an algorithm in numerical
analysis indicates how the error is propagated by the algorithm.
(Eq.1)
(Eq.2)
(Eq.3)
(Eq.4)
OBJECTIVES
1. Compute Cos ( PI/4) using matlab and using Mclaurin series expansion
2. With a given stopping criterion (es) of < 0001% determine the iterations, true error and
approximate error
MATLAB CODES
clc
clear all;
format short;
sum=0;
n=0; %number of terms
ea=100; %approx error
x = input('x (angle in radians):'); %angle in
radians
er = input('es (approximate % relative error):');
cosT = cos(x);
disp(sprintf('True value = cos(x) = %f \n',cosT));
while (abs(ea)>er)
oldsum =sum;
sum = sum + ((-1)^n) * (x^(2*n)) /
factorial(2*n);
n=n+1;
disp(sprintf('# of terms : %d',n));
disp(sprintf('cos x = %f ',sum));
et = abs((cosT - sum) / cosT)*100;
disp(sprintf('True Error = %f',et));
ea = abs((sum - oldsum) / sum)*100;
disp(sprintf('Approx. Error = %f \n',ea));
end;
OUTPUT
x (angle in radians):pi/4
es (approximate % relative error):0.0001
True value = cos(x) = 0.707107
# of terms : 1
cos x = 1.000000
True Error = 41.421356
Approx. Error = 100.000000
# of terms : 2
cos x = 0.691575
True Error = 2.196545
Approx. Error = 44.597506
# of terms : 3
cos x = 0.707429
True Error = 0.045598