LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate 4D array from an equation

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

0 Kudos
Message 1 of 4
(3,097 Views)

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.

0 Kudos
Message 2 of 4
(3,082 Views)

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.

0 Kudos
Message 3 of 4
(3,063 Views)

@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.

0 Kudos
Message 4 of 4
(3,055 Views)