#Constantly moving up: what was Fn in the last iteration, becomes Fn_1, and so on
#create tensors
update1=tf.assign(temp,Fn)
update2=tf.assign(Fn_2,Fn_1)
update3=tf.assign(Fn_1,temp)
#run session and print 30 numbers
init = tf.global_variables_initializer()
#tensorflow assigns values; we execute
#this is all just painting of the graph of the operations we will execute
with
tf.Session()
as
sess:
sess.run(init)
#We tell Session to execute init
#Now we do the loop from 0 to 29, and print a; step is integer
for
step
in
range(30):
print('Fibonacci('
+
str(step)
+
')= '
+
str(sess.run(Fn_2)))
#adding string
sess.run(update1)
#see above: what ever was in Fn (the most recently cal
sess.run(update2)
#whatever was in Fn_1 is pushed into Fn_2; whatever was
sess.run(update3)
#calculate Fn
#we always print the lowest Fibonacci we have -- Fn_2
#create graph
file_writer = tf.summary.FileWriter("fibonacci02", sess.graph)
file_writer.add_graph(sess.graph)
file_writer.close()
sess.close()
#to see graph, we run on Command Prompt tensorboard --logdir fibonacci02

11/5/2017
Lab_10_Fibonacci_sequence
8/8
In [ ]:
Fibonacci(17)= 1597
Fibonacci(18)= 2584
Fibonacci(19)= 4181
Fibonacci(20)= 6765
Fibonacci(21)= 10946
Fibonacci(22)= 17711
Fibonacci(23)= 28657
Fibonacci(24)= 46368
Fibonacci(25)= 75025
Fibonacci(26)= 121393
Fibonacci(27)= 196418
Fibonacci(28)= 317811
Fibonacci(29)= 514229

You've reached the end of your free preview.
Want to read all 8 pages?
- Fall '17
- Recurrence relation, Fibonacci number