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

質問編集履歴

4

コードの修正

2018/11/26 04:28

投稿

YYY9856
YYY9856

スコア13

title CHANGED
File without changes
body CHANGED
@@ -15,73 +15,84 @@
15
15
 
16
16
  エラーメッセージ
17
17
 
18
+ 0.01
18
19
  ---- iteration : 1 ----
20
+ [ 0. 0.01036504 0.03471855 0.07291493 0.12484478 0.19036281
21
+ 0.26928628 0.36139515 0.46643267 0.58410607 0.71408738 0.8560143
22
+ 1.00949126 1.17409048 1.34935321 1.53479094 1.72988684 1.93409712
23
+ 2.14685263 2.36756038 2.5956052 2.83035151 3.07114501 3.31731459
24
+ 3.5681741 3.82302438 4.08115509 4.34184679 4.60437288 4.86800166
25
+ 5.13199834 5.39562712 5.65815321 5.91884491 6.17697562 6.4318259
26
+ 6.68268541 6.92885499 7.16964849 7.4043948 7.63243962 7.85314737
27
+ 8.06590288 8.27011316 8.46520906 8.65064679 8.82590952 8.99050874
28
+ 9.1439857 9.28591262 9.41589393 9.53356733 9.63860485 9.73071372
29
+ 9.80963719 9.87515522 9.92708507 9.96528145 9.98963496 10. ]
30
+ <class 'numpy.ndarray'>
19
31
  Traceback (most recent call last):
20
- File "10_Low_Thrust_Orbit_Transfer16.py", line 259, in <module>
32
+ File "Low_Thrust_Orbit_Transfer17.py", line 222, in <module>
21
33
  prob.solve(obj, display_func, ftol=1e-12)
22
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 683, in solve
34
+ File "C:\Users\yokotalab\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 683, in solve
23
35
  "ftol": ftol})
24
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\_minimize.py", line 611, in minimize
36
+ File "C:\Users\yokotalab\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\_minimize.py", line 611, in minimize
25
37
  constraints, callback=callback, **options)
26
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\slsqp.py", line 313, in _minimize_slsqp
38
+ File "C:\Users\yokotalab\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\slsqp.py", line 313, in _minimize_slsqp
27
39
  for c in cons['eq']]))
28
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\slsqp.py", line 313, in <listcomp>
40
+ File "C:\Users\yokotalab\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\slsqp.py", line 313, in <listcomp>
29
41
  for c in cons['eq']]))
30
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 649, in for_solver
42
+ File "C:\Users\yokotalab\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 649, in for_solver
31
43
  return func(arg0, arg1)
32
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 620, in equality_add
44
+ File "C:\Users\yokotalab\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 620, in equality_add
33
45
  dx = self.dynamics[i](self, obj, i)
34
- File "10_Low_Thrust_Orbit_Transfer16.py", line 68, in dynamics
46
+ File "Low_Thrust_Orbit_Transfer17.py", line 56, in dynamics
35
47
  s = optimize.fsolve(h,0)
36
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\minpack.py", line 148, in fsolve
48
+ File "C:\Users\yokotalab\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\minpack.py", line 148, in fsolve
37
49
  res = _root_hybr(func, x0, args, jac=fprime, **options)
38
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\minpack.py", line 214, in _root_hybr
50
+ File "C:\Users\yokotalab\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\minpack.py", line 227, in _root_hybr
39
- shape, dtype = _check_func('fsolve', 'func', func, x0, args, n, (n,))
40
- File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\minpack.py", line 27, in _check_func
41
- res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
42
- File "10_Low_Thrust_Orbit_Transfer16.py", line 65, in h
43
- return f(E)-g(E)
44
- File "10_Low_Thrust_Orbit_Transfer16.py", line 63, in g
45
- return np.sqrt(obj.R**3/a**3)* t
51
+ ml, mu, epsfcn, factor, diag)
46
- AttributeError: 'float' object has no attribute 'sqrt'
52
+ ValueError: The array returned by a function changed size between calls
47
53
 
48
- ### 該当のソースコード
49
54
 
50
- python
51
-
52
- from __future__ import print_function
53
- import numpy as np
54
- import matplotlib.pyplot as plt
55
- from OpenGoddard.optimize import Problem, Guess, Condition, Dynamics
56
-
57
-
58
55
  class Orbiter:
59
56
  def __init__(self):
60
- self.u_max = 0.01
57
+
61
- self.r0 = 1.0
58
+ self.a0 = 1.0
62
59
  self.vr0 = 0.0
63
60
  self.vt0 = 1.0
64
- self.rf = 4.0
61
+ self.af = 4.0
65
62
  self.vrf = 0.0
66
63
  self.vtf = 0.5
64
+ self.e_0 = 0.7
65
+ self.ef = 0.0
67
- self.tf_max = 55
66
+ self.tf_max = 1000
67
+ self.mu = 3.98e14
68
+ self.R = 6678000
69
+ self.u_max = 0.01
70
+ print(self.u_max)
68
71
 
69
72
 
70
73
  def dynamics(prob, obj, section):
74
+
71
- r = prob.states(0, section)
75
+ a = prob.states(0, section)
72
76
  vr = prob.states(1, section)
73
77
  vt = prob.states(2, section)
78
+ beta = prob.states(3, section)
79
+ e = prob.states(4, section)
74
80
  ur1 = prob.controls(0, section)
75
81
  ur2 = prob.controls(1, section)
76
82
  ut1 = prob.controls(2, section)
77
83
  ut2 = prob.controls(3, section)
78
84
 
79
- t = prob.time_knots()#ここから
80
85
 
86
+
87
+ t = prob.time_update()#ここから
88
+
89
+ print(t)
90
+ print(type(t))
91
+
81
92
  def f(E):
82
93
  return E - np.cos(E)
83
94
  def g(E):
84
- return np.sqrt(obj.R**3/a**3)* t
95
+ return np.sqrt(obj.mu/obj.R**3)* t
85
96
  def h(E):
86
97
  return f(E)-g(E)
87
98
 
@@ -91,50 +102,58 @@
91
102
 
92
103
  r = a * (1 -e * np.cos(s))#ここまで
93
104
 
94
- dx = Dynamics(prob, section)
95
105
  dx[0] = vr
96
- dx[1] = vt**2 / r - 1 / r**2 + (ur1 - ur2)
106
+ dx[1] = vt**2 / r - 1 / r**2 + (ur1 - ur2) -(ui1 - ui2) / np.cos(beta) * np.sin(beta)
97
107
  dx[2] = - vr * vt / r + (ut1 - ut2)
108
+
98
109
  return dx()
99
110
 
100
111
 
101
112
  def equality(prob, obj):
102
- r = prob.states_all_section(0)
113
+ a = prob.states_all_section(0)
103
114
  vr = prob.states_all_section(1)
104
115
  vt = prob.states_all_section(2)
116
+ e = prob.states_all_section(3)
105
117
  ur1 = prob.controls_all_section(0)
106
118
  ur2 = prob.controls_all_section(1)
107
119
  ut1 = prob.controls_all_section(2)
108
120
  ut2 = prob.controls_all_section(3)
121
+
109
122
  tf = prob.time_final(-1)
110
123
 
111
124
  result = Condition()
112
125
 
113
126
  # event condition
114
- result.equal(r[0], obj.r0)
127
+ result.equal(a[0], obj.a0)
115
128
  result.equal(vr[0], obj.vr0)
116
129
  result.equal(vt[0], obj.vt0)
130
+ result.equal(e[0], obj.e_0)
117
- result.equal(r[-1], obj.rf)
131
+ result.equal(a[-1], obj.af)
118
132
  result.equal(vr[-1], obj.vrf)
119
133
  result.equal(vt[-1], obj.vtf)
134
+ result.equal(e[-1], obj.ef)
120
135
 
136
+
121
137
  return result()
122
138
 
123
139
 
124
140
  def inequality(prob, obj):
125
- r = prob.states_all_section(0)
141
+ a = prob.states_all_section(0)
126
142
  vr = prob.states_all_section(1)
127
143
  vt = prob.states_all_section(2)
144
+ e = prob.states_all_section(3)
128
145
  ur1 = prob.controls_all_section(0)
129
146
  ur2 = prob.controls_all_section(1)
130
147
  ut1 = prob.controls_all_section(2)
131
148
  ut2 = prob.controls_all_section(3)
149
+
132
150
  tf = prob.time_final(-1)
133
151
 
134
152
  result = Condition()
135
153
 
136
154
  # lower bounds
137
- result.lower_bound(r, obj.r0)
155
+ result.lower_bound(a, obj.a0)
156
+ result.lower_bound(e, 0.0)
138
157
  result.lower_bound(ur1, 0.0)
139
158
  result.lower_bound(ut1, 0.0)
140
159
  result.lower_bound(ur2, 0.0)
@@ -142,11 +161,15 @@
142
161
  result.lower_bound(tf, 0.0)
143
162
 
144
163
  # upper bounds
145
- result.upper_bound(r, obj.rf)
164
+ result.upper_bound(a, obj.af)
165
+ result.upper_bound(e, obj.e_0)
146
166
  result.upper_bound(ur1, obj.u_max)
147
167
  result.upper_bound(ut1, obj.u_max)
148
168
  result.upper_bound(ur2, obj.u_max)
149
169
  result.upper_bound(ut2, obj.u_max)
170
+
171
+
172
+
150
173
  result.upper_bound(tf, obj.tf_max)
151
174
 
152
175
  return result()
@@ -156,7 +179,6 @@
156
179
  return 0.0
157
180
 
158
181
 
159
-
160
182
  def running_cost(prob, obj):
161
183
 
162
184
  tf = prob.time_final(-1)
@@ -164,15 +186,16 @@
164
186
  return tf
165
187
 
166
188
 
189
+
167
190
  # ========================
168
191
  plt.close("all")
169
192
  plt.ion()
170
193
  # Program Starting Point
171
194
  time_init = [0.0, 10]
172
195
  n = [60]
173
- num_states = [3]
196
+ num_states = [5]
174
197
  num_controls = [4]
175
- max_iteration = 10
198
+ max_iteration = 8
176
199
 
177
200
  flag_savefig = True
178
201
 
@@ -185,7 +208,7 @@
185
208
 
186
209
  # ========================
187
210
  # Initial parameter guess
188
- r_init = Guess.linear(prob.time_all_section, obj.r0, obj.rf)
211
+ a_init = Guess.linear(prob.time_all_section, obj.a0, obj.af)
189
212
  # Guess.plot(prob.time_all_section, r_init, "r", "time", "r")
190
213
  # if(flag_savefig):plt.savefig(savefig_dir + "guess_r" + savefig_add + ".png")
191
214
 
@@ -197,6 +220,7 @@
197
220
  # Guess.plot(prob.time_all_section, theta_init, "vt", "time", "vt")
198
221
  # if(flag_savefig):plt.savefig(savefig_dir + "guess_vt" + savefig_add + ".png")
199
222
 
223
+
200
224
  ur1_init = Guess.linear(prob.time_all_section, obj.u_max, obj.u_max)
201
225
  # Guess.plot(prob.time_all_section, ur1_init, "ur1", "time", "ur1")
202
226
  # if(flag_savefig):plt.savefig(savefig_dir + "guess_ur1" + savefig_add + ".png")
@@ -205,9 +229,20 @@
205
229
  # Guess.plot(prob.time_all_section, ut1_init, "ut1", "time", "ut1")
206
230
  # if(flag_savefig):plt.savefig(savefig_dir + "guess_ut1" + savefig_add + ".png")
207
231
 
232
+
233
+ e_init = Guess.linear(prob.time_all_section, obj.e_0, obj.ef)
234
+
235
+
236
+
237
+
238
+
208
- prob.set_states_all_section(0, r_init)
239
+ prob.set_states_all_section(0, a_init)
209
240
  prob.set_states_all_section(1, vr_init)
210
241
  prob.set_states_all_section(2, vt_init)
242
+ prob.set_states_all_section(3, e_init)
243
+
244
+
245
+
211
246
  prob.set_controls_all_section(0, ur1_init)
212
247
  prob.set_controls_all_section(2, ut1_init)
213
248
 
@@ -234,11 +269,41 @@
234
269
  # Post Process
235
270
  # ------------------------
236
271
  # Convert parameter vector to variable
237
- r = prob.states_all_section(0)
272
+ a = prob.states_all_section(0)
238
273
  vr = prob.states_all_section(1)
239
274
  vt = prob.states_all_section(2)
275
+ beta = prob.states_all_section(3)
276
+ e = prob.states_all_section(4)
277
+
278
+
279
+
240
280
  ur1 = prob.controls_all_section(0)
241
281
  ur2 = prob.controls_all_section(1)
242
282
  ut1 = prob.controls_all_section(2)
243
283
  ut2 = prob.controls_all_section(3)
284
+
244
- time = prob.time_update()
285
+ time = prob.time_update()
286
+
287
+ def f(E):
288
+ return E - np.cos(E)
289
+ def g(E):
290
+ return np.sqrt(obj.mu/obj.R**3)* time
291
+ def h(E):
292
+ return f(E)-g(E)
293
+
294
+
295
+ s = optimize.fsolve(h,0)
296
+ print(s)
297
+ r = a * (1 -e * np.cos(s))
298
+
299
+
300
+ aa= sum(np.abs(ut1)+np.abs(ut2))
301
+ b= sum(np.abs(ur1)+np.abs(ur2))
302
+ c= sum(np.abs(ui1)+np.abs(ui2))
303
+
304
+ print(aa*0.001*obj.mu / obj.R**2)
305
+ print((b+c)*0.001*obj.mu / obj.R**2)
306
+
307
+
308
+
309
+ plt.show()

3

ソースの追加

2018/11/26 04:28

投稿

YYY9856
YYY9856

スコア13

title CHANGED
File without changes
body CHANGED
@@ -6,9 +6,13 @@
6
6
 
7
7
  ### 発生している問題・エラーメッセージ
8
8
  エラーメッセージの読み方が分かりません。
9
- つまりどのファイルのどの行に何が起こっていると言われているのか
9
+ つまりどのファイルのどの行に何が起こっていると言われているのか
10
10
  教えていただきたいです。
11
11
 
12
+ ソースコードが長いですが、コード内の#ここから #ここまでを追加するとこのエラーが出るようになりました。
13
+ OpenGoddard.optimizeは以下のコードです。
14
+ https://github.com/istellartech/OpenGoddard/blob/master/OpenGoddard/optimize.py
15
+
12
16
  エラーメッセージ
13
17
 
14
18
  ---- iteration : 1 ----
@@ -43,4 +47,198 @@
43
47
 
44
48
  ### 該当のソースコード
45
49
 
46
- python
50
+ python
51
+
52
+ from __future__ import print_function
53
+ import numpy as np
54
+ import matplotlib.pyplot as plt
55
+ from OpenGoddard.optimize import Problem, Guess, Condition, Dynamics
56
+
57
+
58
+ class Orbiter:
59
+ def __init__(self):
60
+ self.u_max = 0.01
61
+ self.r0 = 1.0
62
+ self.vr0 = 0.0
63
+ self.vt0 = 1.0
64
+ self.rf = 4.0
65
+ self.vrf = 0.0
66
+ self.vtf = 0.5
67
+ self.tf_max = 55
68
+
69
+
70
+ def dynamics(prob, obj, section):
71
+ r = prob.states(0, section)
72
+ vr = prob.states(1, section)
73
+ vt = prob.states(2, section)
74
+ ur1 = prob.controls(0, section)
75
+ ur2 = prob.controls(1, section)
76
+ ut1 = prob.controls(2, section)
77
+ ut2 = prob.controls(3, section)
78
+
79
+ t = prob.time_knots()#ここから
80
+
81
+ def f(E):
82
+ return E - np.cos(E)
83
+ def g(E):
84
+ return np.sqrt(obj.R**3/a**3)* t
85
+ def h(E):
86
+ return f(E)-g(E)
87
+
88
+
89
+ s = optimize.fsolve(h,0)
90
+
91
+
92
+ r = a * (1 -e * np.cos(s))#ここまで
93
+
94
+ dx = Dynamics(prob, section)
95
+ dx[0] = vr
96
+ dx[1] = vt**2 / r - 1 / r**2 + (ur1 - ur2)
97
+ dx[2] = - vr * vt / r + (ut1 - ut2)
98
+ return dx()
99
+
100
+
101
+ def equality(prob, obj):
102
+ r = prob.states_all_section(0)
103
+ vr = prob.states_all_section(1)
104
+ vt = prob.states_all_section(2)
105
+ ur1 = prob.controls_all_section(0)
106
+ ur2 = prob.controls_all_section(1)
107
+ ut1 = prob.controls_all_section(2)
108
+ ut2 = prob.controls_all_section(3)
109
+ tf = prob.time_final(-1)
110
+
111
+ result = Condition()
112
+
113
+ # event condition
114
+ result.equal(r[0], obj.r0)
115
+ result.equal(vr[0], obj.vr0)
116
+ result.equal(vt[0], obj.vt0)
117
+ result.equal(r[-1], obj.rf)
118
+ result.equal(vr[-1], obj.vrf)
119
+ result.equal(vt[-1], obj.vtf)
120
+
121
+ return result()
122
+
123
+
124
+ def inequality(prob, obj):
125
+ r = prob.states_all_section(0)
126
+ vr = prob.states_all_section(1)
127
+ vt = prob.states_all_section(2)
128
+ ur1 = prob.controls_all_section(0)
129
+ ur2 = prob.controls_all_section(1)
130
+ ut1 = prob.controls_all_section(2)
131
+ ut2 = prob.controls_all_section(3)
132
+ tf = prob.time_final(-1)
133
+
134
+ result = Condition()
135
+
136
+ # lower bounds
137
+ result.lower_bound(r, obj.r0)
138
+ result.lower_bound(ur1, 0.0)
139
+ result.lower_bound(ut1, 0.0)
140
+ result.lower_bound(ur2, 0.0)
141
+ result.lower_bound(ut2, 0.0)
142
+ result.lower_bound(tf, 0.0)
143
+
144
+ # upper bounds
145
+ result.upper_bound(r, obj.rf)
146
+ result.upper_bound(ur1, obj.u_max)
147
+ result.upper_bound(ut1, obj.u_max)
148
+ result.upper_bound(ur2, obj.u_max)
149
+ result.upper_bound(ut2, obj.u_max)
150
+ result.upper_bound(tf, obj.tf_max)
151
+
152
+ return result()
153
+
154
+
155
+ def cost(prob, obj):
156
+ return 0.0
157
+
158
+
159
+
160
+ def running_cost(prob, obj):
161
+
162
+ tf = prob.time_final(-1)
163
+
164
+ return tf
165
+
166
+
167
+ # ========================
168
+ plt.close("all")
169
+ plt.ion()
170
+ # Program Starting Point
171
+ time_init = [0.0, 10]
172
+ n = [60]
173
+ num_states = [3]
174
+ num_controls = [4]
175
+ max_iteration = 10
176
+
177
+ flag_savefig = True
178
+
179
+ savefig_dir = "10_Low_Thrust_Orbit_Transfer/"
180
+
181
+ # ------------------------
182
+ # set OpenGoddard class for algorithm determination
183
+ prob = Problem(time_init, n, num_states, num_controls, max_iteration)
184
+ obj = Orbiter()
185
+
186
+ # ========================
187
+ # Initial parameter guess
188
+ r_init = Guess.linear(prob.time_all_section, obj.r0, obj.rf)
189
+ # Guess.plot(prob.time_all_section, r_init, "r", "time", "r")
190
+ # if(flag_savefig):plt.savefig(savefig_dir + "guess_r" + savefig_add + ".png")
191
+
192
+ vr_init = Guess.linear(prob.time_all_section, obj.vr0, obj.vrf)
193
+ # Guess.plot(prob.time_all_section, vr_init, "vr", "time", "vr")
194
+ # if(flag_savefig):plt.savefig(savefig_dir + "guess_vr" + savefig_add + ".png")
195
+
196
+ vt_init = Guess.linear(prob.time_all_section, obj.vt0, obj.vtf)
197
+ # Guess.plot(prob.time_all_section, theta_init, "vt", "time", "vt")
198
+ # if(flag_savefig):plt.savefig(savefig_dir + "guess_vt" + savefig_add + ".png")
199
+
200
+ ur1_init = Guess.linear(prob.time_all_section, obj.u_max, obj.u_max)
201
+ # Guess.plot(prob.time_all_section, ur1_init, "ur1", "time", "ur1")
202
+ # if(flag_savefig):plt.savefig(savefig_dir + "guess_ur1" + savefig_add + ".png")
203
+
204
+ ut1_init = Guess.linear(prob.time_all_section, obj.u_max, obj.u_max)
205
+ # Guess.plot(prob.time_all_section, ut1_init, "ut1", "time", "ut1")
206
+ # if(flag_savefig):plt.savefig(savefig_dir + "guess_ut1" + savefig_add + ".png")
207
+
208
+ prob.set_states_all_section(0, r_init)
209
+ prob.set_states_all_section(1, vr_init)
210
+ prob.set_states_all_section(2, vt_init)
211
+ prob.set_controls_all_section(0, ur1_init)
212
+ prob.set_controls_all_section(2, ut1_init)
213
+
214
+
215
+ # ========================
216
+ # Main Process
217
+ # Assign problem to SQP solver
218
+ prob.dynamics = [dynamics]
219
+ prob.knot_states_smooth = []
220
+ prob.cost = cost
221
+ prob.running_cost = running_cost
222
+ prob.equality = equality
223
+ prob.inequality = inequality
224
+
225
+
226
+ def display_func():
227
+ tf = prob.time_final(-1)
228
+ print("tf: {0:.5f}".format(tf))
229
+
230
+
231
+ prob.solve(obj, display_func, ftol=1e-12)
232
+
233
+ # ========================
234
+ # Post Process
235
+ # ------------------------
236
+ # Convert parameter vector to variable
237
+ r = prob.states_all_section(0)
238
+ vr = prob.states_all_section(1)
239
+ vt = prob.states_all_section(2)
240
+ ur1 = prob.controls_all_section(0)
241
+ ur2 = prob.controls_all_section(1)
242
+ ut1 = prob.controls_all_section(2)
243
+ ut2 = prob.controls_all_section(3)
244
+ time = prob.time_update()

2

説明文の変更

2018/11/22 07:44

投稿

YYY9856
YYY9856

スコア13

title CHANGED
@@ -1,1 +1,1 @@
1
- pythonを使った最適化計算のエラーについて
1
+ pythonのエラーコードの読み方について
body CHANGED
@@ -3,46 +3,44 @@
3
3
  ここに質問の内容を詳しく書いてください。
4
4
  pythonで最適化システムを作っています。
5
5
  超越方程式の解を変数で出し(一般解)、他の式の変数に入れる機能を実装中に以下のエラーメッセージが発生しました。
6
- aとeとtは定数です。
7
6
 
8
7
  ### 発生している問題・エラーメッセージ
9
- エラーの解決かりません。
8
+ エラーメッセージ読み方がかりません。
9
+ つまりどのファイルのどの行に何が起こっていると言われているのかを
10
+ 教えていただきたいです。
10
11
 
11
12
  エラーメッセージ
12
13
 
14
+ ---- iteration : 1 ----
15
+ Traceback (most recent call last):
16
+ File "10_Low_Thrust_Orbit_Transfer16.py", line 259, in <module>
17
+ prob.solve(obj, display_func, ftol=1e-12)
18
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 683, in solve
19
+ "ftol": ftol})
20
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\_minimize.py", line 611, in minimize
21
+ constraints, callback=callback, **options)
22
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\slsqp.py", line 313, in _minimize_slsqp
23
+ for c in cons['eq']]))
24
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\slsqp.py", line 313, in <listcomp>
25
+ for c in cons['eq']]))
26
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 649, in for_solver
27
+ return func(arg0, arg1)
28
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenGoddard\optimize.py", line 620, in equality_add
29
+ dx = self.dynamics[i](self, obj, i)
13
- ValueError: The array returned by a function changed size between calls
30
+ File "10_Low_Thrust_Orbit_Transfer16.py", line 68, in dynamics
31
+ s = optimize.fsolve(h,0)
32
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\minpack.py", line 148, in fsolve
33
+ res = _root_hybr(func, x0, args, jac=fprime, **options)
34
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\minpack.py", line 214, in _root_hybr
35
+ shape, dtype = _check_func('fsolve', 'func', func, x0, args, n, (n,))
36
+ File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\optimize\minpack.py", line 27, in _check_func
37
+ res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
38
+ File "10_Low_Thrust_Orbit_Transfer16.py", line 65, in h
39
+ return f(E)-g(E)
40
+ File "10_Low_Thrust_Orbit_Transfer16.py", line 63, in g
41
+ return np.sqrt(obj.R**3/a**3)* t
42
+ AttributeError: 'float' object has no attribute 'sqrt'
14
43
 
15
44
  ### 該当のソースコード
16
45
 
17
- python
46
+ python
18
-
19
- ソースコード
20
-
21
- a = prob.states(0, section)
22
- e = prob.states(4, section)
23
-
24
- t = prob.time_update()
25
-
26
- def f(E):
27
- return E - np.sin(E)
28
- def g(E):
29
- return t
30
- def h(E):
31
- return f(E)-g(E)
32
-
33
-
34
- s = optimize.fsolve(h,0)
35
-
36
-
37
- r = a * (1 -e * np.cos(s))
38
-
39
- ### 試したこと
40
-
41
- ここに問題に対して試したことを記載してください。
42
-
43
- ### 補足情報(FW/ツールのバージョンなど)
44
-
45
- ここにより詳細な情報を記載してください。
46
- 下記のHPのコードを修正しようとしています。
47
- 質問自体がわかりづらいかもしれませんがどうぞよろしくお願いします。
48
- https://qiita.com/ina111/items/60f75d90e5376d34a0ef

1

誤記

2018/11/22 06:50

投稿

YYY9856
YYY9856

スコア13

title CHANGED
File without changes
body CHANGED
@@ -9,9 +9,9 @@
9
9
  エラーの解決方法がわかりません。
10
10
 
11
11
  エラーメッセージ
12
- return np.sqrt(obj.mu / obj.R**3) * t
13
- TypeError: 'numpy.float64' object cannot be interpreted as an integer
14
12
 
13
+ ValueError: The array returned by a function changed size between calls
14
+
15
15
  ### 該当のソースコード
16
16
 
17
17
  python