A

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

a = linspace(-pi/4, pi/4, 1000);

b = pi*a;

c = zeros(1, length(a));

for i = 1:length(a);

c(i) = b(i) + randn(1);

end

d = zeros(1, length(a));

for w = 1:length(a);

d(w) = abs(c(w) - b(w));

e(w) = abs((c(w) - b(w))./c(w));

end

plot(a,b); hold on;

plot(a,c); legend('correct', 'computer')

title('accuracy of a computing machine')

grid on

MAE = max(d)

fprintf('maximum absolute error')

disp(MAE)

MRE = max(e)

fprintf('maximum relative error')

disp(MRE)

p = linspace (-pi/2, pi/2, 1000);

q = p*pi.^2;

r = zeros(1, length(p));

for i = 1:length(p);
s(i) = abs(r(i)- q(i));

clc

end

p = linspace (-pi/2, pi/2, 1000);

q = p*pi.^2;

r = zeros(1, length(p));

for i = 1:length(p);

r(i) = q(i) + randn(1);

end

s = zeros(1, length(p));

for j = 1: length(p);

s(j) = abs(r(j)-q(j));

t(j) = abs((r(j) - q(j))./ r(j));

end

fprintf('Absolute error')

disp(s(j))

fprintf('Relative error')

disp(t(j))

You might also like