Please help create MATLAB function file. Create a function that allows you to ap
ID: 3007456 • Letter: P
Question
Please help create MATLAB function file.
Create a function that allows you to approximate 1/e using the formula:
Your function is to take an input D that represents the number of digits your approximation must match the true value of 1/3. You are to use a while loop to find the approximation for 1/e correct to D decimal places.
NOTE: you are NOT calculating a sum or series.
Your function should return two things: the approximation value, and the size of n that was needed to get the approximation close to the desired number of decimal places.
Explanation / Answer
function [e,n] = approx(D)
e = 0;
n = 0;
while abs(e-exp(-1))>10^(-D-1)
n = n + 1;
e = (1-1/n)^n;
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.