Taylor's theorem, find approximation for e^-x for x =1 with accuracy of 5 decimals.

7 visualizaciones (últimos 30 días)
Hi I am new to Matlab and need help with the following problem. Use Taylor's theorem to find approximation for e^-x for x =1 with accuracy of 5 decimals. I am not allowed to use the symbolic toolbox syms. I am allowed to calculate some of the parts by hand. I need to know the order n for when I have the accuracy of 5 decimals. I have been trying to create a loop that runs until I get the order n needed and will display that number. I'll use that answer to find the approximation ( which I have figured out the code for).
n = 0;
R = 1/factorial(n+1);
while R <= 0.000005
n = n+1;
R = 1/factorial(n+1);
end
disp(n)

Respuestas (2)

Naga
Naga el 29 de Dic. de 2024
You are using a mathematical method to approximate e^{-x} by adding terms in a series, and the more terms you add, the closer the approximation. Your goal is to find how many terms (n) are needed to ensure the approximation is accurate to 5 decimal places. To do this, you calculate the size of the next term in the series after the nth term; if it’s smaller than 0.00001, you stop. The loop starts with n=0, calculates the next term, and checks if it’s small enough. If not, n increases, and the process repeats until the next term is sufficiently small. The resulting n tells you how many terms are required for the desired accuracy. Check the updated code:
n = 0;
x = 1;
tolerance = 1e-5;
R = (x^(n+1)) / factorial(n+1);
while R >= tolerance
n = n + 1;
R = (x^(n+1)) / factorial(n+1);
end
disp(n)
  1 comentario
Torsten
Torsten el 29 de Dic. de 2024
Where do you save the approximation to exp(-x) ? Why do you think the approximation is accurate up to 5 decimals if R is smaller than the prescribed tolerance ?

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 29 de Dic. de 2024
Taylor's series involves accumulating the sum of terms. The sum of the n'th derivative of the function divided by n factorial times (x-a)^n .
The code proposed in the original question, and the code proposed by @Naga does not construct a sum.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by