Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How do is the calculation done? MatLab gives two different values
Date: Sun, 21 Feb 2010 09:19:03 -0600
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <hlrivk$kc1$1@news.eternal-september.org>
References: <hlre9m$7eh$1@fred.mathworks.com> <hlrfjp$mj1$1@news.eternal-september.org> <hlrgm1$qrm$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 21 Feb 2010 15:20:21 +0000 (UTC)
Injection-Info: feeder.eternal-september.org; posting-host="q9VEJX2YJd42CcwSyhVZMg";
	logging-data="20865"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Wq+pz3pcbIIIAg8/vZZ5T"
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
In-Reply-To: <HIDDEN>
Cancel-Lock: sha1:uDUOPmeY++la/1ifBdgy6isswlI=
Xref: news.mathworks.com comp.soft-sys.matlab:610174

Saga wrote:
...

>> > > when I type on matlab: polyval (a,19.13)
>> > > the answer is: 9.4393
>> > x being the value of 19.13,
>> > But when I compute the value on matlab manually:
>> > > 0.0015*19.13^3 - 0.1084*19.13^2   + 3.8509*19.13  - 35.1232
>> > > The value it returns is 9.3759
>> > > How is this possible when, is there a mistake I'm making while > 
>> calculating the formula manually?
>> > > Please advice.
>>
>>  >> a =[ 0.0015   -0.1084    3.8509  -35.1232]
>> a =
>>      0.0015   -0.1084    3.8509  -35.1232
>>  >> polyval (a,19.13)
>> ans =
>>      9.3759
>>  >>
>>
>> Now what do you think is the problem/answer/cause...?
>>
>> -- 
> 
> When I do:
> 
>>> a = polyfit(x,y,3)
> 
> a =
> 
>    0.0015   -0.1084    3.8509  -35.1232
> 
>>> polyval(a,19.13)
> 
> ans =
> 
>    9.4393
> 

You said that already...I asked you to really think about why that might 
be...

> It is a different value when you assign values of "a" manually compared 
> to using the polyfit.

Yes, but are those the _SAME_ values of a to full double precision???

> So then I try to work out how the polyval method is calculating the 
> equation of a
> 
> i.e.
>>> 0.0015*19.13^3 - 0.1084*19.13^2   + 3.8509*19.13  - 35.1232
> 
> ans =
> 
>    9.3759
> 
> Why are there different values?
> Is the formula which I typed manually incorrect?

Consider the numerics more closely

hint

try

polyfit(x,y,3) - a

where 'a' is the manually entered coefficient vector above.

--