Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
taylor polynomial evaluation

Subject: taylor polynomial evaluation

From: rose lans

Date: 15 Nov, 2008 01:17:02

Message: 1 of 4

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

Subject: taylor polynomial evaluation

From: Nasser Abbasi

Date: 15 Nov, 2008 02:22:22

Message: 2 of 4


"rose lans" <byrusel42@yahoo.com> wrote in message
news:gfl7ue$un$1@fred.mathworks.com...
> 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

Just saying 'does not work' does not help someone to help you.

what exactly does not work?

Nasser

Subject: taylor polynomial evaluation

From: Roger Stafford

Date: 15 Nov, 2008 03:02:02

Message: 3 of 4

"rose lans" <byrusel42@yahoo.com> wrote in message <gfl7ue$un$1@fred.mathworks.com>...
> Hi, I am trying to evaluate log(x) by using taylor polynomial with degree that will
> ..... SNIP .....
> Rose

  In the range from x = 1 to x = 1.5 the terms in your series reverse sign at each term and each one is smaller in magnitude than the previous one. Therefore the next unused term gives you an upper bound for the total error incurred. For x = 1.5 the 10-th term would be about 1/10^4, representing overall accuracy better than the fourth decimal place.

  On the other hand x = 0.5 yields a series of terms all of the same negative sign. This means the error made is the sum of a number of negative quantities beyond the end of the polynomial which combine their magnitudes, and that would explain the larger error that you are apparently experiencing.

  You will find that the Taylor expansion does not in general provide the best approximating polynomials for analytic functions for given intervals. There exist much better polynomials than that, but it requires some optimization work to find them. Short of that, you will have to use far more than nine polynomial terms to get good accuracy as far out from x = 1 as x = 0.5.

Roger Stafford

Subject: taylor polynomial evaluation

From: rose lans

Date: 15 Nov, 2008 21:59:03

Message: 4 of 4

Thank you for your reply,
i got it working OK now. The error is of 10^-16 order.


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gfle3a$30v$1@fred.mathworks.com>...
> "rose lans" <byrusel42@yahoo.com> wrote in message <gfl7ue$un$1@fred.mathworks.com>...
> > Hi, I am trying to evaluate log(x) by using taylor polynomial with degree that will
> > ..... SNIP .....
> > Rose
>
> In the range from x = 1 to x = 1.5 the terms in your series reverse sign at each term and each one is smaller in magnitude than the previous one. Therefore the next unused term gives you an upper bound for the total error incurred. For x = 1.5 the 10-th term would be about 1/10^4, representing overall accuracy better than the fourth decimal place.
>
> On the other hand x = 0.5 yields a series of terms all of the same negative sign. This means the error made is the sum of a number of negative quantities beyond the end of the polynomial which combine their magnitudes, and that would explain the larger error that you are apparently experiencing.
>
> You will find that the Taylor expansion does not in general provide the best approximating polynomials for analytic functions for given intervals. There exist much better polynomials than that, but it requires some optimization work to find them. Short of that, you will have to use far more than nine polynomial terms to get good accuracy as far out from x = 1 as x = 0.5.
>
> Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us