From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can LabVIEW do mathematical recursion?

Hi All,

I am encountering a problem when I was trying to use labview to solve some equations, say, y=a*ln(x)+b*ln(x)^2... where y is known and x is what needs to be known. My idea is I need to do some cyclings from a X value to another to find out the best value of X. But I really can not let LabVIEW loop to work this out. Can it do this sort of job? I am pretty curious to learn. Thanks.

Best,
Fan

--
Fan Zhang
Dept of Physics and Astronomy
University of Pennsylvania

-----" A journey of a thousand miles must begin with a single step."
0 Kudos
Message 1 of 3
(2,684 Views)
Well, I'm going to give it a try.

I assume that your expression "But I really can not let LabVIEW loop to work this out" does not mean that you can NOT use loops 🙂

First, in your expression y=f(x), if you know the value of "y", you can always equate the expression to zero:

f(x) - y = 0

The problem is now to find the roots of the equation. If that's allowed, then you may want to try LabVIEW's mathematical VIs, which are located in the diagram function palette -> Mathematics -> Zeroes.

If you must, need or want to use a loop, for example a While loop, you may want to use Shift Registers. Shift registers allows you to remember iteration values. To add a shift register, right-click on one of the side borders of the loop and select "Add Shift Register" from the pop
-up menu. When you do that, two registers will appear at both sides of the loop diagram. To initialize the value of a shift register, wire the left side shift register from outside.

When the loop executes, it takes the initial value (left shift register) and you can process it inside the loop using your recursive formula. When functions inside the loop ends executing, the resulting value should be the input of the right shift register. If the loop execute again, the value entered at the right side will go to the left side, so it is the new value for the next iteration. And so on.

For the condition to stop the while loop, if the solution is not going to be exact, you should define and test an error tolerance between iterations.

To extract the resulting value after the loop finish executing, wire the right shift register.

Hope this can be of help.

Regards;
Enrique Vargas
www.vartortech.com
Message 2 of 3
(2,684 Views)
Errata:

The paragraph starting "For the condition..." should read "About the conditions to stop a while loop:".

The paragraph starting "To extract the resulting..." should read "To extract the resulting value after the loop finish executing, wire the right shift register from outside."

I hit the submit button by error.

Vargas
www.vartortech.com
0 Kudos
Message 3 of 3
(2,684 Views)