From 2d06712d62934bb8afe74c37d4a4f76302dbeeba Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Sat, 22 Feb 2025 15:23:07 +0100 Subject: [PATCH 01/15] adjusted docstrings as per #348, reduced execution time --- .../beginner/plot_sliding_block.py | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index b9a9ded7..2774b8c1 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -3,6 +3,16 @@ Block Sliding Over a Hill ========================= +Objective +--------- + +- a simplex example to show how to use ``opty``s capability of variabel node + time interval vs. fixed time interval. + + +Introduction +------------ + A block, modeled as a particle is sliding on a road to cross a hill. The block is subject to gravity and speed dependent viscous friction. Gravity points in the negative Y direction. A force tangential to the road is applied to the @@ -13,6 +23,15 @@ - ``selection = 0``: time to reach the end point is minimized - ``selection = 1``: integral sum of the applied force is minimized + +Notes +----- + +The program was originally written to show both values of ``selection`` +In order to reduce running time only ``selection = 0`` is executed, the parts +for ``selection = 1`` are still in the code, but commented out. + + **Constants** - ``m``: mass of the block [kg] @@ -105,7 +124,9 @@ def strasse(x, a, b): # %% # Set up the optimization problems and solve them. -for selection in (0, 1): +# for selection in [0, 1]: +selection = 0 +if selection == 0: state_symbols = (speicher[0], speicher[1]) num_states = len(state_symbols) constant_symbols = (m, g, friction, a, b) @@ -273,41 +294,36 @@ def update(frame): print(f'Optimal h value is: {solution_list[selection][-1]:.3f}') # %% -prob_list[selection].plot_objective_value() +_ = prob_list[selection].plot_objective_value() # %% # Plot errors in the solution. -prob_list[selection].plot_constraint_violations(solution_list[selection]) +_ = prob_list[selection].plot_constraint_violations(solution_list[selection]) # %% # Plot the trajectories of the block. -prob_list[selection].plot_trajectories(solution_list[selection]) +_ = prob_list[selection].plot_trajectories(solution_list[selection]) # %% # Animate the solution. fig, ax = plt.subplots(figsize=(8, 8)) anim, _ = drucken(selection, fig, ax) -# %% # Now the results of **minimized energy** are shown. -selection = 1 -print('Message from optimizer:', info_list[selection]['status_msg']) +#selection = 1 +#print('Message from optimizer:', info_list[selection]['status_msg']) -# %% -prob_list[selection].plot_objective_value() +#_ = prob_list[selection].plot_objective_value() -# %% # Plot errors in the solution. -prob_list[selection].plot_constraint_violations(solution_list[selection]) +#_ = prob_list[selection].plot_constraint_violations(solution_list[selection]) -# %% # Plot the trajectories of the block. -prob_list[selection].plot_trajectories(solution_list[selection]) +#_ = prob_list[selection].plot_trajectories(solution_list[selection]) -# %% # Animate the solution. -fig, ax = plt.subplots(figsize=(8, 8)) -anim, _ = drucken(selection, fig, ax) +#fig, ax = plt.subplots(figsize=(8, 8)) +#anim, _ = drucken(selection, fig, ax) # %% # A frame from the animation. From 8eaf36a56d8a5f112141533736d0923494e22aad Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Sat, 22 Feb 2025 17:04:55 +0100 Subject: [PATCH 02/15] changed as per suggestions --- .../beginner/plot_sliding_block.py | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 2774b8c1..ececaa1d 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -6,7 +6,7 @@ Objective --------- -- a simplex example to show how to use ``opty``s capability of variabel node +- a simplex example to show how to use ``opty's`` capability of variabel node time interval vs. fixed time interval. @@ -28,8 +28,8 @@ ----- The program was originally written to show both values of ``selection`` -In order to reduce running time only ``selection = 0`` is executed, the parts -for ``selection = 1`` are still in the code, but commented out. +In order to reduce running time only ``selection = 0`` is executed, it is +explained how to run both versions. **Constants** @@ -124,7 +124,11 @@ def strasse(x, a, b): # %% # Set up the optimization problems and solve them. +# if you want to run both optimizations, replace the two lines below with this +# line: +# # for selection in [0, 1]: +# selection = 0 if selection == 0: state_symbols = (speicher[0], speicher[1]) @@ -309,24 +313,25 @@ def update(frame): fig, ax = plt.subplots(figsize=(8, 8)) anim, _ = drucken(selection, fig, ax) -# Now the results of **minimized energy** are shown. -#selection = 1 -#print('Message from optimizer:', info_list[selection]['status_msg']) - -#_ = prob_list[selection].plot_objective_value() - -# Plot errors in the solution. -#_ = prob_list[selection].plot_constraint_violations(solution_list[selection]) - -# Plot the trajectories of the block. -#_ = prob_list[selection].plot_trajectories(solution_list[selection]) - -# Animate the solution. -#fig, ax = plt.subplots(figsize=(8, 8)) -#anim, _ = drucken(selection, fig, ax) +# %% +# If you want to run the solution with a fixed time interval, you should add the +# following code to the code here: +# +# selection = 1 +# +# print('Message from optimizer:', info_list[selection]['status_msg']) +# +# _ = prob_list[selection].plot_objective_value() +# +# _ = prob_list[selection].plot_constraint_violations(solution_list[selection]) +# +# _ = prob_list[selection].plot_trajectories(solution_list[selection]) +# +# fig, ax = plt.subplots(figsize=(8, 8)) +# +# anim, _ = drucken(selection, fig, ax) # %% -# A frame from the animation. fig, ax = plt.subplots(figsize=(8, 8)) _, update = drucken(0, fig, ax, video=False) # sphinx_gallery_thumbnail_number = 9 From 9b9b38706a7e69f57ce939fcca0e701c70493664 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Tue, 25 Feb 2025 16:29:22 +0100 Subject: [PATCH 03/15] used the :: to make the commented out lines look nicer. Use backend = numpy --- .../beginner/plot_sliding_block.py | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index ececaa1d..3be49f74 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -6,7 +6,7 @@ Objective --------- -- a simplex example to show how to use ``opty's`` capability of variabel node +- a simple example to show how to use ``opty's`` capability of variable node time interval vs. fixed time interval. @@ -96,16 +96,16 @@ def strasse(x, a, b): q_ind = [x] u_ind = [ux] +# %% +# Use Kane's method for creating the equations of motion. kane = me.KanesMethod(N, q_ind=q_ind, u_ind=u_ind, kd_eqs=kd) fr, frstar = kane.kanes_equations(bodies, forces) eom = kd.col_join(fr + frstar) sm.trigsimp(eom) sm.pprint(eom) - -speicher = (x, ux, F) - # %% # Store the results of the two optimizations for later plotting +speicher = (x, ux, F) solution_list = [] prob_list = [] info_list = [] @@ -123,12 +123,13 @@ def strasse(x, a, b): fixed_duration = 6.0 # seconds # %% -# Set up the optimization problems and solve them. +# Set up to run only one optimization. # if you want to run both optimizations, replace the two lines below with this -# line: -# -# for selection in [0, 1]: -# +# line:: +# for selection in [0, 1]: + +# %% +# Set up the optimization problem and solve it. selection = 0 if selection == 0: state_symbols = (speicher[0], speicher[1]) @@ -197,6 +198,7 @@ def obj_grad(free): known_parameter_map=par_map, instance_constraints=instance_constraints, bounds=bounds, + backend='numpy', ) solution, info = prob.solve(initial_guess) @@ -315,23 +317,17 @@ def update(frame): # %% # If you want to run the solution with a fixed time interval, you should add the -# following code to the code here: -# -# selection = 1 -# -# print('Message from optimizer:', info_list[selection]['status_msg']) -# -# _ = prob_list[selection].plot_objective_value() -# -# _ = prob_list[selection].plot_constraint_violations(solution_list[selection]) -# -# _ = prob_list[selection].plot_trajectories(solution_list[selection]) -# -# fig, ax = plt.subplots(figsize=(8, 8)) -# -# anim, _ = drucken(selection, fig, ax) +# following code to the code here:: +# selection = 1 +# print('Message from optimizer:', info_list[selection]['status_msg']) +# _ = prob_list[selection].plot_objective_value() +# _ = prob_list[selection].plot_constraint_violations(solution_list[selection]) +# _ = prob_list[selection].plot_trajectories(solution_list[selection]) +# fig, ax = plt.subplots(figsize=(8, 8)) +# anim, _ = drucken(selection, fig, ax) # %% +# Create the plot for the thumb nail. fig, ax = plt.subplots(figsize=(8, 8)) _, update = drucken(0, fig, ax, video=False) # sphinx_gallery_thumbnail_number = 9 From 450cf84234aca6b33ba0c67db99a3edda4c4f6d0 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Tue, 25 Feb 2025 16:55:34 +0100 Subject: [PATCH 04/15] try to fix indentation error --- examples-gallery/beginner/plot_sliding_block.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 3be49f74..6959357d 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -320,9 +320,9 @@ def update(frame): # following code to the code here:: # selection = 1 # print('Message from optimizer:', info_list[selection]['status_msg']) -# _ = prob_list[selection].plot_objective_value() -# _ = prob_list[selection].plot_constraint_violations(solution_list[selection]) -# _ = prob_list[selection].plot_trajectories(solution_list[selection]) +# prob_list[selection].plot_objective_value() +# prob_list[selection].plot_constraint_violations(solution_list[selection]) +# prob_list[selection].plot_trajectories(solution_list[selection]) # fig, ax = plt.subplots(figsize=(8, 8)) # anim, _ = drucken(selection, fig, ax) From 47d90517dd993b0091ce0549856d6d641765a141 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Tue, 25 Feb 2025 17:24:00 +0100 Subject: [PATCH 05/15] try again --- examples-gallery/beginner/plot_sliding_block.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 6959357d..3be49f74 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -320,9 +320,9 @@ def update(frame): # following code to the code here:: # selection = 1 # print('Message from optimizer:', info_list[selection]['status_msg']) -# prob_list[selection].plot_objective_value() -# prob_list[selection].plot_constraint_violations(solution_list[selection]) -# prob_list[selection].plot_trajectories(solution_list[selection]) +# _ = prob_list[selection].plot_objective_value() +# _ = prob_list[selection].plot_constraint_violations(solution_list[selection]) +# _ = prob_list[selection].plot_trajectories(solution_list[selection]) # fig, ax = plt.subplots(figsize=(8, 8)) # anim, _ = drucken(selection, fig, ax) From 183147c1005db47e5069bccc74e5eef2f491ef35 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Tue, 25 Feb 2025 17:36:53 +0100 Subject: [PATCH 06/15] missing blank lines? --- examples-gallery/beginner/plot_sliding_block.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 3be49f74..90ae0d75 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -95,9 +95,7 @@ def strasse(x, a, b): q_ind = [x] u_ind = [ux] - -# %% -# Use Kane's method for creating the equations of motion. +# Use Kane's method. kane = me.KanesMethod(N, q_ind=q_ind, u_ind=u_ind, kd_eqs=kd) fr, frstar = kane.kanes_equations(bodies, forces) eom = kd.col_join(fr + frstar) From aa2df3e33eb73087cffbdb4dc125e80315b6e4b2 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Tue, 25 Feb 2025 18:06:30 +0100 Subject: [PATCH 07/15] indentation? --- examples-gallery/beginner/plot_sliding_block.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 90ae0d75..25910765 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -62,7 +62,6 @@ def strasse(x, a, b): return a*x**2*sm.exp((b - x)) - # %% # Set up Kane's equations of motion. N = me.ReferenceFrame('N') @@ -85,8 +84,8 @@ def strasse(x, a, b): bodies = [me.Particle('P0', P0, m)] # %% -# The control force and the friction are acting in the direction of the tangent -# at the road at the point where the particle is. +# The control force and the friction are acting in the direction of the +# tangent at the road at the point where the particle is. alpha = sm.atan(strasse(x, a, b).diff(x)) forces = [(P0, -m*g*N.y + F*(sm.cos(alpha)*N.x + sm.sin(alpha)*N.y) - friction*ux*(sm.cos(alpha)*N.x + sm.sin(alpha)*N.y))] From 4f3561680278d1d3f842699062eac30261476164 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Wed, 26 Feb 2025 18:59:55 +0100 Subject: [PATCH 08/15] moved thumbnail above animation --- examples-gallery/beginner/plot_sliding_block.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 25910765..e5c8674c 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -1,4 +1,3 @@ -# %% """ Block Sliding Over a Hill ========================= @@ -98,8 +97,9 @@ def strasse(x, a, b): kane = me.KanesMethod(N, q_ind=q_ind, u_ind=u_ind, kd_eqs=kd) fr, frstar = kane.kanes_equations(bodies, forces) eom = kd.col_join(fr + frstar) -sm.trigsimp(eom) +eom = sm.trigsimp(eom) sm.pprint(eom) + # %% # Store the results of the two optimizations for later plotting speicher = (x, ux, F) @@ -307,6 +307,13 @@ def update(frame): # Plot the trajectories of the block. _ = prob_list[selection].plot_trajectories(solution_list[selection]) +# %% +# Create the plot for the thumb nail. +fig, ax = plt.subplots(figsize=(8, 8)) +_, update = drucken(0, fig, ax, video=False) +# sphinx_gallery_thumbnail_number = 4 +_ = update(100) + # %% # Animate the solution. fig, ax = plt.subplots(figsize=(8, 8)) @@ -323,11 +330,5 @@ def update(frame): # fig, ax = plt.subplots(figsize=(8, 8)) # anim, _ = drucken(selection, fig, ax) -# %% -# Create the plot for the thumb nail. -fig, ax = plt.subplots(figsize=(8, 8)) -_, update = drucken(0, fig, ax, video=False) -# sphinx_gallery_thumbnail_number = 9 -update(100) plt.show() From cf63fc7c85a213e2a5e8ea69e31847ca00f214c9 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Thu, 27 Feb 2025 10:43:43 +0100 Subject: [PATCH 09/15] still searching for the indentation --- examples-gallery/beginner/plot_sliding_block.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index e5c8674c..25bff340 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -5,7 +5,7 @@ Objective --------- -- a simple example to show how to use ``opty's`` capability of variable node +- a simple example to show how to use opty's capability of variable node time interval vs. fixed time interval. @@ -312,6 +312,7 @@ def update(frame): fig, ax = plt.subplots(figsize=(8, 8)) _, update = drucken(0, fig, ax, video=False) # sphinx_gallery_thumbnail_number = 4 + _ = update(100) # %% @@ -319,6 +320,8 @@ def update(frame): fig, ax = plt.subplots(figsize=(8, 8)) anim, _ = drucken(selection, fig, ax) +plt.show() + # %% # If you want to run the solution with a fixed time interval, you should add the # following code to the code here:: @@ -329,6 +332,4 @@ def update(frame): # _ = prob_list[selection].plot_trajectories(solution_list[selection]) # fig, ax = plt.subplots(figsize=(8, 8)) # anim, _ = drucken(selection, fig, ax) - - -plt.show() +# plt.show() From c122b75e281e19b1a304b5389bec4045e5f7f426 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Thu, 27 Feb 2025 11:13:33 +0100 Subject: [PATCH 10/15] next trial --- examples-gallery/beginner/plot_sliding_block.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 25bff340..1cf1b308 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -289,7 +289,6 @@ def update(frame): return animation, update - # %% # Below the results of **minimized duration** are shown. selection = 0 @@ -310,7 +309,8 @@ def update(frame): # %% # Create the plot for the thumb nail. fig, ax = plt.subplots(figsize=(8, 8)) -_, update = drucken(0, fig, ax, video=False) +_ , update = drucken(0, fig, ax, video=False) + # sphinx_gallery_thumbnail_number = 4 _ = update(100) From 8f8e9e26a522dc6bac66030f85abf6a234ccedf1 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Fri, 28 Feb 2025 08:04:49 +0100 Subject: [PATCH 11/15] indentation issue solved? --- examples-gallery/beginner/plot_sliding_block.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 1cf1b308..2ba73c27 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -174,9 +174,9 @@ def obj_grad(free): instance_constraints = ( tuple(xi.subs({t: t0}) - xi_val for xi, xi_val in - initial_state_constraints.items()) + + initial_state_constraints.items()) + tuple(xi.subs({t: tf}) - xi_val for xi, xi_val in - final_state_constraints.items()) + final_state_constraints.items()) ) bounds = {F: (-15., 15.), From 6072327f52104021ee0cb98472ac96006ca6abfa Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Fri, 28 Feb 2025 09:07:22 +0100 Subject: [PATCH 12/15] reduced frames --- .../beginner/plot_sliding_block.py | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 2ba73c27..aa70b626 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -169,19 +169,16 @@ def obj_grad(free): if selection == 0: initial_guess = np.hstack((initial_guess, 0.02)) - initial_state_constraints = {x: 0.0, ux: 0.0} - final_state_constraints = {x: 10.0, ux: 0.0} - instance_constraints = ( - tuple(xi.subs({t: t0}) - xi_val for xi, xi_val in - initial_state_constraints.items()) + - tuple(xi.subs({t: tf}) - xi_val for xi, xi_val in - final_state_constraints.items()) - ) + x.subs({t: t0}) - 0.0, + ux.subs({t: t0}) - 0.0, + x.subs({t: tf}) - 10.0, + ux.subs({t: tf}) - 0.0) bounds = {F: (-15., 15.), - x: (initial_state_constraints[x], final_state_constraints[x]), + x: (0.0, 10.0), ux: (0., 100)} + if selection == 0: bounds[h] = (1.e-5, 1.) @@ -254,10 +251,8 @@ def initialize_plot(): strasse_x = np.linspace(xmin, xmax, 100) ax.plot(strasse_x, strasse_lam(strasse_x, par_map[a], par_map[b]), color='black', linestyle='-', linewidth=1) - ax.axvline(initial_state_constraints[x], color='r', linestyle='--', - linewidth=1) - ax.axvline(final_state_constraints[x], color='green', linestyle='--', - linewidth=1) + ax.axvline(0.0, color='r', linestyle='--', linewidth=1) + ax.axvline(10.0, color='green', linestyle='--', linewidth=1) # Initialize the block and the arrow line1, = ax.plot([], [], color='blue', marker='o', markersize=12) @@ -282,8 +277,8 @@ def update(frame): return line1, pfeil if video: - animation = FuncAnimation(fig, update, frames=range(len(P0_x)), - interval=1000*interval_value) + animation = FuncAnimation(fig, update, frames=range(0, len(P0_x), 2), + interval=1000*interval_value*2) else: animation = None From ec12bec138a3d48a87bdd966db8b4bd1acfb5386 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Fri, 28 Feb 2025 09:37:09 +0100 Subject: [PATCH 13/15] again..... --- examples-gallery/beginner/plot_sliding_block.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index aa70b626..47d6598c 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -162,6 +162,9 @@ def obj_grad(free): grad[-1] = 1.0 return grad + else: + raise ValueError('Invalid selection') + t0, tf = 0.0, duration initial_guess = np.ones((num_states + From b3522cf79203c7b3df20325f6a5c8875663419e1 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Fri, 28 Feb 2025 10:01:39 +0100 Subject: [PATCH 14/15] reaching the end of my wits... --- examples-gallery/beginner/plot_sliding_block.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index 47d6598c..d9b49efc 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -134,7 +134,8 @@ def strasse(x, a, b): constant_symbols = (m, g, friction, a, b) specified_symbols = (speicher[2], ) - if selection == 1: # minimize integral of force magnitude + if selection == 1: + # minimize integral of force magnitude duration = fixed_duration interval_value = duration/(num_nodes - 1) @@ -149,7 +150,8 @@ def obj_grad(free): grad[l1: l2] = 2.0*free[l1:l2]*interval_value return grad - elif selection == 0: # minimize total duration + elif selection == 0: + # minimize total duration h = sm.symbols('h') duration = (num_nodes - 1)*h interval_value = h From f52c58a1398c26ff1bdcf7da4153036d81d1d559 Mon Sep 17 00:00:00 2001 From: Peter Stahlecker Date: Fri, 28 Feb 2025 10:20:28 +0100 Subject: [PATCH 15/15] ojecting to an empty line... --- examples-gallery/beginner/plot_sliding_block.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples-gallery/beginner/plot_sliding_block.py b/examples-gallery/beginner/plot_sliding_block.py index d9b49efc..fa5bee85 100644 --- a/examples-gallery/beginner/plot_sliding_block.py +++ b/examples-gallery/beginner/plot_sliding_block.py @@ -155,7 +155,7 @@ def obj_grad(free): h = sm.symbols('h') duration = (num_nodes - 1)*h interval_value = h - +# def obj(free): return free[-1]