Coding taylor approximation of natural log
5 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I need to approximate ln(1.9) using a taylor series ln(1-x)=Sum(-(x^k)/k,k,1,inf). I have to code a script to figure out 1) how many terms I need, 2) the value from the series, and 3) the error. Here is what I have so far. I tried to run it, but it seems to be not ending.
x=0.9;
target_equation = log(1-x);
series_sum = 0;
difference = abs(target_equation - series_sum);
threshold = 1*10^-10;
count = 0;
while difference > threshold;
count=count+1;
series_sum=series_sum + ((x^count)/count);
difference = abs(target_equation - series_sum);
end
disp(series_sum);
I'm not sure what is wrong with my code. Any suggestion?
0 件のコメント
回答 (1 件)
RAMAKANT SHAKYA
2019 年 2 月 11 日
if you want to calculate log(1.9) and x=0.9 then you have apply taylor series log(1+x) see formula form google and change in to the code is
function series_sum=talor(x) %give x=0.9 as input
target_equation = log(1+x); % for calculating log(1.9)
series_sum = 0;
difference = abs(target_equation - series_sum);
threshold = 1*10^-10;
count = 0;
while difference > threshold;
count=count+1;
series_sum=series_sum + ((-1)^(count+1)*(x^count)/count); %as per formula of taylor series the even term cofficients are negative
difference = abs(target_equation - series_sum);
end
disp(series_sum);
参考
カテゴリ
Help Center および File Exchange で Mathematics and Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!