#This is my code
import numpy as np
import sympy as sp
n=3
y = [sp.symbols('y%d' % i) for i in range(8*n-4)]
#x=sp.symbols('x:n')
x=np.zeros((1,n))
for i in range(n):
x[i]=sp.gamma(y[i])
print(x)
I need x[i] to continue the code, but unfortunately, this error occurred. ###################### My modified code is here and the error " '<' not supported between instances of 'tuple' and 'int' " occurred after executing code.
import numpy as np
import sympy as sp
from sympy.matrices import zeros
from gekko import GEKKO
# create variables
n=3;z=1
m = GEKKO(remote=False)
x = [sp.symbols('x%d' % i) for i in range(8*n-4)]
#x=sp.symbols('x:20')
t=sp.symbols('t ')
B=np.zeros((n,n))
number = range(n)
for i in number:
for j in number:
if i<j :
B[i][j]=0
else :
B[i][j]=sp.factorial(i+j)/(2**j*sp.factorial(j)*sp.factorial(i-j))
PS=[x[0:n]];PI=[x[n:2*n]];PH=[x[2*n:3*n]];PL=[x[3*n:4*n]]
TS=[[1]];TI=[[1]];TH=[[1]];TL=[[1]]
for i in range(n-1):
TS.append([t**(x[4*n+i]+i+1)])
TI.append([t**(x[5*n+i-1]+i+1)])
TH.append([t**(x[6*n+i-2]+i+1)])
TL.append([t**(x[7*n+i-3]+i+1)])
S=np.dot(np.dot(PS,B),TS)
I=np.dot(np.dot(PI,B),TI)
H=np.dot(np.dot(PH,B),TH)
L=np.dot(np.dot(PL,B),TL)
DS0=zeros((n,n))
#DI0=np.zeros((n,n));DH0=np.zeros((n,n));DL0=np.zeros((n,n))
for i in number:
if i==0:
DS0[i][i]=0
#DI0[i][i]=0
#DH0[i][i]=0
# DL0[i][i]=0
else:
DS0[i][i]=sp.gamma(x_4*n+i+1)/sp.gamma(x_4*n+i+1-z)
#ss=sp.integrate(s[0][0],(t,0,1))
print (DS0)
As mentioned in the comments, you're mixing numpy and sympy. If you stick to pure sympy, you can create the y symbols and then use list comprehension in sp.Matrix
. To make sure you create a row vector, you can double the parentheses around the entire list comprehension. Though, if you don't actually want a sympy Matrix
, you can just use the list comprehension for a regular Python list of gamma function evaluations.
import sympy as sp
n = 3
y = sp.symbols(f"y:{n}")
x = sp.Matrix([[sp.gamma(yi) for yi in y]])