10-12-2010 04:00 PM
Hi,
I need to use Levenberg-Marquardt algorithm in C#. There is VI with Levenberg-Marquardt algorithm in LabVIEW and there is not in Measurement Studio (2008). I decided to create dll in LabVIEW and call it in C#.
So I created LevenbergMarquartFit.vi and Function.vi. I also created Test.vi. In Test.vi LevenbergMarquartFit.vi are called as vi and as function. It works correctly as vi and it doesn't work correctly as function call.
I also try to call fuction from C#.
Header file LevenbergMarquartFit.h is
========
void __cdecl LevenbergMarquartFit(double Tolerance, int32_t MaxIterations,
double Y[], double X[], double OffsetIn, double B2In, double A2In,
double B1In, double A1In, int32_t *Iterations, double Fit[], double *Offset,
double *B2, double *A2, double *B1, double *A1, double *Residue,
char Error[], int32_t len, int32_t len2, int32_t len3, int32_t len4);
========
I call from C#
=========
double [] AdYTimeBase = new double[ 64];
...
double dTolerance = 0.00000001;
int iMaxIterations = 1000;
//double[] AdY;
double dOffsetIn = Double.Parse(textBox_Offset.Text) * AdYTimeBase[ iTimeBasePoints - 1];
double dB2In = Double.Parse(textBox_B2.Text);
double dA2In = Double.Parse(textBox_A2.Text) * AdYTimeBase[iTimeBasePoints - 1];
double dB1In = Double.Parse(textBox_B1.Text);
double dA1In = Double.Parse(textBox_A1.Text) * AdYTimeBase[0];
int iIterations = 0;
double[] AdFit = new double[AdYTimeBase.Length];
double dOffset = 0;
double dB2 = 0;
double dA2 = 0;
double dB1 = 0;
double dA1 = 0;
double dResidue = 0;
string StrError = "";
int iLen = 0;
int iLen2 = 0;
int iLen3 = 0;
int iLen4 = 0;
LevenbergMarquartFit(dTolerance, iMaxIterations, AdYTimeBase, AdX,
dOffsetIn, dB2In, dA2In, dB1In, dA1In,
out iIterations, out AdFit,
out dOffset, out dB2, out dA2, out dB1, out dA1,
out dResidue, out StrError, out iLen, out iLen2, out iLen3, out iLen4);
==========
but program hangs at LevenbergMarquartFit() function.
Any help?
Thanks, Andrey.
Solved! Go to Solution.
10-12-2010 04:12 PM
Hey Andrey -
You didn't mention what edition of Measurement Studio you're using, but if you've got the Enterprise edition, you should be able to use the CurveFit.NonLinearFit method. It internally uses the Levenberg-Marquardt algorithm.
NickB
National Instruments
10-12-2010 05:19 PM
it works.
thanks!!!