How can I label a solution as NaN in a MEX code?

I am using solvers of LAPACK libraries in a MATLAB MEX file for solving linear system of equations. For some of the cases, the system that I solve is singular. For example, the system is as follows for one of my cases:
A =
0.00000000 0.00000000 0.00000000
0.00000000 0.00000000 0.00000000
0.00000000 0.00000000 77.31867171
b:
-0.00000000 -0.00000000 -0.00000000
What would be the best approach to label this solution as NaN similar to MATLAB?

 채택된 답변

James Tursa
James Tursa 2014년 6월 24일
Use the API function mxGetNaN:
E.g., to put a NaN value into a double for returning to the MATLAB workspace:
double d = mxGetNaN( );

추가 답변 (1개)

José-Luis
José-Luis 2014년 6월 24일
if (some_condition)
some_value = 0.0/0.0; %This will produce a NaN
end

댓글 수: 4

AP
AP 2014년 6월 24일
I understand this. I wanted to label some_value as NaN.
José-Luis
José-Luis 2014년 6월 24일
편집: José-Luis 2014년 6월 24일
I am afraid I don't understand the problem. To test for singularity you could use:
rank(some_matrix)
And if you find out some_matrix is singular then set some_value as NaN.
AP
AP 2014년 6월 24일
편집: AP 2014년 6월 24일
Since I am writing a c++ code in MATLAB, I am trying to find a way to label the solution of a singular matrix to NaN in the c++ code. I am using LAPACK solvers to solve a linear system of equation. At some point the solution to this system fail and I want to be able to label this as NaN in my c++ code. Hope this clarifies my question.
José-Luis
José-Luis 2014년 6월 24일
편집: José-Luis 2014년 6월 24일
double myNaN = 0.0/0.0;
will produce a NaN in C++. Alternatively, you could set it to some other value
double flag = numeric_limits<double>::max();
that you then change into NaN in Matlab.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

질문:

AP
2014년 6월 24일

편집:

2014년 6월 24일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by