質問編集履歴

2

誤字

2019/10/09 23:54

投稿

NR4200
NR4200

スコア41

test CHANGED
File without changes
test CHANGED
@@ -16,42 +16,52 @@
16
16
 
17
17
  ```
18
18
 
19
- C:\Users\□□□□\Desktop\〇〇>python mass-spring-FTSM.py
20
-
21
- mass-spring-FTSM.py:51: RuntimeWarning: invalid value encountered in double_scalars
22
-
23
- nextu = (m/k*c2)*((c1*((-(k/m)*x1-μ(x2)*g*np.sign(x2))+0.02*np.sin(t)-(k/m)*u))+c2*((-(k/m)*x2(x2)*g*np.sign(u))+0.02*np.cos(t))+κ*np.sign(σ(x1,x2,u,t))*abs(σ(x1,x2,u,t))**η+ɤ*σ(x1,x2,u,t)+χ*np.sign(σ(x1,x2,u,t))+(c1*(x2-0.02*np.cos(t))+c2*(-(k/m)*x1-μ(x2)*g*np.sign(x2)+0.02*np.sin(t)-(k/m)*u))*(λ+μ(x2)*η*(c1*(x1-0.02*np.sin(t))+c2*(x2-0.02*np.cos(t)))**(η-1)))
19
+ PS C:\Users\□□□□\Desktop\○○○○> python mass-spring-FTSM.py
20
+
21
+ mass-spring-FTSM.py:62: RuntimeWarning: invalid value encountered in double_scalars
22
+
23
+ nextu = (m/k*c2)*((c1*(f_x1x2(x1,x2))+0.02*np.sin(t)-(k/m)*u)+c2*(df_x1x2(x2,u)+0.02*np.cos(t))+κ*np.sign(σ(x1,x2,u,t))*abs(σ(x1,x2,u,t))**η+ɤ*σ(x1,x2,u,t)+χ*np.sign(σ(x1,x2,u,t))+(c1*(x2-0.02*np.cos(t))+c2*(f_x1x2(x
24
+
25
+ 1,x2)+0.02*np.cos(t)-(k/m)*u))*(λ+μ(x2)*η*s1(x1,x2,t)**(η-1)))
26
+
27
+ mass-spring-FTSM.py:54: RuntimeWarning: invalid value encountered in sign
28
+
29
+ return -(k/m)*x2-μ(x2)*g*np.sign(u)
30
+
31
+ mass-spring-FTSM.py:62: RuntimeWarning: invalid value encountered in sign
32
+
33
+ nextu = (m/k*c2)*((c1*(f_x1x2(x1,x2))+0.02*np.sin(t)-(k/m)*u)+c2*(df_x1x2(x2,u)+0.02*np.cos(t))+κ*np.sign(σ(x1,x2,u,t))*abs(σ(x1,x2,u,t))**η+ɤ*σ(x1,x2,u,t)+χ*np.sign(σ(x1,x2,u,t))+(c1*(x2-0.02*np.cos(t))+c2*(f_x1x2(x
34
+
35
+ 1,x2)+0.02*np.cos(t)-(k/m)*u))*(λ+μ(x2)*η*s1(x1,x2,t)**(η-1)))
36
+
37
+ mass-spring-FTSM.py:61: RuntimeWarning: invalid value encountered in sign
38
+
39
+ nextx2 = -(k/m)*x1 + d(t) - μ(x2)*g*np.sign(x2) - (k/m)*u
24
40
 
25
41
  mass-spring-FTSM.py:51: RuntimeWarning: invalid value encountered in sign
26
42
 
27
- nextu = (m/k*c2)*((c1*((-(k/m)*x1-μ(x2)*g*np.sign(x2))+0.02*np.sin(t)-(k/m)*u))+c2*((-(k/m)*x2-μ(x2)*g*np.sign(u))+0.02*np.cos(t))+κ*np.sign(σ(x1,x2,u,t))*abs(σ(x1,x2,u,t))**η+ɤ*σ(x1,x2,u,t)+χ*np.sign(σ(x1,x2,u,t))+(c1*(x2-0.02*np.cos(t))+c2*(-(k/m)*x1-μ(x2)*g*np.sign(x2)+0.02*np.sin(t)-(k/m)*u))*(λ+μ(x2)*η*(c1*(x1-0.02*np.sin(t))+c2*(x2-0.02*np.cos(t)))**(η-1)))
43
+ return -(k/m)*x1-μ(x2)*g*np.sign(x2)
28
44
 
29
45
  mass-spring-FTSM.py:48: RuntimeWarning: invalid value encountered in sign
30
46
 
31
- nextx2 = -(k/m)*x1 + d(t) - μ(x2)*g*np.sign(x2) - (k/m)*u
47
+ return c1*(x2-0.02*np.cos(t))+c2*(-(k/m)*x1+d(t)-μ(x2)*g*np.sign(x2)-(k/m)*u+0.02*np.cos(t))
32
-
33
- mass-spring-FTSM.py:42: RuntimeWarning: invalid value encountered in sign
34
-
35
- return c1*(x2-0.02*np.cos(t))+c2*(-(k/m)*x1+d(t)-μ(x2)*g*np.sign(x2)-(k/m)*u+0.02*np.cos(t))+λ*(c1*(x1-0.02*np.sin(t))+c2*(x2-0.02*np.cos(t)))+μ(x2)*(c1*(x1-0.02*np.sin(t))+c2*(x2-0.02*np.cos(t)))
36
48
 
37
49
  Traceback (most recent call last):
38
50
 
39
- File "mass-spring-FTSM.py", line 61, in <module>
51
+ File "mass-spring-FTSM.py", line 72, in <module>
40
52
 
41
53
  v = solve_ivp(vector_solove, t_span, [x1_f, x2_f, u_f ], method = 'RK45', t_eval = t)
42
54
 
43
- File "C:\Users\□□□□\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\integrate\_ivp\ivp.py", line 574, in solve_ivp
55
+ File "C:\Users\□□□□\AppData\Local\Programs\Python\Python37\lib\site-packages\scipy\integrate\_ivp\ivp.py", line 574, in solve_ivp
44
56
 
45
57
  ts = np.hstack(ts)
46
58
 
47
- File "C:\Users\□□□□\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\shape_base.py", line 340, in hstack
59
+ File "C:\Users\□□□□\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\shape_base.py", line 340, in hstack
48
60
 
49
61
  return _nx.concatenate(arrs, 1)
50
62
 
51
63
  ValueError: need at least one array to concatenate
52
64
 
53
-
54
-
55
65
  ```
56
66
 
57
67
 

1

プログラムが見にくかったのでまとめれるところは関数としてまとめました

2019/10/09 23:54

投稿

NR4200
NR4200

スコア41

test CHANGED
File without changes
test CHANGED
@@ -130,8 +130,6 @@
130
130
 
131
131
  def d(t):
132
132
 
133
-
134
-
135
133
  if t < 20:
136
134
 
137
135
  return 0
@@ -144,10 +142,38 @@
144
142
 
145
143
  def σ(x1,x2,u,t):
146
144
 
147
- return c1*(x2-0.02*np.cos(t))+c2*(-(k/m)*x1+d(t)-μ(x2)*g*np.sign(x2)-(k/m)*u+0.02*np.cos(t))+λ*(c1*(x1-0.02*np.sin(t))+c2*(x2-0.02*np.cos(t)))+μ(x2)*(c1*(x1-0.02*np.sin(t))+c2*(x2-0.02*np.cos(t)))
145
+ return s2(x1,x2,t,u)+λ*s1(x1,x2,t)+μ(x2)*s1(x1,x2,t)
148
146
 
149
147
  #return 1
150
148
 
149
+
150
+
151
+ def s1(x1,x2,t):
152
+
153
+ return c1*(x1-0.02*np.sin(t))+c2*(x2-0.02*np.cos(t))
154
+
155
+
156
+
157
+ def s2(x1, x2, t, u):
158
+
159
+ return c1*(x2-0.02*np.cos(t))+c2*(-(k/m)*x1+d(t)-μ(x2)*g*np.sign(x2)-(k/m)*u+0.02*np.cos(t))
160
+
161
+
162
+
163
+ def f_x1x2(x1,x2):
164
+
165
+ return -(k/m)*x1-μ(x2)*g*np.sign(x2)
166
+
167
+
168
+
169
+ def df_x1x2(x2, u):
170
+
171
+ return -(k/m)*x2-μ(x2)*g*np.sign(u)
172
+
173
+
174
+
175
+
176
+
151
177
  def vector_solove(t, state):
152
178
 
153
179
 
@@ -158,7 +184,7 @@
158
184
 
159
185
  nextx2 = -(k/m)*x1 + d(t) - μ(x2)*g*np.sign(x2) - (k/m)*u
160
186
 
161
- nextu = (m/k*c2)*((c1*((-(k/m)*x1-μ(x2)*g*np.sign(x2))+0.02*np.sin(t)-(k/m)*u))+c2*((-(k/m)*x2(x2)*g*np.sign(u))+0.02*np.cos(t))+κ*np.sign(σ(x1,x2,u,t))*abs(σ(x1,x2,u,t))**η+ɤ*σ(x1,x2,u,t)+χ*np.sign(σ(x1,x2,u,t))+(c1*(x2-0.02*np.cos(t))+c2*(-(k/m)*x1-μ(x2)*g*np.sign(x2)+0.02*np.sin(t)-(k/m)*u))*(λ+μ(x2)*η*(c1*(x1-0.02*np.sin(t))+c2*(x2-0.02*np.cos(t)))**(η-1)))
187
+ nextu = (m/k*c2)*((c1*(f_x1x2(x1,x2))+0.02*np.sin(t)-(k/m)*u)+c2*(df_x1x2(x2,u)+0.02*np.cos(t))+κ*np.sign(σ(x1,x2,u,t))*abs(σ(x1,x2,u,t))**η+ɤ*σ(x1,x2,u,t)+χ*np.sign(σ(x1,x2,u,t))+(c1*(x2-0.02*np.cos(t))+c2*(f_x1x2(x1,x2)+0.02*np.cos(t)-(k/m)*u))*(λ+μ(x2)*η*s1(x1,x2,t)**(η-1)))
162
188
 
163
189
 
164
190
 
@@ -182,6 +208,8 @@
182
208
 
183
209
 
184
210
 
211
+
212
+
185
213
  t_vec = v.t
186
214
 
187
215
  x1_vec = v.y[0,:]
@@ -252,6 +280,8 @@
252
280
 
253
281
 
254
282
 
283
+
284
+
255
285
  ```
256
286
 
257
287