Absolute Error and Relative Error, Help please!!

15 Ansichten (letzte 30 Tage)
SB
SB am 2 Nov. 2012
Kommentiert: Torsten am 7 Mär. 2023
So I've found one approximation of ln(x) to be 2* the sum of 1/(2n+1)*((x-1)/(x+1))^(2n+1) and I need to find the absolute and relative errors at every new x and n value and then graph them in a 3d Surface Plot.
Here's what I have so far, I'm not sure where to go from here:
%
function [abserror,relerror]=error_comparison(x,n)
sum1=0;
for i=0:n
sum1=sum1+ 1./(2.*i+1).*(((x-1)./(x+1)).^(2*i+1)); % an approximation of ln(x)
end
sum=2*sum1;
abserror= log(x)-sum
relerror=abserror./log(x)
end
  9 Kommentare
Mahmoud
Mahmoud am 7 Mär. 2023
Writing the negative exponent to give the same result as the calculator. Example: 0.3000 * 10^-3 gives a result of 3 * 10^-4
But in MATLAB it gives a very different result. What is the problem here or how to write the equation correctly to give the same value as the calculator
Torsten
Torsten am 7 Mär. 2023
I don't know what you mean.
0.3000 * 10^-3
ans = 3.0000e-04
3 * 10^-4
ans = 3.0000e-04

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by