[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matching Equation to Data
From: |
Juan Pablo Carbajal |
Subject: |
Re: Matching Equation to Data |
Date: |
Fri, 15 Mar 2013 12:25:59 +0100 |
On Fri, Mar 15, 2013 at 3:34 AM, Thomas D. Dean <address@hidden> wrote:
> I have a problem with matching an equation to data.
>
> I have JPL's de405 and created an oct file to interface to it. I can
> extract data from de405 and with scatter3(), the plot looks exactly like
> what you would expect. The orbit of Earth, or any other selected body. The
> source for the oct file is available if anyone is interested.
>
> I calculated the angle to the ecliptic and got 23.457 degrees, exactly what
> it should be.
>
> I have an array with 1000 data points, D=[et,x,y,z,dx,dy,dz]; I want to get
> an equation for the plane that contains the earth's orbit.
> a*x + b*y + c*z + d = 0
> so the vector x=[a, b, c, d] and,
> [D(:,2:4),ones(size(D,1),1)]*x'
> is near zero for all values in D(:,2:4).
>
> I tried looking at optim but, cannot get my head produce the correct
> arguments to the functions.
>
> How do I do this?
>
> Tom Dean
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
Hi Tom,
Almost all optimizers required code that looks more or less like this:
Assume "data" has your (x,y,z,1) points, one **column** per point.
Assume p is the vector of parameters to find, is given as a 1x4 row vector.
The following function gives the total square error:
function rhs = myfunc (p, data)
rhs = sum((p*data).^2);
endfunction
When you call the optimizer you create a handle to that function and
pass the data at construction time (you can also use global variables
or even persistent variables with a load command)
errfun = @(p) myfun(p,mydata)
You will have to provide a firts guess p0 and call the optimizer of
your choice like
p = optimizer (errfun, p0)
Now, since you are doing linear regression on the data I would
recommend to look at functions regress and regress_gp in the
statistics package.
Hope this helps.
JPi