08-12-2019 06:59 PM
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 ?
08-12-2019 09:31 PM
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).
08-13-2019 10:35 AM
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.
08-13-2019 10:59 AM
What is the error code?
08-13-2019 11:02 AM
Here is attachment is the error
08-13-2019 03:54 PM
@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...
08-13-2019 04:18 PM
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:
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.... 😉
08-13-2019 04:54 PM
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.
08-16-2019 11:35 AM - edited 08-17-2019 10:38 AM
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... 😉
08-16-2019 11:52 AM
@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". 😞