LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

summations from j=1 to n

I am having problems performing the following summation in attempting to program the following in LV:

Mi = SUM(j=1, j=!i to n) (ABS_VAL[Column3i - Column3j] / SQRT((Column1j - Column1i)^2 +(Column2j - Column2i)^2)

Can someone help?
0 Kudos
Message 1 of 5
(3,241 Views)
Your question is confusing, but it appears that you just need to make an array in a nested loop, with one loop being for i and one loop for j, and then sum all of the values. You could also calculate the value for each of the iterations and add it to the previous iteration (passed via a shift register), but be careful with this using the nested loop so that you don't add things twice.

Hope that helps.

John
0 Kudos
Message 2 of 5
(3,241 Views)
Thnaks for your effort John. Sorry about the confusing question , but it is a bit hard to explain so I thought that by showing the formula I am trying to program, this may help.
My problem is is that I want to calculate the difference between values in a single column (i.e. xi - xj) and then sum them so that (SUM j=1, (j does not equal i) to n). Is this any clearer? And if your answer is the same as above, could you please expand on it a bit? I am fairly new at LV. Thanks very much in advance.
0 Kudos
Message 3 of 5
(3,241 Views)
Thnaks for your effort John. Sorry about the confusing question , but it is a bit hard to explain so I thought that by showing the formula I am trying to program, this may help.
My problem is is that I want to calculate the difference between values in a single column (i.e. xi - xj) and then sum them so that (SUM j=1 to n). Is this any clearer? And if your answer is the same as above, could you please expand on it a bit? I am fairly new at LV. Thanks very much in advance.
0 Kudos
Message 4 of 5
(3,241 Views)
So you have a single column of data (which is a 1D array) and you want to sum xi-xj for all j does not equal i, where i is a constant for purposes of this summation. What you need to do is bring the array into a for loop and also the value of xi. Inside the loop you add the value of xi-xj (where j is derived from the iteration value of the loop) as another element in the array if i=j is false. Otherwise you do nothing and go to the next iteration. I have included an example where I build an array inside the loop and then sum outside of the loop. You could just as easily initialize the shift register with a zero value and add the value each time, which is probably more efficient now that I think about it.

I would like to note that the
iteration starts at zero, which will correspond to the first element in an array, and the value of n is the number of times the array will execute, so that you are really going from j=0 to n-1. This shouldn't be a problem.

I hope this is of more help.

John
0 Kudos
Message 5 of 5
(3,241 Views)