x and y must have same first dimension, but have shapes (10000,) and (1,)のエラーの解決
要素数がなぜ変化しているのかがわからない
from scipy.special import kv
import matplotlib.pyplot as plt
from scipy.integrate import quad
import numpy as np
import math
from math import gamma
from sympy import *
import os
xs=np.logspace(-4, 2, 10000)
ys=np.logspace(0, 5, 10000)
vs=np.logspace(0,5,10000)
m=9.10938356*1e-31
c=2.99792458*1e+8
q=1.6021766208*1e-19
pa=np.pi/2#ピッチ角#
sin_pa=math.sin(pa)
B1=100*1e-6*1e-4
a = gamma(1/3)
def v_c(y):
return 3*y**2*q*B1*sin_pa/(4*np.pi*m*c)
f = lambda z: kv(5/3,z)
F = [quad(f,x,np.inf)[0]*x for x in xs]
G = [(4*np.pi/np.sqrt(3)/a)*(x/2)**(1/3) for x in xs]
H = [((np.pi/2)**(1/2))*(x**(1/2))*(np.exp(-x))for x in xs]
def A(x,y,F,G,H):
if x <= 5.0*1e-3:
return G(x,y)
elif 5.0*1e-3 < x < 30:
return F(x,y)
elif 30 <= x:
return H(x,y)
vec_A = np.vectorize(A)
def L(x,y):
return vec_A(xs,ys,F,G,H)
def P(v,y):
x=v/v_c
return (math.sqrt(3)*q**3*B1*sin_pa/(m*c**2))*L(v/v_c)
gmin=1
gmax=10**5
N=10
p=-2
def R(v,y):
return N*y**-p*P
def Pt(v):
return [quad(lambda y:R, gmin, gmax)[0] for y in ys]
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.grid
ax.set_yscale('log')
ax.set_xscale('log')
ax.plot(vs,Pt)
plt.show()
エラー
ValueError Traceback (most recent call last)
<ipython-input-5-33ed3b99f09b> in <module>
60 ax.set_yscale('log')
61 ax.set_xscale('log')
---> 62 ax.plot(vs,Pt)
63
64 plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
1663 """
1664 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
-> 1665 lines = [*self._get_lines(*args, data=data, **kwargs)]
1666 for line in lines:
1667 self.add_line(line)
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in __call__(self, *args, **kwargs)
223 this += args[0],
224 args = args[1:]
--> 225 yield from self._plot_args(this, kwargs)
226
227 def get_next_color(self):
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
389 x, y = index_of(tup[-1])
390
--> 391 x, y = self._xy_from_xy(x, y)
392
393 if self.command == 'plot':
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _xy_from_xy(self, x, y)
268 if x.shape[0] != y.shape[0]:
269 raise ValueError("x and y must have same first dimension, but "
--> 270 "have shapes {} and {}".format(x.shape, y.shape))
271 if x.ndim > 2 or y.ndim > 2:
272 raise ValueError("x and y can be no greater than 2-D, but have "
ValueError: x and y must have same first dimension, but have shapes (10000,) and (1,)
追記
from scipy.special import kv
import matplotlib.pyplot as plt
from scipy.integrate import quad
import numpy as np
import math
from math import gamma
from sympy import *
import os
x=np.logspace(-4, 2, 10000)
xs=np.logspace(-4, 2, 10000)
v=np.logspace(-4, 2, 10000)
m=9.10938356*1e-31
c=2.99792458*1e+8
q=1.6021766208*1e-19
pa=np.pi/2
sin_pa=math.sin(pa)
B1=100*1e-6*1e-4
a = gamma(1/3)
f = lambda z: kv(5/3,z)
F = [quad(f,x,np.inf)[0]*x for x in xs]
G = [(4*np.pi/np.sqrt(3)/a)*(x/2)**(1/3) for x in xs]
H = [((np.pi/2)**(1/2))*(x**(1/2))*(np.exp(-x))for x in xs]
def A(x,F,G,H):
if x <= 5.0*1e-3:
return G
elif 5.0*1e-3 < x < 30:
return F
elif 30 <= x:
return H
vec_A = np.vectorize(A)
L=vec_A(xs,F,G,H)
P=(math.sqrt(3)*q**3*B1*sin_pa/(m*c**2))*L
gmin=1
gmax=10**5
N=10/(10**5-1)
p=-2
s[0]=L*x**(-1/2)
def x1(v):
return 4*np.pi*m*c*v/(3*q*B1*sin_pa*gmin**2)
def x2(v):
return 4*np.pi*m*c*v/(3*q*B1*sin_pa*gmax**2)
b1=-1/np.sqrt(v)
b2=(np.sqrt(3)*q**3*B1*sin_pa/(2*m*c**2))
b3=np.sqrt(3*q*B1*sin_pa/(4*np.pi*m*c))
b=b1*b2*b3*N
Pt=[quad(s,4*np.pi*m*c*v/(3*q*B1*sin_pa*1**2),4*np.pi*m*c*v/(3*q*B1*sin_pa*(10**5)**2))[0]*b for x in xs]
vec_B = np.vectorize(Pt)
Ptot=vec_B(v)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(xs,Ptot)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-14-6fbdeb4f340e> in <module>
58 b=b1*b2*b3*N
59
---> 60 Pt=[quad(s,4*np.pi*m*c*v/(3*q*B1*sin_pa*1**2),4*np.pi*m*c*v/(3*q*B1*sin_pa*(10**5)**2))[0]*b for x in xs]
61
62 vec_B = np.vectorize(Pt)
<ipython-input-14-6fbdeb4f340e> in <listcomp>(.0)
58 b=b1*b2*b3*N
59
---> 60 Pt=[quad(s,4*np.pi*m*c*v/(3*q*B1*sin_pa*1**2),4*np.pi*m*c*v/(3*q*B1*sin_pa*(10**5)**2))[0]*b for x in xs]
61
62 vec_B = np.vectorize(Pt)
C:\ProgramData\Anaconda3\lib\site-packages\scipy\integrate\quadpack.py in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
336
337 # check the limits of integration: \int_a^b, expect a < b
--> 338 flip, a, b = b < a, min(a, b), max(a, b)
339
340 if weight is None:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()