04-11-2012 02:41 AM
Hi
I'm trying to create a fairly large 4 dimensional array whose elements are given by an equation based on their indices.
I have done this using a mathscript node inside of 4 nestled for-loops, getting the index from the iteration number. It seems to work, but is EXTREMELY slow. This is probably because the equation for each element is quite complicated and it has to be computed from the start every single time.
Might there be a more efficient way to create such an array?
Thanks,
Steve
04-11-2012 08:07 AM
I have not looked at every single line of your MathScript node, but a cursory look indicates you can probably eliminate at least one loop by doing array operations in LabVIEW. The math functions are polymorphic, so they can operate on an element or an array. With some line you basically need to create a ramp that corresponds to the loop iterations. For example, the line "i = x-width2/+.49" can be done by creating an X array (use the Ramp VI to get your array of x values based on the number of iterations, which you can determine using the Array Size function), and then using just the math functions.
04-11-2012 11:58 PM
The ramp VI does seem like a good suggestion, since each element in my final array is defined solely by its indices.
The problem is that I want to do element-wise calculations like "Mz1=atan(b*c/a*sqrt(a^2+b^2+c^2))".
How would I do that if (say) c was a vector, and I want each element of Mz to be defined by the corresponding element of c?
Sorry if this is a dumb question, I haven't done a lot of mathematical programming.
04-12-2012 07:42 AM
@moi maker wrote:
The problem is that I want to do element-wise calculations like "Mz1=atan(b*c/a*sqrt(a^2+b^2+c^2))".
How would I do that if (say) c was a vector, and I want each element of Mz to be defined by the corresponding element of c?
In the last line you are adding the individual Mz* values and then scaling. It doesn't matter if you do this at an element level or at an array level. Thus, you could calculate an array of Mz1 values based on all the possible x2 values, and the equations should still work.