We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2ddc9ea commit d4a8a59Copy full SHA for d4a8a59
control/optimal.py
@@ -319,11 +319,9 @@ def _cost_function(self, coeffs):
319
dt = np.diff(self.timepts)
320
321
# Integrate the cost
322
- # TODO: vectorize
323
- cost = 0
324
- for i in range(self.timepts.size-1):
325
- # Approximate the integral using trapezoidal rule
326
- cost += 0.5 * (costs[i] + costs[i+1]) * dt[i]
+ costs = np.array(costs)
+ # Approximate the integral using trapezoidal rule
+ cost = np.sum(0.5 * (costs[:-1] + costs[1:]) * dt)
327
328
else:
329
# Sum the integral cost over the time (second) indices
0 commit comments