The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
Recursive functions and Advanced Graphing
09-11-2018, 12:34 PM
Post: #1
Recursive functions and Advanced Graphing
I’m intrigued by the ability of the Prime to handle recursion in simple function definitions.. but also its limitations.

Note - I’m just using the Lite app at present, so have no access to programming.

Ay first sight, it appears that the Define function does not allow you to reference the function being defined. If I try to define fact(X)=when(X<=2,X,X*fact(X-1)), it gives a syntax error.

However, I discovered that if you first define fact as a non-recursive function, e.g. X*(X-1), and exit the Define screen, the calculator ‘learns’ that “fact” is a function; you can then go back in and edit the function to make the recursive call to itself.

Sure enough, fact(5) gives 120. (The calculator does struggle after roughly 35 iterations, presumably as the stack overflows, but that’s to be expected.)

Next, I plot fact(X)in the Graphing app. It’s a tad slower than plotting a ‘normal’ function, but very impressive!

I now go into Advanced Graphing, and try Z1: Y=fact(X)... and sadly get an ‘Invalid object’ error.

Does anyone know why this fails, and if there’s a way around it?

(Motivation: what I really want to do is define mandelbrot(N, Z, C)= when(N<2, |Z|<2, mandelbrot(N-1, Z^2+C),C), and plot mandelbrot(20, 0, X+Yi)=1 ! :-) )
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Recursive functions and Advanced Graphing - Sven44 - 09-11-2018 12:34 PM



User(s) browsing this thread: 2 Guest(s)