Effacer les filtres
Effacer les filtres

I need help with a taylor series approximation of ln(1+x)!

19 vues (au cours des 30 derniers jours)
Thomas MacDowell
Thomas MacDowell le 16 Juil 2018
Commenté : James Tursa le 16 Juil 2018
I am trying to do a taylor series approximation of ln(1+x) with a while loop and can't seem to get it right. this is what I have so far:
x = 3;
terms = 3;
n = 0;
lnx = 0;
arg = x + 1; % argument for ln function
lnx_plot = zeros(terms,1); % vector holding taylor series approximation values
real_lnx = zeros(terms,1); % vector of same length holding true ln evaluation
iter = zeros(terms,1);
% loop for taylor series approxiation
while n < terms
n = n + 1;
lnx = lnx + (-1)^(n-1)*x^n/n;
lnx_plot(n) = lnx; % puts current value at position 'n'
real_lnx(n) = log(arg); % puts true ln value at position 'n'
iter(n) = n;
end

Réponses (1)

James Tursa
James Tursa le 16 Juil 2018
This series only converges for abs(x) < 1. You are trying to use it with x = 3, which will diverge.
  5 commentaires
Thomas MacDowell
Thomas MacDowell le 16 Juil 2018
How will it not converge if ln(1+3) is not equal to inf?
James Tursa
James Tursa le 16 Juil 2018
The fact that a function value itself is finite does not guarantee that a Taylor Series expansion of the function will converge for all values. Just look at the trend of the first few terms of your series:
log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + x^5/5 - ...
Now plug in 3:
log(4) = 3 - 3^2/2 + 3^3/3 - 3^4/4 + 3^5/5 - ...
= 3 - 9/2 + 27/3 - 81/4 + 243/5 - ...
This has larger and larger positive & negative swings in the terms ... does it really look like that will converge? No, of course not. This series simply will not converge if abs(x) > 1 even though the function value itself at x=3 is finite. This behavior, where the interval of convergence is finite, is not uncommon in Taylor Series expansions.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by