我正在将手推车和杆子仿真与python 3.7和Julia 1.2进行比较。在python中,仿真被编写为类对象,如下所示,而在Julia中,它只是一个函数。我得到一致的0.2秒时间来解决使用Julia的问题,这比python慢得多。我对朱莉娅的理解不够深刻,无法理解为什么。我的猜测是它与编译或建立循环的方式有关。
import math
import random
from collections import namedtuple
RAD_PER_DEG = 0.0174533
DEG_PER_RAD = 57.2958
State = namedtuple('State', 'x x_dot theta theta_dot')
class CartPole:
""" Model for the dynamics of an inverted pendulum
"""
def __init__(self):
self.gravity = 9.8
self.masscart = 1.0
self.masspole = 0.1
self.length = 0.5 # actually half the pole's length
self.force_mag = 10.0
self.tau = 0.02 # seconds between state updates
self.x = 0
self.x_dot = 0
self.theta = 0
self.theta_dot = 0
@property …Run Code Online (Sandbox Code Playgroud)