v-Ptグラフをプロットしたいがx and y must have same first dimension, but have shapes (10000,) and (1,)のエラーが出る
python
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()
エラー
python
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,)
書き換えてみたけど別のエラーが出る。
python
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) 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(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): return vec_A(xs,F,G,H) def P(v,y): return (math.sqrt(3)*q**3*B1*sin_pa/(m*c**2))*L(v/v_c) gmin=1 gmax=10**5 N=10/(10**5-1) p=-2 def s(x): b=L*x**(-1/2) return b 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) def b(v): b1=-1/math.sqrt(v) b2=(math.sqrt(3)*q**3*B1*sin_pa/(2*m*c**2)) b3=math.sqrt(3*q*B1*sin_pa/(4*np.pi*m*c)) return b1*b2*b3*N def Pt(v): a=[quad(s,x1(v),x2(v))[0] for x in xs] return b*a[0] v=np.logspace(-4,2,10000) plt.plot(v,Pt(v)) plt.show()
エラー
python
ValueError Traceback (most recent call last) <ipython-input-14-4d47f52aab3a> in <module> 66 v=np.logspace(-4,2,10000) 67 ---> 68 plt.plot(v,Pt(v)) 69 plt.show() 70 <ipython-input-14-4d47f52aab3a> in Pt(v) 61 62 def Pt(v): ---> 63 a=[quad(s,x1(v),x2(v))[0] for x in xs] 64 return b*a[0] 65 <ipython-input-14-4d47f52aab3a> in <listcomp>(.0) 61 62 def Pt(v): ---> 63 a=[quad(s,x1(v),x2(v))[0] for x in xs] 64 return b*a[0] 65 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()
まだ回答がついていません
会員登録して回答してみよう