Why am I not getting different values for the absolute value percent error?
Show older comments
The question that is in the textbook that I have states:
The infinite series converges on a value of f (n) = π4/90 as n approaches infinity. Write a program in single precision to calculate f (n) for n = 10,000 by computing the sum from i = 1 to 10,000. Then repeat the calculation but in reverse order—that is, from i = 10,000 to 1 using increments of −1. In each case, compute the true percent relative error. Explain the results. The bottom image is the series.

My code that I have gives the exact same error values for forwards and backwards. :( What is wrong with my code?
clear
clc
while (1)
tru = ((pi^4)/90);
p = input('Enter number of iterations (n): ' );
for i = 1:p
y(i+1) = 1/(i^4);
end
z = sum (y);
disp ('The approximation value is ');
disp (z);
absval = ((tru - z)/tru);
disp ('The absolute value percent error from 1 to 10000 is ');
disp (absval);
for i = p:-1:1
y2(i+1) = 1/(i^4);
end
z2 = sum(y2);
disp ('The approximation value backwards is ');
disp (z2)
absval2 = ((tru - z2)/tru);
disp ('The absolute value percent error from 10000 to 1 is ');
disp (absval2);
m = input('Do you want to continue, Y/N [Y]:','s');
if m == 'N';
break
elseif m == 'n';
break
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!