VB6 Least Squares *RESOLVED

kevinthenerd

Platinum Member
Jun 27, 2002
2,908
0
76
Does anyone know how I can code a non-linear least squares regression in VB or C/C++? (VB is preferred, but I know if I need to port it myself.) Everything I can find with matrix methods is only for the y=mx+b case, but I need to do a regression involving around 20-30 data points at a fifth-order regression.

This is for work. Thanks!
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
It should be almost identical to the y=mx+b case, only with a few more lines to allow adjustment of the additional parameters. Just maximize R^2 for parameter 1, then parameter 2, and so on until you've done it for all parameters and you're done.
 

kevinthenerd

Platinum Member
Jun 27, 2002
2,908
0
76
CycloWizard.... but after you've minimized the sum of squares for the first parameter, changing the second parameter may alter the optimal first parameter. Such is the case with nonlinear equations. I COULD write an interative code that samples it many times, using a trial and error method until it's finally done right, but that would take way too much computing time, and it still won't be perfect when it's finished anyway. This is for university research, and unnecessary computing error is simply unacceptable; the measurements are almost too much error to accept as it is. I know there's got to be a method out there that's not so computing intensive. Our current method involves exporting the data to Excel, but with all the overhead with that, it's slow, and it doesn't allow us to do enough data.
 

kevinthenerd

Platinum Member
Jun 27, 2002
2,908
0
76
I found what I needed on this one. I'm going to use some hefty linear algebra to write a non-iterative code, adapting the algorithms out of a book I found.