Taylor series for ln(x)?
Show older comments
Hi, I am trying to use the formula for the Taylor series of ln(x) in order to solve for the value of 'e'. The answer is supposed to be one, but I am getting a huge number instead. I am having no luck in debugging this - perhaps my formula for the taylor series of ln(x) is wrong? Here is my code:
SumN=0; % initialize SumN
sign=-1; % variable that assigns a sign to a term
x= exp(1);
for N=1:1000
sign=-1*sign;
SumN=SumN + ((sign)^N*(x-1)^N)/(N);
end
Accepted Answer
More Answers (1)
Bijaya Nepal
on 4 Feb 2017
Edited: Walter Roberson
on 4 Feb 2017
0 votes
The value of ln (x) for any x in the range of 0 < x <= 2 can be estimated using the Taylor series as shown below. As more terms are added the results should get better.
lnx=(x-1)-(x-1)^2/2+(x-1)^3/3-(x-1)^4/4....
Write a script file that takes as user inputs the value of x (between 0 and 2) and the number of terms to use N. The program should then compute the estimate of ln(x) using the Taylor series. The program should output the estimate, the actual value, and the percent difference (in absolute terms
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!