[Date Index]
[Thread Index]
[Author Index]
Re: Function Fit to 3D data set
*To*: mathgroup at smc.vnet.net
*Subject*: [mg57792] Re: [mg57748] Function Fit to 3D data set
*From*: "David Annetts" <davidannetts at aapt.net.au>
*Date*: Wed, 8 Jun 2005 03:21:42 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Hi Adrienne
> I have been trying to do several analyses with an [x,y,z]
> data set, where z is dependent on x and y. First, I tried a
> 3D plot. However, the only way I was able to get Mathematica
> to plot my data was to assume a grid form for x and y, and
> use ListPlot3D. First question: can Mathematica make a 3D
> plot from stated x,y,z points?
Yes.
See documentation, particularly the functions in Graphics`Graphics3D.
> Secondly, I am trying to fit a function to the data. I have
> determined a function to which to fit parameters. However,
> Mathematica does not seem to want to accept y as a variable.
> Here is a simple suggestion of what I was trying. Note, my
> function is much more complicated. Please also ignore if the
> given does not work as stated, as I'm making it up.
>
> points = {{1, 1, 1}, {1, 2, 4}, {1, 4, 16}}
> f1 = FindFit[points, a + b*x^0 * y^1 + c*x^0 *y^2 +k*x^2 *y^0
> + l*x^2 * y^1, {a, b, c, k, l}, x, y]
>
> The error I receive is \!\(\*
> RowBox[{\(FindFit::"nonopt
> "\), \(\(:\)\(\ \)\), "\<\"Options expected (
> instead of \\!\\(y\\)) beyond
> position \\!\\(4\\) in \\!\\(\[LeftSkeleton] 1
> \[RightSkeleton]\\). An \ option must be a rule or a list of
> rules. \\!\\(\\*ButtonBox[\\\"Moreb
The error (and documentation) tells you that the last argument to FindFit
(in this form) must be a list. This list must have the same length as the
number of independent variables -- in your case, two.
As an example, load the package, then generate some data & plot them:-
Needs["Graphics`Graphics3D`"]
pts = Table[{x, y, .1 * (3 x + 2 y + x y)}, {x, -2, 2, .25}, {y, -2,
2, .25}];
ListSurfacePlot3D[pts, Axes -> {Automatic, Automatic, Automatic}];
Perturb the z-variable slightly & show the new data set as a series of
points:-
prt = Table[{x, y, .1 * (3 x + 2 y + x y) + Random[Real, {-.01,
.01}]}, {x, -2, 2, .25}, {y, -2, 2, .25}];
dplt = Show[Graphics3D[Point[#] & /@ Partition[Flatten[prt], 3]],
Axes -> {Automatic, Automatic, Automatic}];
See if we can find a function that fits our perturbed data set:-
eqn = FindFit[Partition[Flatten[prt], 3], a * (b x + c y + d x y),
{a, b, c, d}, {x, y}]
DisplayTogether[{
Plot3D[a * (b x + c y + d x y) /. eqn, {x, -2, 2}, {y, -2,
2}],
dplt}];
Visual inspection shows we did pretty well, but if you like looking at
numbers:-
a * (b x + c y + d x y) /. eqn // ExpandAll
.1 * (3 x + 2 y + x y) // ExpandAll
Compares our fitted equation with the unperturbed equation.
Alternatively, use NonlinearRegress (from "Statistics`NonlinearFit`") to get
a better idea of the fit.
Regards,
Dave.
Prev by Date:
**Re: Re: adding text to a plot erases plot?**
Next by Date:
**Re: CellPrint with text, table and graphics**
Previous by thread:
**Re: Function Fit to 3D data set**
Next by thread:
**Re: sorting complex number?**
| |