04-20-2018 08:02 AM
tl;dr
How do I make this go?
So here is the code in actual MatLab:
N = 10; F = myfib(N); disp([N,F]) function [out] = myfib(n) if n< 2 out = 1; else out = myfib(n-2) + myfib(n-1); end end
It yields this as output:
>> myfib_in_MatLab 10 89 >>
I want to do something similar in MathScript.
Here is my Snippet:
You can notice that the text is grayed, it isn't compiling, and there is no output. It can't detect "F" as an output variable.
04-20-2018 06:21 PM
So don't use MathScript. Do it in LabVIEW. Note that Recursion, while really neat and lots of fun, does require that you know what you are doing and understand Reentrancy ... Note that the Recursive Form you've given is the usual form for the Fibonacci series, but it is very inefficient, particularly for larger numbers (the number of calls grows much faster than N).
I just coded it (in LabVIEW) and got the following values for n = 1 .. 6: 1, 1, 2, 3, 5, 8.
Bob Schor
04-24-2018 03:24 PM
Bob,
This is a toy that demonstrates recursion. I don't have the choice of whether or not to use MathScript. If I need to learn how reentrancy works, I should do that instead.
Can you provide references or links?
-EngrStudent
04-24-2018 08:07 PM
Well, I know LabVIEW. I also know Matlab (or used to -- it's been about a decade since I did anything serious in Matlab), but have never thought to bother with MathScript (the Worst of Both Worlds). I have no idea why MathScript doesn't "do" recursion. I do know that LabVIEW does, but since you "have no choice of whether or not to use MathScript", I can't be of any help to you. Good luck.
BS