0
Hello,
I am trying to plot a 3D graph of an integral solution and am having the error "only size-1 arrays can be converted to Python scalars". When I try to plot a function simpler than the original Plot appears. What I’m doing wrong?
the code
import numpy as np
import matplotlib.pyplot as plt
import math as m
import scipy as sp
import cmath as c
import scipy.integrate as integrate
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from scipy.special import gamma
k = 0.1
def teste2(x, chi):
s = np.sin(z)
return s
def solnum(x, chi, y): #Tudo que vai entrar na integral
Bk = ((2*(k))**(3/2))*((1+(1.5*abs(k))))*(gamma((1/(2*abs(k)))+(3/4))/gamma((1/(2*(k)))-(3/4)))
C = (chi/(2*(np.pi)**(0.5)))
R1 = (1/(1+(y**2)))
R21 = ((k**2)*(-((chi**2)*((x-y)**2))/4))
R22 = ((1+((k**2)*(-((chi**2)*((x-y)**2))/4)**2))**(0.5))
R23 = (R21-R22)/(k**2 - 1)
R3 = (((((1+((k**2)*(-((chi**2)*((x-y)**2))/4)**2))**(0.5))) + ((k*(-((chi**2)*((x-y)**2))/4))))**(1/k))
sn = (C*Bk*R1*R23*R3)
return sn
def teste(x, chi):
l = x**2 + (chi)**2
return l
def f(x,chi): #O cálculo da integral em si
j = lambda y: solnum(x, chi, y)
resint = integrate.quad(j, -200, 200)
return (resint[0])
x = np.linspace(-40.,40.,num=200)
chi = np.linspace(0.05, 0.50, num=200)
x, chi = np.meshgrid(x,chi)
z = f(x,chi) #quando eu uso a função teste, por exemplo, o código roda
print(f(0.,0.05))
fig = plt.figure()
grafico = fig.gca(projection='3d')
surf = grafico.plot_surface(x, chi, z)
plt.show()
the error presented:
Traceback (most recent call last):
File "c:/Users/pwadmin/Google Drive/Pós-Doc/Py2/Completão/Tentativas de melhoramento/Teste plot função numérica.py", line 50, in <module>
z = f(x,chi)
File "c:/Users/pwadmin/Google Drive/Pós-Doc/Py2/Completão/Tentativas de melhoramento/Teste plot função numérica.py", line 44, in f
resint = integrate.quad(j, -200, 200)
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\integrate\quadpack.py", line 351, in quad
retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\integrate\quadpack.py", line 463, in _quad
return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
TypeError: only size-1 arrays can be converted to Python scalars