When I go to print my matrix, it prints an error that says 'Float' object has no attribute 'sin'.
While coding in Python, I am attempting to print a matrix in symbolic form using sym.matrix but I am defining my matrix numerically. When I go to print my matrix, it prints an error that says 'Float' object has no attribute 'sin'. It appears that for some reason, my sin function is not being read or outputted properly.
import numpy as np
from scipy.integrate import quad
from numpy import sin, cos, pi
N = 5
L = 1
r_e = 1.4
mu = 916
def Phi_V(x,n,r):
return (2/L)**(1/2) * sin(n*np.pi*x/L +n*np.pi/2) * 4.7 * (1-np.exp(-x))**2 * (2/L)**(1/2) * sin(r*np.pi*x/L +r*np.pi/2)
def V_Func(n,r,j):
return quad(Phi_V, -L/2, L/2, args = (n,r))[0] + (j*j+1)/(2*mu*r_e**2)
V = sym.Matrix(N,N, lambda n,r: V_Func(n + 1 ,r + 1,10))
V
I get this error message:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-38-8624393320b4> in <module>()
16 return quad(Phi_V, -L/2, L/2, args = (n,r))[0] + (j*j+1)/(2*mu*r_e**2)
17
---> 18 V = sym.Matrix(N,N, lambda n,r: V_Func(n + 1 ,r + 1,10))
19
20 V
/anaconda3/lib/python3.7/site-packages/sympy/matrices/dense.py in __new__(cls, *args, **kwargs)
418 class MutableDenseMatrix(DenseMatrix, MatrixBase):
419 def __new__(cls, *args, **kwargs):
--> 420 return cls._new(*args, **kwargs)
421
422 @classmethod
/anaconda3/lib/python3.7/site-packages/sympy/matrices/dense.py in _new(cls, *args, **kwargs)
430 rows, cols, flat_list = args
431 else:
--> 432 rows, cols, flat_list = cls._handle_creation_inputs(*args, **kwargs)
433 flat_list = list(flat_list) # create a shallow copy
434 self = object.__new__(cls)
/anaconda3/lib/python3.7/site-packages/sympy/matrices/matrices.py in _handle_creation_inputs(cls, *args, **kwargs)
2111 flat_list.extend(
2112 [cls._sympify(op(cls._sympify(i), cls._sympify(j)))
-> 2113 for j in range(cols)])
2114
2115 # Matrix(2, 2, [1, 2, 3, 4])
/anaconda3/lib/python3.7/site-packages/sympy/matrices/matrices.py in <listcomp>(.0)
2111 flat_list.extend(
2112 [cls._sympify(op(cls._sympify(i), cls._sympify(j)))
-> 2113 for j in range(cols)])
2114
2115 # Matrix(2, 2, [1, 2, 3, 4])
<ipython-input-38-8624393320b4> in <lambda>(n, r)
16 return quad(Phi_V, -L/2, L/2, args = (n,r))[0] + (j*j+1)/(2*mu*r_e**2)
17
---> 18 V = sym.Matrix(N,N, lambda n,r: V_Func(n + 1 ,r + 1,10))
19
20 V
<ipython-input-38-8624393320b4> in V_Func(n, r, j)
14 return (2/L)**(1/2) * sin(n*np.pi*x/L +n*np.pi/2) * 4.7 * (1-np.exp(-x))**2 * (2/L)**(1/2) * sin(r*np.pi*x/L +r*np.pi/2)
15 def V_Func(n,r,j):
---> 16 return quad(Phi_V, -L/2, L/2, args = (n,r))[0] + (j*j+1)/(2*mu*r_e**2)
17
18 V = sym.Matrix(N,N, lambda n,r: V_Func(n + 1 ,r + 1,10))
/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
339 if weight is None:
340 retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
--> 341 points)
342 else:
343 retval = _quad_weight(func, a, b, args, full_output, epsabs, epsrel,
/anaconda3/lib/python3.7/site-packages/scipy/integrate/quadpack.py in _quad(func, a, b, args, full_output, epsabs, epsrel, limit, points)
446 if points is None:
447 if infbounds == 0:
--> 448 return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
449 else:
450 return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
<ipython-input-38-8624393320b4> in Phi_V(x, n, r)
12
13 def Phi_V(x,n,r):
---> 14 return (2/L)**(1/2) * sin(n*np.pi*x/L +n*np.pi/2) * 4.7 * (1-np.exp(-x))**2 * (2/L)**(1/2) * sin(r*np.pi*x/L +r*np.pi/2)
15 def V_Func(n,r,j):
16 return quad(Phi_V, -L/2, L/2, args = (n,r))[0] + (j*j+1)/(2*mu*r_e**2)
AttributeError: 'Float' object has no attribute 'sin'