LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Recursivity with MathScrip

Hello,

I would like to use mathscript to code some recursive function,

So, I tried to code the classical factorial function :


function answer = factorielle(n)
    if( n == 0 )
        answer = 1;
        return;
    else
        answer = n*factorielle(n-1);
    end


But it seems that it is not working...
Is my code wrong ? or is recursivity not working ?

Thank,
Pierre
0 Kudos
Message 1 of 2
(6,690 Views)
Hi Pierre,

Unfortunately, MathScript does not support recursive functions.  There is, of course, a function called factorial that computes the factorial of a given number.  But I suspect this is not what you are trying to accomplish.  You have also discovered a bug in that we do not report an error message on an attempted recursive function call.  This makes the function appear to work and just fail to return a value.  We are aware of the lack of support for recursive functions and are considering adding support for them in a future version of MathScript.  For now, you can try to implement your recursive function with an iterative method.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 2 of 2
(6,684 Views)