Path: news.mathworks.com!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 17:34:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 92
Message-ID: <hlrqqc$j1e$1@fred.mathworks.com>
References: <hlre9m$7eh$1@fred.mathworks.com> <hlrfjp$mj1$1@news.eternal-september.org> <hlrgm1$qrm$1@fred.mathworks.com> <hlri15$flt$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1266773644 19502 172.30.248.38 (21 Feb 2010 17:34:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 21 Feb 2010 17:34:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2231206
Xref: news.mathworks.com comp.soft-sys.matlab:610200

"Sadik " <sadik.hava@gmail.com> wrote in message <hlri15$flt$1@fred.mathworks.com>...
> Saga,
> 
> Please type 
> 
> format long
> 
> and then, redo your
> 
> a = polyfit
> 
> stuff. You will see that your coefficients are not as sharp as 0.0015. It could for example be 0.0015234223 or something like that. This is why you are getting a different answer.
> 
> By default, matlab rounds the numbers to display them with 4 decimal places.
> 
> Best.
> 
> 
> 
> 
> "Saga " <a5stargamescompany@googlemail.com> wrote in message <hlrgm1$qrm$1@fred.mathworks.com>...
> > dpb <none@non.net> wrote in message <hlrfjp$mj1$1@news.eternal-september.org>...
> > > Saga wrote:
> > > > Hi,
> > > > 
> > > > I've got matlab to generate a equation of polynomial.
> > > > 
> > > > a = 0.0015   -0.1084    3.8509  -35.1232
> > > > 
> > > > which is of order 3 i.e.
> > > > 
> > > > 0.0015*x^3 - 0.1084*x^2   + 3.8509*x  - 35.1232
> > > > 
> > > > 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
> > 
> > It is a different value when you assign values of "a" manually compared to using the polyfit.
> > 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?
> > 
> > Thanks

Thank You very much...

It works.