0

I have created the code for recurrence relationship for two coupled sequences but for some reason, I'm getting an error

Code:

import math

for x,y in range(1,3):
    def Function_X_Y(x,y):
        x_val = (-5*x*(n-2)) + (2*y*(n-1))
        y_val = (3*y*(n-2)) - (4*x*(n-1)) + (4*y*(n-1)) 
        return(x_val, y_val)

def coupled_sequence(n):
    return Function_X_Y(x,y)

print(coupled_sequence(0))
print(coupled_sequence(1))
print(coupled_sequence(5))

#Expected output: print(coupled_sequence(0))
#>>> (1, 1)

#print(coupled_sequence(1))
#>>> (2, 2)

#print(coupled_sequence(5))
#>>> (246, 322)

Error

----> 5 for x,y in range(1,3):
      6     def Function_X_Y(x,y):
      7         x_val = (-5*x*(n-2)) + (2*y*(n-1))

TypeError: cannot unpack non-iterable int object 

I have tried different ways to iterate over the given function with the help of for loop, but can't get the expected output

Mayur Potdar
  • 451
  • 1
  • 8
  • 18
  • 1
    What specifically are you trying to do? Are you just trying to set `x=1` and `y=2`? It's not clear why you'd need a for loop to do that. And for that matter, `n` is undefined in `Function_X_Y`; I assume you're intending that to be passed in as a variable? Please clarify – Michael Oct 26 '19 at 03:10
  • I'm trying to set `x=y =1,2` can you help me how to define n as well ? and Yeah, I'm trying to pass it as a variable. `xn=−5xn−2+2yn−1` and `yn=3yn−2−4xn−1+4yn−1` where `x,y = 1, 2` I'm trying to iterate over the for loop to get the result from calling function. – Mayur Potdar Oct 26 '19 at 03:32

1 Answers1

1

Range as it is being used will only return one integer each iteration, so you cannot get multiple values that way. Depending on your use case you could just create another loop inside the one you have, see this question.

user7217806
  • 2,014
  • 2
  • 10
  • 12