10-14-2023 03:25 AM
Hi All,
What is the best method to obtain the highest speed for the code in attached formula node?
Solved! Go to Solution.
10-14-2023 04:51 AM
We are graphical programmers, so we would probably not use a formula node at all. It is also confusing if you e.g. label the input to A as D1, etc. Why not name the controls as in the formula node?
I am not going to try to understand what you are trying to calculate, but if you point us to a website that describes the algorithm and purpose, we can probably point you in the right direction. Does the algorithm have a name?
What speed do you expect for large values of "u"? Complexity seems to be O(u²), so the execution time will probably go with the square of u.
10-14-2023 06:14 AM
Hi Altenbach,
The code is an example you can find here:
http://electronbunker.ca/eb/CalcMethods1b.html
On this page you can search for:
"Function Mcoil(ByVal n1,r1,x1,n2,r2,x2,x)"
It is related to a mutual L between two coaxial solenoids
10-14-2023 08:18 AM
I did some quick benchmarking. The formula node is 100 times slower than the native G code.
10-14-2023 08:28 AM
Hi,
Try implementing it with G code completely, here I managed to reduce the time by ~60% by pre-generating the x's and y's in 2D arrays prior to the formula node. Also, some repeated calculations can be factorized to do it only once instead of in each iteration. Finally, the G code compiler can automatically detect some portions of code that are "loop invariant" and take it out of the loop for performance optimization, which I guess you don't have with formula nodes:
Regards,
Raphaël.
10-14-2023 09:15 AM
I hope my colleague @altenbach will forgive me for "poaching" on his pleasure of turning scripts from Visual Basic code into LabVIEW. Thank you to the Original Poster for providing the reference. Rather than tackle the function for MCoil, I did the "inner function" it calls, "mut" (which I named "Mutual Inductance", following the principle that when you are dealing with LabVIEW, there is no sense in obscuring things by choosing single letters to represent variables).
You can see that I added the Error Line (always a good idea), that the "loop" is now a While Loop with a "Run-until-done" condition, all the temporary variables are initialized before being brought into the While Loop as Shift Registers (because they are modified within the loop), and the final result is calculated when the loop exits.
Bob Schor
10-14-2023 10:25 AM
@Bob_Schor wrote:
I hope my colleague @altenbach will forgive me for "poaching" on his pleasure of turning scripts from Visual Basic code into LabVIEW.
Thanks. I had no intention to analyze the text code and my earlier reply was made at 2:51am here (after I got up to check something). Still, I might have a look later this weekend to see if we can squeeze another factor of two out of it. 😄
For example, whenever I see something like x=sqrt((A + B)**2 + z**2);, I think "complex" to get the magnitude! Of course.
10-14-2023 03:40 PM
Great Bob Schor!
So it is the innner function mut and for the total function I have to merge something like the code raphschru has posted before.
I am not able to convert it in LabVIEW.
10-16-2023 06:04 AM
Hi,
Here a revision with small modifications.
I've added square roots you forgot and dividing by a at the end. I hope now it is correct.
Best regards,
Mal
10-16-2023 10:06 AM
@Mal123 wrote:Here a revision with small modifications.
Unfortunately, this is just a picture. Please attach your VI or at least a LabVIEW snippet.
@Mal123 wrote:
I hope now it is correct.
Hope is insufficient. If the algorithm is correct, it will give the correct result. Did you try for several inputs?