From: mahan on
I have a set of 3d data points (x, y, z) that I want to fit to an ellipsoid, with the implicit function
c1*(z-z0)^2 - c2*xz + c1*x^2 + c3*y^2 - c4 = 0.

The unkown parameters are c1, c2, c3, c4, z0. This linear system has been solved.

My problem is that I want to use the x and y values to calculate new z-values. It's not possible to rearrange this equation to obtain z as an explicit function of x and y, that is f(x,y). Are there any ways to create a function handle like

fh= @(x,y) ....;

afterall? Because I would like to calculate the difference between the new z-values (f(x,y)) and the z-values from the original data.

Appreciate the help!
From: Walter Roberson on
mahan wrote:
> I have a set of 3d data points (x, y, z) that I want to fit to an
> ellipsoid, with the implicit function
> c1*(z-z0)^2 - c2*xz + c1*x^2 + c3*y^2 - c4 = 0.
>
> The unkown parameters are c1, c2, c3, c4, z0. This linear system has
> been solved.
>
> My problem is that I want to use the x and y values to calculate new
> z-values. It's not possible to rearrange this equation to obtain z as an
> explicit function of x and y, that is f(x,y).

Why not? It's just a quadratic. (-b +/- sqrt(4*a*c))/2a standard form

(c2*x + 2*c1*z0 + (c2^2*x^2 + 4*c2*x*c1*z0 - 4*c1^2*x^2 - 4*c1*c3*y^2 +
4*c1*c4)^(1/2)) / (2*c1)

(c2*x + 2*c1*z0 - (c2^2*x^2 + 4*c2*x*c1*z0 - 4*c1^2*x^2 - 4*c1*c3*y^2 +
4*c1*c4)^(1/2)) / (2*c1)

So it produces 2 values: fit to the closest one unless you want to do
some continuity analysis to fit the upper and lower z poles better where
the two values are nearly equal and due to noise the closest predicted
value might happen to be on the "other" branch.
From: mahan on
Walter Roberson <roberson(a)hushmail.com> wrote in message <0xW6o.19359$RZ1.7129(a)newsfe24.iad>...
> mahan wrote:
> > I have a set of 3d data points (x, y, z) that I want to fit to an
> > ellipsoid, with the implicit function
> > c1*(z-z0)^2 - c2*xz + c1*x^2 + c3*y^2 - c4 = 0.
> >
> > The unkown parameters are c1, c2, c3, c4, z0. This linear system has
> > been solved.
> >
> > My problem is that I want to use the x and y values to calculate new
> > z-values. It's not possible to rearrange this equation to obtain z as an
> > explicit function of x and y, that is f(x,y).
>
> Why not? It's just a quadratic. (-b +/- sqrt(4*a*c))/2a standard form
>
> (c2*x + 2*c1*z0 + (c2^2*x^2 + 4*c2*x*c1*z0 - 4*c1^2*x^2 - 4*c1*c3*y^2 +
> 4*c1*c4)^(1/2)) / (2*c1)
>
> (c2*x + 2*c1*z0 - (c2^2*x^2 + 4*c2*x*c1*z0 - 4*c1^2*x^2 - 4*c1*c3*y^2 +
> 4*c1*c4)^(1/2)) / (2*c1)
>
> So it produces 2 values: fit to the closest one unless you want to do
> some continuity analysis to fit the upper and lower z poles better where
> the two values are nearly equal and due to noise the closest predicted
> value might happen to be on the "other" branch.


Thanks for the tip!