LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to take sum from middle iteration to last iteration?

Solved!
Go to solution

Hello! pls, can any one assist, i have six variables and want to take the sum of each variable separately from middle iteration to last iteration( that is from iteration 6 to iteration 12). Attached are the vi and input data file.

Download All
0 Kudos
Message 1 of 19
(3,465 Views)

Hello Abul,

 

Is there any reason you are using Control Design and Simulation? It seems like you could do the iteration and sum from our Mathematics palette. Also, I believe you will want to use While loop for your iteration count. Using these tools will be easier than trying to get this done with your current VI. 

 

Mychal F

Applications Engineer
National Instruments
0 Kudos
Message 2 of 19
(3,431 Views)
Solution
Accepted by topic author Abul

I'm not going to mess with your control design thingy... but here is the simple and direct way to take the sum of the middle to last interation.  I'm using random numbers here, but you can fill in your own values once you get your formula straigthend out.

 

Basically, it works like this:  feed the values into an indexing tunnel.  That will make each set of values into an array with length N where N is number of iterations. 

 

Find the size of the array and divide by 2.  Remember that arrays start at index zero, so 12 iterations will give you 0,1,2,3,4,5,6,7,8,9,10,11.

 

You want the second half, so that's 6,7,8,9,10 and 11.  Use array subset to pick out 6 elements starting at element 6.... then take the array sum.sum array.jpg

Message 3 of 19
(3,426 Views)

Is because of the use of integrator.

0 Kudos
Message 4 of 19
(3,414 Views)

Kudos

0 Kudos
Message 5 of 19
(3,407 Views)

I did as u directed but still when i run nothing comes out as the sum of each variable from middle iteration to the last, or is it because i see the simulation loop runs faster than the while loop. How do i synchronize the two? i.e the simulation loop and while loop to run at the same rate. Attached are the vi and input data file complete. Thanks

Download All
0 Kudos
Message 6 of 19
(3,384 Views)

Because the simulation loop is inside the While loop, they cannot be synchronized.

 

What happens is this:

 

  1. The while loop starts
  2. Everything inside the while loop runs (including the simulation loop)
  3. The simulation loop runs until it is complete (this might be once or many times)
  4. The while loop does not start again until the simulation (and everything else inside of it) is done.

Each time this happens, one value is placed in the output of the while loop.

 

The first thing you need to do is delete the random number generators that I put in.  These were just there for demonstration purposes.  You should wire the output of your X1, X2, X3, etc to the outputs of the while loop (the tunnels at the right edge.)  If not, there's no way for your data to get out of the loop.

 

Also, I'm really worried about the simulation loop.  In fifteen years, I have never needed or used this feature.  I've done quite a lot of complex math and I've always built my functions from the basic LabView toolset.  So I can't help you with that part, but I really think you'd be better off if you  got rid of it.

 

 

 

0 Kudos
Message 7 of 19
(3,355 Views)

Initially i did it that way it does not work. I can get rid of simulation loop but is not possible for me to use integrator in while loop,  i tried it does not work , i want to use integrators to have solution variable equations not as deratives or is there any way to have  solution of equations using while loop without use of  integrators. Thanks

0 Kudos
Message 8 of 19
(3,337 Views)

Initially i have done it that way it does not work as attached. What i am interested is to use integrators from control and simulation because of the initial condition of the variables to solve the differential using formula node inside while loop so that i take the sum from middle iteration to the last but the integrator can not be inserted in while loop that is why i used simulation loop, i want to get rid of it because of this synchronization problem. I want solve the differential equations if not using integrators how do i go about it. Thanks

0 Kudos
Message 9 of 19
(3,324 Views)

Hi Abul,

 

You will still be able to solve differential equations by using VIs built in on the Mathematics portion of your Functions palette. I have linked you to a website here that discusses the different VIs on this palette. Using these will help you solve the differential equations and allow you to move away from the Simulation Loop. Hope this helps!

 

Mychal F

Applications Engineer
National Instruments
0 Kudos
Message 10 of 19
(3,303 Views)