Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: taylor polynomial evaluation
Date: Sat, 15 Nov 2008 01:17:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <gfl7ue$un$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1226711822 983 172.30.248.35 (15 Nov 2008 01:17:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 15 Nov 2008 01:17:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1581815
Xref: news.mathworks.com comp.soft-sys.matlab:500935

Hi, I am trying to evaluate log(x) by using  taylor polynomial with degree that will approximate it as accurately as possible, on interval 0.5-1.5. For some reason, my code does not work right from 1 to 1.5, although the results from 0.5 to 1.5 are OK. Can anyone see what the problem is? (sorry, I am new to MATLAB, it's probably really simple)
function taylor1(a,b)
% a=0.5, b=1.5
for x=a:0.01:b
t=(x-1)-(1/2)*(x-1)^2+(1/3)*(x-1)^3-(1/4)*(x-1)^4+(1/5)*(x-1)^5-...
    (1/6)*(x-1)^6+(1/7)*(x-1)^7-(1/8)*(x-1)^8+(1/9)*(x-1)^9;

fprintf('t=%2.10g \n',t)
fprintf('x=%1.2g \n',x)
end

Also, does anyone know how to display the results in a nice readable form?
Thank you all,
Rose