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

10 ビュー (過去 30 日間)
Tove Storsnes
Tove Storsnes 2021 年 10 月 5 日
回答済み: Walter Roberson 2024 年 12 月 29 日 20:47
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)

回答 (2 件)

Naga
Naga 2024 年 12 月 29 日 13:24
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 件のコメント
Torsten
Torsten 2024 年 12 月 29 日 18:15
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 ?

サインインしてコメントする。


Walter Roberson
Walter Roberson 2024 年 12 月 29 日 20:47
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.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by