Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Call to CNiMath::PolynomialFit() throws exception

Hello everyone,
 
I am trying to use CNIMath::NonlinearFit() and CNIMath::PolynomialFit() functions in my program. To my surprise, the second does not want to behave 🙂 - it just throws an exception every time I call it. The first works fine though. I compiled the NI Measurement Studio example "Polynomial Fit". I ran it - it works! In my program though however I try I cannot make it functional. I made sure the interface data types and sizes are correct, the both projects link the same NIMathD.lib or NIMathSD.lib... What else could cause this function from throwing exceptions???
 
Thank you in advance,
 
Mike Faynberg
 
0 Kudos
Message 1 of 5
(4,112 Views)
Hi Mike!

What exception are you getting? You might want to check if you are passing the correct data types to the function. Were you able to create or assign vectors correctly?

The data types are:
static MathError PolynomialFit(
const CNiVector& x,
const CNiVector& y,
CNiReal64Vector& z,
CNiReal64Vector& coef,
double& mse,
int order = 1);

Please let me know where the error occurs and what the exception text reads.

Thank you
Nandini
NI
0 Kudos
Message 2 of 5
(4,100 Views)

Hi Nandini,

and Happy New Year!

Thank you for your answer. By this time I did not check what kind of exception does it throw. I double- and triple-checked the data types though. I tried both CNiVector (as it is specified in the library reference) and CNiReal64Vector types (as it is implemented in the NI example) for first 2 arguments, I tried to initialize the vector of coefficients... Nothing helped. Again, I brought down my code almost to the one shown in the example - and with no success either. Do you have any idea what exceptions can this routine throw in general? Maybe it would be helpful.

Thank you,

 

Mike Faynberg

0 Kudos
Message 3 of 5
(4,090 Views)

Hello again, Nandini,

I tried to check the error codes... If I disable exceptions throwing, the call to Polynomial Fit, which looks like:

MyFile.h

...

 double m_X[MAX_LENGTH];
 double m_Y[MAX_LENGTH];
 double m_MSE;

MyFile.cpp

 NI::CNiReal64Vector xv( length, m_X );
 NI::CNiReal64Vector yv( length, m_Y );
 NI::CNiReal64Vector zv( length, 0. );
 NI::CNiReal64Vector cv( Order + 1, coeff );


// NI::CNiException::SetExceptionMode( false );
 try
 {
  NI::MathError mr = NI::CNiMath::PolynomialFit( xv, yv, zv, cv,
                                                                             m_MSE, Order );
 }
 catch( NI::CNiMathException *e )
 {
  CString s = e->GetErrorMessage();
  TRACE( s + "\n" );
  e->ReportError();
 }

0 Kudos
Message 4 of 5
(4,085 Views)

Hello again, Nandini,

now I tried to figure which error codes (or what type of exception) is returned after my call to PolynomialFit. The call itself looks like:

MyFile.h

...

double m_X[MAX_LENGTH];
double m_Y[MAX_LENGTH];
double m_MSE;
...

MyFile.cpp
...
 double coeff[MAX_COEFF];
 ZeroMemory( coeff, MAX_COEFF * sizeof( double ) );
 coeff[0] = 24.5;                                      // Just the application specifics

 NI::CNiReal64Vector xv( length, m_X );
 NI::CNiReal64Vector yv( length, m_Y );
 NI::CNiReal64Vector zv( length, 0. );
 NI::CNiReal64Vector cv( Order + 1, coeff );
// NI::CNiException::SetExceptionMode( false );  // Switching exceptions-throwing mode
 try
 {
  NI::MathError mr = NI::CNiMath::PolynomialFit( xv, yv, zv, cv, m_MSE, Order );
 }
 catch( NI::CNiMathException *e )
 {
  CString s = e->GetErrorMessage();
  TRACE( s + "\n" );
  e->ReportError();
 }
...
 
What actually happens is:
- if the exceptions are enabled (by default), it throws "Unknown Math Exception", and the e->error value is different every time I run it. The values were, for example, 0x1ba5001, 0x191e001, 0x191e301;
- if the exceptions are disabled, the returned mr value is 204, which also does not look like any legitimate MathError code.
 
Any ideas? Or can you locate any sort of suspicious code?
 
Thank you in advance,
 
Mike Faynberg
 
 
 
0 Kudos
Message 5 of 5
(4,083 Views)