relative error of machine epsilon

조회 수: 1 (최근 30일)
Frederick Melanson
Frederick Melanson 2021년 2월 7일
답변: Rohit Pappu 2021년 2월 11일
Hi!
I am trying to calculate the relative error of machine epsilon. I have the roundoff error but can seem to figure how to get the relative error... here is my function:
function eplison = ep(n)
eplison = double(1);
r = eplison/2;
while (n+eplison) ~= n
eplison = eplison/2;
r = eplison/2;
end
eplison= eplison*2;
end
thanks in advance

답변 (1개)

Rohit Pappu
Rohit Pappu 2021년 2월 11일
According to the formal definition, the approximation of Machine Epsilon is as follows
epsilon = 1.0;
while (1.0 + 0.5 * epsilon) 1.0:
epsilon = 0.5 * epsilon
Extending this to n, it can be rewritten as
epsilon = 1.0; % Default datatype is double
while(n + 0.5*epsilon ~= n)
epsilon = 0.5*epsilon;
end

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by