Skip to content
\n

In this setting, it works just fine.

\n

But when I tried to change the horizon into something like (changing nothing but the number of points in the linspace):

\n
horizon = np.linspace(0, Tf, 4, endpoint=True)\n
\n

the result seemed to be extremely strange, with the inputs u always remaining the same:

\n
Summary statistics:\n* Cost function calls: 9\n* Constraint calls: 20\n* System simulations: 27\n* Final cost: 16000.0\n    cost: 16000.0\n     fun: 16000.0\n  inputs: array([[10., 10., 10., 10.],\n       [ 0.,  0.,  0.,  0.]])\n     jac: array([ 0.00000000e+00,  2.44140625e-04,  1.22070312e-04,  0.00000000e+00,\n       -3.62099047e+06, -6.84054738e+06, -2.12256850e+06, -7.49211857e+05])\n message: 'Optimization terminated successfully'\n    nfev: 9\n     nit: 5\n    njev: 1\n problem: <control.optimal.OptimalControlProblem object at 0x7ff0cb281df0>\n  states: array([[  0.        ,  33.33333333,  66.66666667, 100.        ],\n       [ -2.        ,  -2.        ,  -2.        ,  -2.        ],\n       [  0.        ,   0.        ,   0.        ,   0.        ]])\n  status: 0\n success: True\n    time: array([ 0.        ,  3.33333333,  6.66666667, 10.        ])\n       x: array([10., 10., 10., 10.,  0.,  0.,  0.,  0.])\n\n
\n

It's the case for all num except 3 in the np.linspace(0, Tf, num).

\n

I'm confused by this results and wonder what's the actual use of 'horizon'? (I do notice from the comments that it's a \"List of times at which the optimal input should be computed\", but I still can't understand)

\n

Hope for any help.

\n

Thanks!

","upvoteCount":1,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"

This problem is addressed in PR #799 by switching to using collocation as the default method for solving optimal control problems. This is much more numerically stable and provides good solutions to the example problem from the documentation (and without the issues are the solution only working for a specific number of time points).

","upvoteCount":1,"url":"https://github.com/python-control/python-control/discussions/781#discussioncomment-4240712"}}}
Discussion options

You must be logged in to vote

This problem is addressed in PR #799 by switching to using collocation as the default method for solving optimal control problems. This is much more numerically stable and provides good solutions to the example problem from the documentation (and without the issues are the solution only working for a specific number of time points).

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@murrayrm
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by murrayrm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants