LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Loop

Solved!
Go to solution

Oops, sorry to have not returned and responded.  I thought I'd leave you with the following Demo, which you can compare with your own Recursive routine.  I'm using Strings (to demonstrate that recursion works in all kinds of situations) instead of numbers, but it is the same idea.  I have an Array, Q, of Coefficients (the Array has ["a1", "a2", "a3", "a4", "a5"] in "text-language notation" for an array of strings, the first being the string "a1", etc.) and a variable X (the string "x").  It calls the Recursive Routine, which produces the Polynomial, the string "a1 + x * (a2 + x * (a3 + x * (a4 + x * a5))))".  The calling routine is simple:

DEMO Recursive Evaluate Polynomial.png

 The Recursive Evaluate routine is a tiny bit more complicated, but here is the main Recursive call:

Recursive Evaluate.png

Here's how it works:

  • The outer Case structure handles an empty Coefficient Array, and returns a blank string (there's nothing to do, so do nothing).  Otherwise --
  • Strip off the leading Coefficient from the Coefficient Array.  Now test if that was the final coefficient (because what is left is an empty Array).  If so, jjust return that Coefficient (and you are done).  Otherwise --
  • The Recursion takes place inside the inner Case Statement.  You form a string (using Format Into String) having three components:
    • the isolated leading coefficient stripped from the Coefficients array and a Plus sign (" + ")
    • the symbol for the unknown, X  followed by a Times symbol (" * ")
    • and the string formed by recursively calling the function with the remaining Coefficients, surrounded by parentheses

And that does it!  Substituting Arrays of Dbls for the coefficients and a Dbl for X, and replacing the string operations with their arithmetic counterparts will let you do Polynomial Evaluation numerically.

 

Enjoy.

 

Bob Schor

 

Download All
Message 11 of 13
(871 Views)

Hi Bob,

        Thanks for your patience and explaining me the concepts in detail. Truely, your inputs helped me a lot. Thanks again!

0 Kudos
Message 12 of 13
(853 Views)

@rajram75 wrote:

Hi Bob,

        Thanks for your patience and explaining me the concepts in detail. 


It's always fun (for me) when a Forum topic hits on something about LabVIEW that I find to be especially interesting, like Recursion ...

 

Bob Schor

0 Kudos
Message 13 of 13
(843 Views)