Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions examples-gallery/beginner/plot_pendulum_swing_up_fixed_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
---------

- Show the use of opty with likely the simplest example possible.
- Show how to use adjustable bounds.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Show how to use adjustable bounds.
- Show how to use variable bounds.



Introduction
Expand Down Expand Up @@ -84,8 +85,16 @@
)

# %%
# Limit the torque to a maximum magnitude.
bounds = {T(t): (-2.0, 2.0)}
# Limit the torque using variable bounds.
third = int(num_nodes/3)
low_T = np.array([-3 for _ in range(third)] +
[-1 for _ in range(third)] +
[-3 for _ in range(num_nodes - 2 * third)])
hi_T = np.array([3 for _ in range(third)] +
[1 for _ in range(third)] +
[3 for _ in range(num_nodes - 2 * third)])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This are how to use NumPy to do such things:

hi = np.full(n, 3.0)
hi[100:200] = 1.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This are how to use NumPy to do such things:

hi = np.full(n, 3.0)
hi[100:200] = 1.0

Thanks!
My python is still very limited! :-((


bounds = {T(t): (low_T, hi_T)}

# %%
# Create an optimization problem.
Expand All @@ -111,7 +120,7 @@

# %%
# Plot the optimal state and input trajectories.
_ = prob.plot_trajectories(solution)
_ = prob.plot_trajectories(solution, show_bounds=True)

# %%
# Plot the constraint violations.
Expand Down
Loading