The approximation of the ln(1.9) using the Taylor series ln(1-x) = -sum of x^k/k, -1 less than or equal to x less than 1, I can't figure out how to code this properly

5 views (last 30 days)
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
k=count+1;
N=series_sum + ((x^k)/k);
error = (target_equation - N);
end
disp(k,N,error);

Answers (1)

Torsten
Torsten on 30 Jan 2024
Edited: Torsten on 30 Jan 2024
x = 0.9;
compare_value = log(1+x);
k = 0;
value = 0;
error = 1e-10;
while abs(value-compare_value) > error
k = k + 1;
value = value + (-1)^(k-1)*x^k/k;
end
k
k = 164
Now change the code to log(1-x).

Community Treasure Hunt

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

Start Hunting!