Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

ISLAMIC UNIVERSITY OF TECHNOLOGY (IUT)

ORGANISATION OF ISLAMIC COOPERATION (OIC)


DEPARTMENT OF ELECTRICAL AND ELECTRONIC
ENGINEERING

NAME : Tasnia Nafs


STUDENT ID : 200021113
DEPARTMENT : ELECTRICAL AND ELECTRONIC ENGINEERING (EEE)
SECTION & GROUP : A1

DATE OF SUBMISSION : October 3, 2023

❖ Waveshapes:

COURSE NO. : EEE 4506


COURSE TITLE : Numerical Lab
EXPERIMENT NO : 1
NAME OF EXPERIMENT : Introduction to the sources of error in the numerical method
Maclaurin series for sin(𝑥)

clear all
close all
format long

x=input('Enter the Value of x')


x =
1.570796326794897

n=input('Enter the number of significant digits\n>')


n =
10

Scarborough Criterion
Es=(0.5*10^(2-n))
Es =
5.000000000000000e-09

Solution
true_value=sin(x)
true_value =
1

True Error:
it=100;% initial error set to 100%
t=[0,0,0];
a=0;
while(it>Es)
t(a+1,1)=a+1;
if a==0
t(a+1,2)=(((-1)^a)*x^(2*a+1))/factorial(2*a+1);
else
t(a+1,2)=t(a,2)+(((-1)^a)*x^(2*a+1))/factorial(2*a+1);
end
it=abs((true_value-t(a+1,2))*100/true_value);
t(a+1,3)=it;
a=a+1;
end

Approx Error:
ia=1;% initial error set to 1
a=[0,0,0];
a=0;
while(ia>(Es/100))
a(a+1,1)=a+1;
if a==0
a(a+1,2)=(((-1)^a)*x^(2*a+1))/factorial(2*a+1);
ia=1;
else
a(a+1,2)=a(a,2)+(((-1)^a)*x^(2*a+1))/factorial(2*a+1);
ia=abs((a(a+1,2)-a(a,2))/a(a+1,2));
end
a(a+1,3)=ia;
a=a+1;
end

Plotting
subplot(2,2,1)
plot(t(:,1),t(:,2),'Marker','*', 'MarkerEdgeColor','r')
xlabel('no. of iteration')
ylabel('sin(x)')
hold on
yline(true_value,'--g')
hold off
subplot(2,2,3)
plot(t(:,1),t(:,3),'Marker','*', 'MarkerEdgeColor','r')
xlabel('no. of iteration')
ylabel('True Error')
subplot(2,2,4)
plot(a(:,1),a(:,3),'Marker','*', 'MarkerEdgeColor','r')
xlabel('no. of iteration')
ylabel('Approximate error')
Table:
For true error
No=t(:,1);
sinx_value=t(:,2);
true_error_percentage=t(:,3);
table(No,sinx_value,true_error_percentage)
ans = 8×3 table

No sinx_value true_error_percentage

1 1 1.570796326794897 57.079632679489656

2 2 0.924832229288650 7.516777071134961

3 3 1.004524855534817 0.452485553481741

4 4 0.999843101399499 0.015689860050128

5 5 1.000003542584286 0.000354258428614

6 6 0.999999943741051 0.000005625894905

7 7 1.000000000662780 0.000000066278028

8 8 0.999999999993977 0.000000000602318
For approx error
No=a(:,1);
sinx_value=a(:,2);
approx_error=a(:,3);
table(No,sinx_value,approx_error)
ans = 9×3 table

No sinx_value approx_error

1 1 1.570796326794897 1

2 2 0.924832229288650 0.698466248308734

3 3 1.004524855534817 0.079333652927620

4 4 0.999843101399499 0.004682488811260

5 5 1.000003542584286 0.000160440616413

6 6 0.999999943741051 0.000003598843438

7 7 1.000000000662780 0.000000056921729

8 8 0.999999999993977 0.000000000668803

9 9 1.000000000000044 0.000000000006067

You might also like