LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mathscipt node issue

I used function [n,d]=rat(dbl) in mathscript node and I experienced issue with Labview on some of the fraction. 0.625 for example cause issue where 0.6251 or other fractions are OK. When running matlab, all numbers are OK. Attachment is example code. Has anyone experienced the same issue and have solution ?

 

 

  

0 Kudos
Message 1 of 15
(3,168 Views)

I'm not sure I understand your question.  What do you mean by "numbers are ok"?  

 

I can't imagine ALL numbers are ok.  If so, just replace your code with a true.

 

Also, keep in mind the mathscript node is not Matlab.  It's a node that uses code of a similar style.  If you want to use Matlab code, you'll want to use the Matlab node (assuming you have the Matlab runtime also installed on that machine).

Message 2 of 15
(3,130 Views)

This is to convert from decimal number to fractional. With labview, some number cause error; however, when using matlab or even excel spreadsheet, it works OK. 

0 Kudos
Message 3 of 15
(3,020 Views)

What is the error code?

0 Kudos
Message 4 of 15
(3,015 Views)

Here is attachment is the error

0 Kudos
Message 5 of 15
(3,011 Views)

@natasftw wrote:

 

 

Also, keep in mind the mathscript node is not Matlab.  It's a node that uses code of a similar style.  If you want to use Matlab code, you'll want to use the Matlab node (assuming you have the Matlab runtime also installed on that machine).


 

https://zone.ni.com/reference/en-XX/help/371361R-01/gmath/mathscript_node/

https://zone.ni.com/reference/en-XX/help/371361R-01/gmath/matlab_script_node/

 

learned something new ... I only knew about the Mathscript node, which I believe was able to load a .m file (a file type which is quite related to matlab) ...

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000004BDYSA2&l=de-DE

https://www.mathworks.com/help/matlab/learn_matlab/scripts.html

https://www.tutorialspoint.com/matlab/matlab_m_files.htm

 

but it needed Matlab to be installed on the same machine, where the LabView IDE was installed.

Altough, I'm not sure, if the mathscript node was capable to load all those various matlab libraries...

 

0 Kudos
Message 6 of 15
(2,994 Views)

Obviously, there is a bug in the rat function of matlab and I think it has to do with termination conditions. There is a second paramtere to specify a desired tolerance and any input seems to fail if the tolerance is too small:

 

matrat.png

0.625 works fine with a tolerance of 1e-1, while 0.6251 fails with a tolerance of 1e-8).

 

NI just needs to fix it. Probably a small miswire somewhere.... 😉

 

Message 7 of 15
(2,987 Views)

I used this to calculate the M/N ratio for the digital PLL feedback divider and I got errors often. I submitted ticket to NI for over a year and they have not been able to resolve it yet. My temporary fix was to at 1E-9 to the decimal number and it worked well; however, this produces error of 1E-9 to the math.

 

0 Kudos
Message 8 of 15
(2,982 Views)

Yes, the code is obviously faulty and fails especially for most simple fractions. I have reported it in the monthly bug thread and elsewhere, so hopefully we can get a CAR# soon. This should get patched!

 

If you scavenge the NI folder, you can actually find the VI corresponding to the Mathscript rat function. From a casual inspection, the main problem is that it terminates with an error for simple fraction inputs, even if the result is otherwise OK. Code can easily be fixed. Maybe you want to copy the VI out, correct it, and use the fixed version as a plain VI to do the calculation if you really need that result. (Don't edit anything in vi.lib, of course!)

 

You could even just write your own rat function subVI from scratch. Algorithms are out there... 😉

0 Kudos
Message 9 of 15
(2,935 Views)

@dungnnguyen wrote:

I submitted ticket to NI for over a year and they have not been able to resolve it yet.


Did you get a CAR# for the case?

 


@dungnnguyen wrote:

 My temporary fix was to at 1E-9 to the decimal number and it worked well; however, this produces error of 1E-9 to the math.


I guess it got de-prioritized because you found a "workaround". 😞

0 Kudos
Message 10 of 15
(2,924 Views)