Re: FindFit and LeastSquares

• To: mathgroup at smc.vnet.net
• Subject: [mg132400] Re: FindFit and LeastSquares
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Mon, 10 Mar 2014 04:36:33 -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

```On 3/8/14 at 2:43 AM, lipson.alexandra at gmail.com (Alexandra Lipson)
wrote:

>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}}

Note, ListPlot[data] will give you the same plot of your data as
what you did with a lot less typing.

>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},_]

Look at the documentation for FindFit and LeastSquares. Neither
can deal with a model in implicit form as you have it.

You can construct an array for FindFit for each of your data
points with rows formated as:

{y^2,x*y,x,y,e,x^2,0}

where each part above is numeric computed from your {x,y} pairs.
With that array, you would call FindFit as follows:

FindFit[dataArray,,a*y2 + b*xy + c*x + d*y + e - x2,{a, b, c, d, e},{y2,xy,x,y,x2}]

A somewhat different approach would be to create an explicit
expression of the sum of squares and use NMinimize. That is:

x = data[[All, 1]]; y = data[[All, -1]];
error = Total[model^2] // Simplify;
sol = NMinimize[error, {a, b, c, d, e}]

```

• Prev by Date: Re: matrix manipulation
• Next by Date: Re: Do we need a When function?
• Previous by thread: FindFit and LeastSquares
• Next by thread: Re: FindFit and LeastSquares