如何解决记忆误差并加快Sympy中的方法?
我正在按照稳定性,准确性和其他数值方法来控制runge -kutta方法,以防止过渡超越切换点。
当步骤很小(通过准确性或其他方法)时,整合持续时间很长,并且我遇到了内存错误,
line 712, in _getitem_RepMatrix
return self._rep.getitem_sympy(index_(i), index_(j))
TypeError: 'slice' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
line 157, in extract
row2[j2] = row1_j1
MemoryError
因此,当我需要大约1E-5或1E-6及以上的准确性时,会发生这种情况。
然后,方法是由方法构建的
def rkf2stepcontrol(
matrix_size,
dydx, A, x, b, dxdt, hn, t, tout, eps, predicate_func, MatrixForYacobian, hstabilitygetting, halgebraic):
k1 = zeros(matrix_size, 1)
k2 = zeros(matrix_size, 1)
k3 = zeros(matrix_size, 1)
k2k1norm = zeros(matrix_size, 1)
while ((predicate_func == False) or (tout - t > eps)):
print('Current time', t)
b = t
iterations += 1
print("I am in point ", x)
xprint_s = xprint_s.col_insert(1, Matrix([x]))
k1 = hn * dxdt(A, x, b)
print(k1, 'k1')
for i in (range(matrix_size)):
k2[i, 0] = hn * dxdt(A, x + k1[i, 0] * sympy.ones(*x.shape), b)[i, 0]
xold = x
for i in (range(matrix_size)):
x[i, 0] = x[i, 0] + 0.5 * (k1[i, 0] + k2[i, 0])
,通过精确求解方程式0.5” K1 -K2”≤EPS来控制步骤,其中K2和K1-方法步骤和EPS所需的精度。并通过获得最大值(ABS(Jacobian Matrix.EigenValues)来控制稳定性,
所有值将显示在图上,因此我必须包含它们。
I am doing Runge-Kutta method, with controlling step by stability, accuracy, and from other numerical method - to prevent transition beyond the switching point.
When the step is small(by accuracy or other method), integrating lasts long, and I got memory error, like this
line 712, in _getitem_RepMatrix
return self._rep.getitem_sympy(index_(i), index_(j))
TypeError: 'slice' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
line 157, in extract
row2[j2] = row1_j1
MemoryError
So, it happens, when I need accuracy about 1E-5 or 1E-6 and more.
The main built of method
def rkf2stepcontrol(
matrix_size,
dydx, A, x, b, dxdt, hn, t, tout, eps, predicate_func, MatrixForYacobian, hstabilitygetting, halgebraic):
k1 = zeros(matrix_size, 1)
k2 = zeros(matrix_size, 1)
k3 = zeros(matrix_size, 1)
k2k1norm = zeros(matrix_size, 1)
while ((predicate_func == False) or (tout - t > eps)):
print('Current time', t)
b = t
iterations += 1
print("I am in point ", x)
xprint_s = xprint_s.col_insert(1, Matrix([x]))
k1 = hn * dxdt(A, x, b)
print(k1, 'k1')
for i in (range(matrix_size)):
k2[i, 0] = hn * dxdt(A, x + k1[i, 0] * sympy.ones(*x.shape), b)[i, 0]
xold = x
for i in (range(matrix_size)):
x[i, 0] = x[i, 0] + 0.5 * (k1[i, 0] + k2[i, 0])
Then, controlling step by accuracy solving the equation 0.5‖k1-k2 ‖≤eps, where k2 and k1 - method steps and eps - needed accuracy. And controlling stability by getting max(abs(Jacobian Matrix.eigenvalues)
All the values will be shown on plot, so I must contain them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
切换到numpy会速度提高,但如果您使用大约1E-5或1E-6的精度,则仍然太长了。使用1E-4,整合2.37秒需要55分钟,因此大约一个小时才能制造2.5秒。而且,您只需要按照0.5“ K1-K2”≤EPS来重新计算精度。
代码重写为
...
并制作情节
Switching to numpy gives some speed up, but still too long, if you use accuracy about 1E-5 or 1E-6. With 1E-4, it takes 55 minutes to integrate 2.37 seconds, so about an hour to make 2.5 seconds. And, you need to recalculate accuracy only by condition 0.5‖k1-k2 ‖≤eps.
Code rewrited as
...
And to make the plot