teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

追記

2020/08/18 23:11

投稿

hataki7
hataki7

スコア4

title CHANGED
File without changes
body CHANGED
@@ -106,4 +106,111 @@
106
106
  272 raise ValueError("x and y can be no greater than 2-D, but have "
107
107
 
108
108
  ValueError: x and y must have same first dimension, but have shapes (10000,) and (1,)
109
+ ```
110
+
111
+ 書き換えてみたけど別のエラーが出る。
112
+ ```python
113
+ from scipy.special import kv
114
+ import matplotlib.pyplot as plt
115
+ from scipy.integrate import quad
116
+ import numpy as np
117
+ import math
118
+ from math import gamma
119
+ from sympy import *
120
+ import os
121
+
122
+ xs=np.logspace(-4, 2, 10000)
123
+
124
+
125
+ m=9.10938356*1e-31
126
+ c=2.99792458*1e+8
127
+ q=1.6021766208*1e-19
128
+ pa=np.pi/2
129
+ sin_pa=math.sin(pa)
130
+ B1=100*1e-6*1e-4
131
+ a = gamma(1/3)
132
+
133
+ f = lambda z: kv(5/3,z)
134
+ F = [quad(f,x,np.inf)[0]*x for x in xs]
135
+ G = [(4*np.pi/np.sqrt(3)/a)*(x/2)**(1/3) for x in xs]
136
+ H = [((np.pi/2)**(1/2))*(x**(1/2))*(np.exp(-x))for x in xs]
137
+
138
+ def A(x,F,G,H):
139
+ if x <= 5.0*1e-3:
140
+ return G(x,y)
141
+ elif 5.0*1e-3 < x < 30:
142
+ return F(x,y)
143
+ elif 30 <= x:
144
+ return H(x,y)
145
+
146
+ vec_A = np.vectorize(A)
147
+ def L(x):
148
+ return vec_A(xs,F,G,H)
149
+
150
+ def P(v,y):
151
+ return (math.sqrt(3)*q**3*B1*sin_pa/(m*c**2))*L(v/v_c)
152
+
153
+ gmin=1
154
+ gmax=10**5
155
+ N=10/(10**5-1)
156
+ p=-2
157
+
158
+
159
+ def s(x):
160
+ b=L*x**(-1/2)
161
+ return b
162
+
163
+ def x1(v):
164
+ return 4*np.pi*m*c*v/(3*q*B1*sin_pa*gmin**2)
165
+ def x2(v):
166
+ return 4*np.pi*m*c*v/(3*q*B1*sin_pa*gmax**2)
167
+
168
+ def b(v):
169
+ b1=-1/math.sqrt(v)
170
+ b2=(math.sqrt(3)*q**3*B1*sin_pa/(2*m*c**2))
171
+ b3=math.sqrt(3*q*B1*sin_pa/(4*np.pi*m*c))
172
+ return b1*b2*b3*N
173
+
174
+ def Pt(v):
175
+ a=[quad(s,x1(v),x2(v))[0] for x in xs]
176
+ return b*a[0]
177
+
178
+ v=np.logspace(-4,2,10000)
179
+
180
+ plt.plot(v,Pt(v))
181
+ plt.show()
182
+
183
+ ```
184
+ エラー
185
+ ```python
186
+ ValueError Traceback (most recent call last)
187
+ <ipython-input-14-4d47f52aab3a> in <module>
188
+ 66 v=np.logspace(-4,2,10000)
189
+ 67
190
+ ---> 68 plt.plot(v,Pt(v))
191
+ 69 plt.show()
192
+ 70
193
+
194
+ <ipython-input-14-4d47f52aab3a> in Pt(v)
195
+ 61
196
+ 62 def Pt(v):
197
+ ---> 63 a=[quad(s,x1(v),x2(v))[0] for x in xs]
198
+ 64 return b*a[0]
199
+ 65
200
+
201
+ <ipython-input-14-4d47f52aab3a> in <listcomp>(.0)
202
+ 61
203
+ 62 def Pt(v):
204
+ ---> 63 a=[quad(s,x1(v),x2(v))[0] for x in xs]
205
+ 64 return b*a[0]
206
+ 65
207
+
208
+ 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)
209
+ 336
210
+ 337 # check the limits of integration: \int_a^b, expect a < b
211
+ --> 338 flip, a, b = b < a, min(a, b), max(a, b)
212
+ 339
213
+ 340 if weight is None:
214
+
215
+ ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
109
216
  ```

2

文字の修正

2020/08/18 23:11

投稿

hataki7
hataki7

スコア4

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- x-Ptグラフをプロットしたいがx and y must have same first dimension, but have shapes (10000,) and (1,)のエラーが出る
1
+ v-Ptグラフをプロットしたいがx and y must have same first dimension, but have shapes (10000,) and (1,)のエラーが出る
2
2
 
3
3
 
4
4
  ```python
@@ -13,6 +13,8 @@
13
13
 
14
14
  xs=np.logspace(-4, 2, 10000)
15
15
  ys=np.logspace(0, 5, 10000)
16
+ vs=np.logspace(0,5,10000)
17
+
16
18
  m=9.10938356*1e-31
17
19
  c=2.99792458*1e+8
18
20
  q=1.6021766208*1e-19
@@ -49,11 +51,11 @@
49
51
  N=10
50
52
  p=-2
51
53
 
52
- def R(y):
54
+ def R(v,y):
53
55
  return N*y**-p*P
54
56
 
55
57
  def Pt(v):
56
- return [quad(R, gmin, gmax)[0] for y in ys]
58
+ return [quad(lambda y:R, gmin, gmax)[0] for y in ys]
57
59
 
58
60
 
59
61
  fig = plt.figure()
@@ -61,19 +63,19 @@
61
63
  ax.grid
62
64
  ax.set_yscale('log')
63
65
  ax.set_xscale('log')
64
- ax.plot(xs,Pt)
66
+ ax.plot(vs,Pt)
65
67
 
66
68
  plt.show()
67
69
  ```
68
70
  エラー
69
71
  ```python
70
72
  ValueError Traceback (most recent call last)
71
- <ipython-input-9-c903738de0cc> in <module>
73
+ <ipython-input-5-33ed3b99f09b> in <module>
72
- 58 ax.set_yscale('log')
74
+ 60 ax.set_yscale('log')
73
- 59 ax.set_xscale('log')
75
+ 61 ax.set_xscale('log')
74
- ---> 60 ax.plot(xs,Pt)
76
+ ---> 62 ax.plot(vs,Pt)
75
- 61
77
+ 63
76
- 62 plt.show()
78
+ 64 plt.show()
77
79
 
78
80
  C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
79
81
  1663 """

1

文字の修正

2020/08/18 18:22

投稿

hataki7
hataki7

スコア4

title CHANGED
File without changes
body CHANGED
@@ -16,7 +16,7 @@
16
16
  m=9.10938356*1e-31
17
17
  c=2.99792458*1e+8
18
18
  q=1.6021766208*1e-19
19
- pa=np.pi/2
19
+ pa=np.pi/2#ピッチ角#
20
20
  sin_pa=math.sin(pa)
21
21
  B1=100*1e-6*1e-4
22
22
  a = gamma(1/3)
@@ -27,18 +27,22 @@
27
27
  F = [quad(f,x,np.inf)[0]*x for x in xs]
28
28
  G = [(4*np.pi/np.sqrt(3)/a)*(x/2)**(1/3) for x in xs]
29
29
  H = [((np.pi/2)**(1/2))*(x**(1/2))*(np.exp(-x))for x in xs]
30
+
30
- def A(x,F,G,H):
31
+ def A(x,y,F,G,H):
31
32
  if x <= 5.0*1e-3:
32
- g =G
33
+ return G(x,y)
33
34
  elif 5.0*1e-3 < x < 30:
34
- g =F
35
+ return F(x,y)
35
36
  elif 30 <= x:
36
- g =H
37
- return g
37
+ return H(x,y)
38
+
38
39
  vec_A = np.vectorize(A)
40
+ def L(x,y):
39
- L = vec_A(xs,F,G,H)
41
+ return vec_A(xs,ys,F,G,H)
40
42
 
43
+ def P(v,y):
44
+ x=v/v_c
41
- P=(math.sqrt(3)*q**3*B1*sin_pa/(m*c**2))*L
45
+ return (math.sqrt(3)*q**3*B1*sin_pa/(m*c**2))*L(v/v_c)
42
46
 
43
47
  gmin=1
44
48
  gmax=10**5
@@ -51,6 +55,7 @@
51
55
  def Pt(v):
52
56
  return [quad(R, gmin, gmax)[0] for y in ys]
53
57
 
58
+
54
59
  fig = plt.figure()
55
60
  ax = fig.add_subplot(1,1,1)
56
61
  ax.grid
@@ -63,12 +68,12 @@
63
68
  エラー
64
69
  ```python
65
70
  ValueError Traceback (most recent call last)
66
- <ipython-input-1-8a0453e8c3d3> in <module>
71
+ <ipython-input-9-c903738de0cc> in <module>
67
- 53 ax.set_yscale('log')
72
+ 58 ax.set_yscale('log')
68
- 54 ax.set_xscale('log')
73
+ 59 ax.set_xscale('log')
69
- ---> 55 ax.plot(xs,Pt)
74
+ ---> 60 ax.plot(xs,Pt)
70
- 56
75
+ 61
71
- 57 plt.show()
76
+ 62 plt.show()
72
77
 
73
78
  C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
74
79
  1663 """