前提・実現したいこと
以下のコードを動かしてt,sigma1_c, sigma2_c, sigma3_c, qを求めたい。
発生している問題・エラーメッセージ
エラーメッセージ File "<ipython-input-15-7b6d1feb2de7>", line 51 reurn kf(x = 2) * r3 ^ SyntaxError: invalid syntax
該当のソースコード
python
1ソースコード 2import math 3def sigma_1(x): 4 return math.floor(x / 16) 5def sigma_2(x, sigma1): 6 return math.floor((x - 16 * sigma1) / 4) 7def sigma_3(x, sigma1, sigma2): 8 return x - 16 * sigma1 - 4 * sigma2 9def q64(x, y, z): 10 return 16 * x + 4 * y + z 11r2 = 100 12r3 = 1000 13r4 = 10000 14atp = 2 15adp = 2 16pi = 2 17def kf(x = 0): 18 return 0.11 * atp 19def kf(x = 1): 20 return 0.12 21def kf(x = 2): 22 return 1.6 * 10 ** (-3) 23def kf(x =3): 24 return 1.2 * 10 ** (-3) 25def kb(x = 0): 26 return 2.5 * 10 ** (-5) 27def kb(x = 1): 28 return 4.3 * 10 ** (-5) 29def kb(x = 2): 30 return 1.8 * 10 ** (-4) * adp 31def kb(x = 3): 32 return 4.8e-10 * pi 33q = 0 34while q <= 63: 35 sigma1 = sigma_1(q) 36 sigma2 = sigma_2(q, sigma1) 37 sigma3 = sigma_3(q, sigma1, sigma2) 38 def k(q, n = 0): 39 return kf(sigma1) 40 def k(q, n = 1): 41 return kb(sigma1) 42 def k(q, n = 2): 43 return kf(sigma2) 44 def k(q, n = 3): 45 return kb(sigma2) 46 def k(q, n = 4): 47 return kf(sigma3) 48 def k(q, n = 5): 49 return kb(sigma3) 50 q += 1 51def k(q = 22, n = 4): 52 reurn kf(x = 2) * r3 53def k(q = 23, n = 0): 54 return kf(x = 1) * r2 55def k(q = 25, n = 2): 56 return kf(x = 2) * r3 57def k(q = 29, n = 4): 58 return kf(x = 1) * r2 59def k(q = 30, n = 2): 60 return kf(x = 3) * r4 61def k(q = 37, n = 0): 62 return kf(x = 2) * r3 63def k(q = 39, n = 4): 64 return kf(x = 3) * r4 65def k(q = 53, n = 2): 66 return kf(x = 1) * r2 67def k(q = 57, n = 0): 68 return kf(x = 3) * r4 69q = 0 70while q <= 63: 71 k0(q) = 0 72 i = 0 73 while i <= 5: 74 k0(q) = k0(q) + k(q, i) 75 i += 1 76 q += 1 77q = 0 78while q <= 63: 79 c(q, i = 0) =k(q, i = 0) / k0(q) 80 i = 0 81 while i <= 5: 82 c(q, i) = c(q, i - 1) + k(q, i) / k0(q) 83 i += 1 84 q += 1 85q = 0 86sigma1_c = 0 87sigma2_c = 0 88sigma3_c = 0 89sigma1 = sigma_1(q) 90sigma2 = sigma_2(q, sigma1) 91sigma3 = sigma_3(q, sigma1, sigma2) 92j = 1 93import random 94while j <= 100: 95 tau = 1 / k0(q) 96 x = random.random() 97 dt = - tau * log(x) 98 t = t + dt 99 y = random.random() 100 if y < c(q, n = 0): 101 sigma1 = sigma1 + 1 102 sigma1_c = sigma1_c + 1 103 if (sigma1 > 3): 104 sigma1 = 0 105 elif y < c(q, n = 1): 106 sigma1 = sigma1 - 1 107 sigma1_c = sigma1_c - 1 108 if sigma1 < 0: 109 sigma1 = 3 110 if y < c(q, n = 2): 111 sigma2 = sigma2 + 1 112 sigma2_c = sigma2_c + 1 113 if (sigma2 > 3): 114 sigma2 = 0 115 elif y < c(q, n = 3): 116 sigma2 = sigma2 - 1 117 sigma2_c = sigma2_c - 1 118 if sigma2 < 0: 119 sigma2 = 3 120 if y < c(q, n = 4): 121 sigma3 = sigma3 + 1 122 sigma3_c = sigma3_c + 1 123 if (sigma3 > 3): 124 sigma3 = 0 125 elif y < c(q, n = 5): 126 sigma3 = sigma3 - 1 127 sigma3_c = sigma3_c - 1 128 if sigma3 < 0: 129 sigma3 = 3 130 q = q64(sigma1, sigma2, sigma3) 131print (t, sigma1_c, sigma2_c, sigma3_c, q)
試したこと
関数に書き換えた。
補足情報(FW/ツールのバージョンなど)
回答2件
あなたの回答
tips
プレビュー