May-03-2019, 04:53 PM
I'm trying to understand the following code that sets up the three term recursion ui+1=a1u1+a0ui-1 as a class:
class Recursion3Term: def __init__ (self , a0 , a1 , u0 , u1 ): self.coeff = [a1 , a0] self.initial = [u1 , u0] def __iter__ ( self ): u1,u0 = self.initial yield u0 yield u1 a1,a0=self.coeff while True: u1 , u0 = a1*u1 + a0*u0 , u1 yield u1 def __getitem__ (self,k): for i, r in enumerate (self): if i == k: return rI would deeply appreciate a short explanation about line 5 to 16. For example in the iterable method, why are the different yield statements necessary? What does the while-loop do? What is
r
?