回答編集履歴

1

訂正

2017/11/14 06:53

投稿

mkgrei
mkgrei

スコア8560

test CHANGED
@@ -5,3 +5,89 @@
5
5
  return c*(1.+z)/(H0*np.sqrt(abs(1.-omega_m-omega_l)))*np.sinh(np.sqrt(abs(1.-omega_m-omega_l))*integrate.quad(integrand,0.,z))
6
6
 
7
7
  の部分に相当するものが上に貼り付けてあるコードに含まれてないのは気のせいでしょうか?
8
+
9
+
10
+
11
+ ---
12
+
13
+ 追記:
14
+
15
+ 不思議な質問ですね。
16
+
17
+ 貼り付けてあるコードは普通に動きます。(一部numpy->npのミスがありますが)
18
+
19
+ 正しく修正した後に過去のエラーを勘違いしていませんか?
20
+
21
+ i=integrate.quad(integrand,0.,z)
22
+
23
+ .....*i[0]
24
+
25
+ とご自身で訂正されています?
26
+
27
+
28
+
29
+ ```python
30
+
31
+ import math
32
+
33
+ import numpy as np
34
+
35
+ import scipy.optimize
36
+
37
+ from scipy import integrate
38
+
39
+ from scipy.optimize import curve_fit
40
+
41
+ import matplotlib.pyplot as plt
42
+
43
+ import scipy
44
+
45
+
46
+
47
+ def dL(z,omega_m,omega_l,H0,c):
48
+
49
+ def integrand(x):
50
+
51
+ return 1. / np.sqrt((1.+x)**2.*(1.+x*omega_m)-x*(2.+x)*omega_l)
52
+
53
+
54
+
55
+ if omega_m + omega_l ==1:
56
+
57
+ i=integrate.quad(integrand,0.,z)
58
+
59
+ return c*(1.+z)/H0*i[0]
60
+
61
+ elif omega_m + omega_l > 1:
62
+
63
+ i=integrate.quad(integrand,0.,z)
64
+
65
+ return c*(1.+z)/(H0*np.sqrt(abs(1.-omega_m-omega_l)))*np.sin(np.sqrt(abs(1.-omega_m-omega_l))*i[0])
66
+
67
+ else:
68
+
69
+ i=integrate.quad(integrand,0.,z)
70
+
71
+ return c*(1.+z)/(H0*np.sqrt(abs(1.-omega_m-omega_l)))*np.sinh(np.sqrt(abs(1.-omega_m-omega_l))*i[0])
72
+
73
+
74
+
75
+ dL = np.vectorize(dL, excluded=("omega_m","omega_l","H0","c"))
76
+
77
+
78
+
79
+ def m_model(z,omega_m,omega_l,H0,MB,sth):
80
+
81
+ return MB + 5.0*np.log(dL(z,omega_m,omega_l,H0,sth))+25.0
82
+
83
+
84
+
85
+ def m_model_00(x):
86
+
87
+ return m_model(x,0.,0.,0.7,-1.8,1.)
88
+
89
+
90
+
91
+ print(m_model_00(0.4))
92
+
93
+ ```