Q:

The inverse of the mathematical constant e can be approximated as follows:

0

The inverse of the mathematical constant e can be approximated as follows:

Write a script that will loop through values of n until the difference between the approximation and the actual value is less than 0.0001. The script should then print out the built-in value of e -1 and the approximation to 4 decimal places, and also print the value of n required for such accuracy.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now