Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accuracy of parameters in `fit'.

680 views
Skip to first unread message

R I Bagnall

unread,
Feb 26, 1998, 3:00:00 AM2/26/98
to

Having fitted a (degree 12 !!) polynomial to some data, I then defined
a new gunction as the polynomial with the given coefficients. Plotting
this on the same plot doesn't give the same line.

I assume this is due to the parameters being displayed only to 6(?)
significant figures.

Is there a way to get more accurate values out of the reporting ?

TIA,

Rob.

PS. a CC by mail would be appreciated so I don't miss any replies.

Andreas Stahel

unread,
Feb 26, 1998, 3:00:00 AM2/26/98
to

Hello Rob

it is quite possible that the problems you are running into are due to
a illconditioned system of linear equatins to be soved. Are you sure
that fitting a polynomial of degree 12 is a clever thing to do?
I sugest that you first choose the TYPE of function that should fit to
your data. The let Gnuplot worry about the coefficients. Gnuplot can
not choose the type of function for you. Have a close look at the
application to find out what types of functions should be considered.

With best regards

Andreas

--
Andreas Stahel, Mathematics, Ingenieurschule, CH-2501 Biel, Switzerland
Andreas...@isbiel.ch Tel 41--32--32 16 258 FAX: 41--32--32 16 500

R I Bagnall

unread,
Feb 26, 1998, 3:00:00 AM2/26/98
to

> Hello Rob
>
> it is quite possible that the problems you are running into are due to
> a illconditioned system of linear equatins to be soved. Are you sure
> that fitting a polynomial of degree 12 is a clever thing to do?
> I sugest that you first choose the TYPE of function that should fit to
> your data. The let Gnuplot worry about the coefficients. Gnuplot can
> not choose the type of function for you. Have a close look at the
> application to find out what types of functions should be considered.

Point taken but I figure, seeing as gnuplot manages to fit the curve
itself, I should be able to do so with the same parameters. The
gnu-fitted curve IS pretty accurate.

Rob.


ib...@isdn-ib09.rz.uni-karlsruhe.de

unread,
Feb 27, 1998, 3:00:00 AM2/27/98
to

R I Bagnall <men...@mensgi6.leeds.ac.uk> wrote:
> I assume this is due to the parameters being displayed only to 6(?)
> significant figures.

yes - most likely

> Is there a way to get more accurate values out of the reporting ?

sort of... given you function f(x)=a+b*x+... do a print a,b,... after the
fit command.... this outputs the fitted values with more digits.

Hope this helps,

Andreas
--
Andreas Tack Real-time-Voice-Connect: +49 (0)721 608 2326
ib...@ttk1.ciw.uni-karlsruhe.de FAX: +49 (0)721 607102
http://ttk1.ciw.uni-karlsruhe.de/~ib09/

Hans-Bernhard Broeker

unread,
Feb 27, 1998, 3:00:00 AM2/27/98
to

In article <1998Feb26.1...@leeds.ac.uk> you wrote:
> Having fitted a (degree 12 !!) polynomial to some data, I then defined
> a new gunction as the polynomial with the given coefficients. Plotting
> this on the same plot doesn't give the same line.

The same line as *what*? I mean: if you already had it plotted during
the fit, why not just keep that definition, instead of writing out
a new one by hand?

The key to precision with fit parameters is to not use the output text
written during the 'fit' command, but instead use the gnuplot
variables that 'fit' sets automatically during its work. I.e. if you
fitted 'via a, b, c', then those variables will be available all the
way through that gnuplot session, and they can also be saved with
'save var', if you want to, or displayed via 'print a'.


OTOH, fitting a 12-th degree polynomial straight away, in the
canonical notation (a0 + a1*x + a2*x**2 + a3*x**3 ... ) is really a
bad idea (and the new fit docs clearly say so, IIRC), as it almost
invariably ends up giving enormously large parameter values, with the
single terms of the sums cancelling each other almost exactly. The
tiny residual term is thus almost entirely steered by the last few
digits of the parameters, i.e. it's essentially garbage produced by
roundoff error that makes up your fitted function.

You should fit orthogonal polynomials instead in such cases (or not
fit at all, but just use 'smooth acspline' or something).

--
Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Juergen von Hagen

unread,
Feb 27, 1998, 3:00:00 AM2/27/98
to

just some comments:

1) use what germans call the Horner scheme if you evaluate or
define polynomials. Do NOT use the canonical formulation.
So in clear
bad idea: a + b*x + c*x**2 + d*x**3
good idea (because faster and more accurate) ((d*x + c)*x + b)*x + a

2) fitting polinomials of high degree is not always good, you almost
definetly get strong oscillations at the ends of the fitting interval
A better idea is to use a function which is already close enough
to the target function. Also (as someone suggested) using a family
of funtions is a good idea (orthogonal polynoms, sine, cosine,
Tchebycheff polynomials....)

for the rest I agree with already said things (print, use variables...)

cheers
juergen

R I Bagnall wrote:
>
> Having fitted a (degree 12 !!) polynomial to some data, I then defined
> a new gunction as the polynomial with the given coefficients. Plotting
> this on the same plot doesn't give the same line.
>

> I assume this is due to the parameters being displayed only to 6(?)
> significant figures.
>

R I Bagnall

unread,
Feb 28, 1998, 3:00:00 AM2/28/98
to

>> Having fitted a (degree 12 !!) polynomial to some data, I then defined
>> a new gunction as the polynomial with the given coefficients. Plotting
>> this on the same plot doesn't give the same line.
>
> The same line as *what*? I mean: if you already had it plotted during
> the fit, why not just keep that definition, instead of writing out
> a new one by hand?

Sorry - I didn't explain enough of the background. The curve to be
fitted is to be used as a boundary condition in a FE package, which is
why the parameters were required. They were only re-input into gnuplot
as a check that they were correct.

> The key to precision with fit parameters is to not use the output text
> written during the 'fit' command, but instead use the gnuplot
> variables that 'fit' sets automatically during its work. I.e. if you
> fitted 'via a, b, c', then those variables will be available all the
> way through that gnuplot session, and they can also be saved with
> 'save var', if you want to, or displayed via 'print a'.

Thanks, to you and the others who suggested this. I think that will do
the trick (although I can't test it out till Monday).

> OTOH, fitting a 12-th degree polynomial straight away, in the
> canonical notation (a0 + a1*x + a2*x**2 + a3*x**3 ... ) is really a
> bad idea (and the new fit docs clearly say so, IIRC), as it almost
> invariably ends up giving enormously large parameter values, with the
> single terms of the sums cancelling each other almost exactly. The
> tiny residual term is thus almost entirely steered by the last few
> digits of the parameters, i.e. it's essentially garbage produced by
> roundoff error that makes up your fitted function.
>
> You should fit orthogonal polynomials instead in such cases (or not
> fit at all, but just use 'smooth acspline' or something).

I agree with what you say (and liked the suggestion by Juergen,
elsewhere in the thread, of reformatting the polynomial) although
alternatives wouldn't work in this case because of the way it has
to be input to the FE package.

Rob.


R I Bagnall

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Thanks everyone.

print <vars> and save <vars> worked a treat.

Rob.


0 new messages