Re: FindFit and LeastSquares
- To: mathgroup at smc.vnet.net
- Subject: [mg132407] Re: FindFit and LeastSquares
- From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
- Date: Mon, 10 Mar 2014 04:38:53 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
Hello All,
I have an assignment to use Linear Least Squares to determine the orbital
parameters given the following observations as (x,y)
coordinates: (1.02,.39), (.95,.32), (.87,.27), (.77,.22), (.67,.18),
(.56,.15), (.44,.13), (.30,.12), (.16,.13), (.01,.15). I am asked to plot
the resulting orbit for the given data points.
Here is what I have been playing with:
a1 = {{1.02, .39}, {.95, .32}};
b1 = {{.87, .27}, {.77, .22}};
c1 = {{.67, .18}, {.56, .15}};
d1 = {{.44, .13}, {.3, .12}};
e1 = {{.16, .13}, {.01, .15}};
r = ListPlot[{a1, b1, c1, d1, e1}]
points = {{a1}, {b1}, {c1}, {d1}, {e1}};
data = {{1.02, .39}, {.95, .32}, {.87, .27}, {.77, .22}, {.67, .18}, {.56, \
.15}, {.44, .13}, {.3, .12}, {.16, .13}, {.01, .15}}
model = a*y^2 + b*x*y + c*x + d*y + e - x^2
FindFit[data, model, {a, b, c, d, e}, {x, y}]
l = LeastSquares[{a1, b1, c1, d1, e1},_]
I've been getting the error that FindFit is not a list or a rectangular
array, among others.
I was wondering you have any suggestions.
Thanks!
Alexandra Lipson
Hi, Alexandra,
The problem with FindFit is that the data represents pairs of numbers, such as data={{x1,y1}, {x2,y2}...}, rather than triples. In this case FindFit can determine y=y(x), but cannot find z=z(x,y). This is, however, what you expect to do, since your model is a function depending on two variables x and y. For the latter you should have the data consisting of triples, such as data={{x1,y1,z1}, {x2,y2,z2}...}.
If finding y=y(x) is OK with you, this is readily done. Check this:
data = {{1.02, .39}, {.95, .32}, {.87, .27}, {.77, .22}, {.67, .18}, {.56, .15}, {.44, .13}, {.3, .12}, {.16, .13}, {.01, .15}};
model = a + b*x + c*x^2 + d*x^3;
ff = FindFit[data, model, {a, b, c, d}, x]
{a -> 0.150252, b -> -0.145231, c -> 0.108877, d -> 0.252976}
Then you may also have a visual check of the fitting quality by evaluating this:
Show[{
ListPlot[data],
Plot[model /. ff, {x, 0, 1.1}, PlotStyle -> Red]
}]
Have fun, Alexei
Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG
Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44
e-mail: alexei.boulbitch at iee.lu