
def simulate(D, s0, sigma_p, T):
  """ Compute the response of the linear dynamical system.

  Args:
    D (scalar): dynamics multiplier
    s0 (scalar): initial postion
    sigma_p (scalar): amount of noise in the system (standard deviation)
    T (scalar): total duration of the simulation

  Returns:
    ndarray: `s`: astrocat's trajectory up to time T
  """

  # Initialize variables
  s = np.zeros(T+1)
  s[0] = s0

  # Compute the position at time t given the position at time t-1 for all t
  # Consider that np.random.normal(mu, sigma) generates a random sample from
  # a gaussian with mean = mu and standard deviation = sigma

  for t in range(1, len(s)):

    # Update position
    s[t] = D*s[t-1] + np.random.normal(0, sigma_p)

  return s


# Set random seed
np.random.seed(0)

# Set parameters
D = 0.9    # parameter in s(t)
T = 50      # total time duration
s0 = 5.     # initial condition of s at time 0
sigma_p = 2 # amount of noise in the actuators of astrocat's propulsion unit

# Simulate Astrocat
s = simulate(D, s0, sigma_p, T)

# Visualize
with plt.xkcd():
  visualize_Astrocat(s, T)

def simulate(D, s0, sigma_p, T):
  """ Compute the response of the linear dynamical system.

  Args:
    D (scalar): dynamics multiplier
    s0 (scalar): initial postion
    sigma_p (scalar): amount of noise in the system (standard deviation)
    T (scalar): total duration of the simulation

  Returns:
    ndarray: `s`: astrocat's trajectory up to time T
  """

  # Initialize variables
  s = np.zeros(T+1)
  s[0] = s0

  # Compute the position at time t given the position at time t-1 for all t
  # Consider that np.random.normal(mu, sigma) generates a random sample from
  # a gaussian with mean = mu and standard deviation = sigma

  for t in range(1, len(s)):

    # Update position
    s[t] = D*s[t-1] + np.random.normal(0, sigma_p)

  return s


# Set random seed
np.random.seed(0)

# Set parameters
D = 0.9    # parameter in s(t)
T = 50      # total time duration
s0 = 5.     # initial condition of s at time 0
sigma_p = 2 # amount of noise in the actuators of astrocat's propulsion unit

# Simulate Astrocat
s = simulate(D, s0, sigma_p, T)

# Visualize
with plt.xkcd():
  visualize_Astrocat(s, T)
Compute the response of the linear dynamical system.    Args:     D (scalar): dynamics multiplier     s0 (scalar): initial postion     sigma_p (scalar): amount of noise in the system (standard deviation)     T (scalar): total duration of the simulation    Returns:     ndarray: `s`: astrocat's trajectory up to time T # Initialize variables # Compute the position at time t given the position at time t-1 for all t # Consider that np.random.normal(mu, sigma) generates a random sample from # a gaussian with mean = mu and standard deviation = sigma # Update position # Set random seed # Set parameters # parameter in s(t) # total time duration # initial condition of s at time 0 # amount of noise in the actuators of astrocat's propulsion unit # Simulate Astrocat # Visualize