math equation using function

2 visualizaciones (últimos 30 días)
Roger Nadal
Roger Nadal el 24 de Nov. de 2019
Comentada: Image Analyst el 26 de Nov. de 2019
function will recive input Value a and it caluclate its approximate value to e. e=1/e~~(1-1/n)^n. e value that the difference between the approximation and the actual value of e is smaller than err.function should return the corresponding value of n.

Respuestas (1)

Image Analyst
Image Analyst el 24 de Nov. de 2019
I don't know what that means. Let's say that a=8, and e=2.718281828. Do you simply want to return an ouput = (exp(1) - a)??? And do you just want to do a while loop, incrementing the value of n, until (1-1/n)^n is less than 1/e ???
n=0;
e1 = 1 / exp(1)
while difference > e1
difference = abs(e1 - (1-1/n)^n);
n = n + 1;
end
n = n - 1; % Undo last addition before the break.
  6 comentarios
Roger Nadal
Roger Nadal el 26 de Nov. de 2019
Not getting the proper answer in function it should receive input value of err and calculate approx value to e and difference of approx and actual e is small than err
Image Analyst
Image Analyst el 26 de Nov. de 2019
Well, only Walter here has the Mind Reading Toolbox, not me, so let's see what code you have so far, if you still want/need help. What modifications did you make to the snippet I gave you?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by