Choose Language Hide Translation Bar
Highlighted
skyzvoir0001
Level III

generate

how to generate the nth fibonacci number?

4 REPLIES 4
Highlighted
ron_horne
Super User

Re: generate

Hi @skyzvoir0001 

H

Names Default To Here( 1 );
// declare the ith item you are looking for
FibN = 10;

New Table( "Fibonacci", // private,
	Add Rows( fibN ),
	New Column( "Fib",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Formula( If( Row() == 1, 0, Row() == 2, 1, Lag( :Fib, 1 ) + Lag( :Fib, 2 ) ) ),
		Set Selected
	)
);
wait (.01);
nthfib = Col Max( :fib );
close ("Fibonacci", NoSave);
show (nthfib);



ave a look at this script. it many not be the sleekest but you can control it very easily.

It creates a table with a column containing the Fibonacci series and extracts the last value.

Let us know if it works for you.

 

Highlighted
skyzvoir0001
Level III

Re: generate

Thanks for this!
Highlighted

Re: generate

Your request is vague. I think that @ron_horne provided a good solution if you want to make a JMP data table with the Fibonacci sequence. If instead you want to calculate a particular value in the sequence, then use Method 2 shown in this answer. It is not clear if you want to make a column formula, create a user function, or add the calculation to a script for this purpose.

Learn it once, use it forever!
Highlighted
txnelson
Super User

Re: generate

Using @markbailey link, here is the simple script to get the value of a given sequence step

seq=6;
floor((1.618034^seq-(1-1.618034)^seq)/sqrt(5));
Jim
Article Labels

    There are no labels assigned to this post.