필터 지우기
필터 지우기

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

조회 수: 20 (최근 30일)
Thomas MacDowell
Thomas MacDowell 2018년 7월 16일
댓글: James Tursa 2018년 7월 16일
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

답변 (1개)

James Tursa
James Tursa 2018년 7월 16일
This series only converges for abs(x) < 1. You are trying to use it with x = 3, which will diverge.
  댓글 수: 5
Thomas MacDowell
Thomas MacDowell 2018년 7월 16일
How will it not converge if ln(1+3) is not equal to inf?
James Tursa
James Tursa 2018년 7월 16일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Expansion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by