The inverse of the mathematical constant e can be approximated as follows:
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:5| Question number:20.5
All Answers
total answers (1)
Ch5Ex20.m
% Approximates 1/e as (1-1/n)^n, and determines
% the value of n required for accuracy to 4 dec. places
actual = 1 / exp(1);
diff = 1;
n = 0;
while diff >= 0.0001
n = n + 1;
approx = (1 - 1/n)^n;
diff = actual - approx;
end
fprintf('The built-in value of 1/e is %.4f\n',actual)
fprintf('The approximation is %.4f\n',approx)
fprintf('The value of n is %d\n',n)
need an explanation for this answer? contact us directly to get an explanation for this answer