Hypersensitive Problem#
Mathematical Formulation#
Problem Statement#
Find the optimal control \(u(t)\) that minimizes the quadratic cost functional:
\[J = \int_0^{40} \frac{1}{2}\left( x^2 + u^2 \right) dt\]
Subject to the nonlinear dynamic constraint:
\[\frac{dx}{dt} = -x^3 + u\]
Boundary Conditions#
Initial condition: \(x(0) = 1.5\)
Final condition: \(x(40) = 1.0\)
Control bounds: \(u \in \mathbb{R}\) (unconstrained)
Physical Parameters#
Time horizon: \(t_f = 40\) s
State Variables#
\(x(t)\): System state
Control Variable#
\(u(t)\): Control input
Notes#
This problem is known as “hypersensitive” because small changes in the control can lead to large changes in the state trajectory due to the nonlinear \(-x^3\) term.
Running This Example#
cd examples/hypersensitive
python hypersensitive.py
Code Implementation#
examples/hypersensitive/hypersensitive.py#
1import maptor as mtor
2
3
4# Problem setup
5problem = mtor.Problem("Hypersensitive Problem")
6phase = problem.set_phase(1)
7
8# Variables
9t = phase.time(initial=0, final=40)
10x = phase.state("x", initial=1.5, final=1.0)
11u = phase.control("u")
12
13# Dynamics
14phase.dynamics({x: -(x**3) + u})
15
16# Objective
17integrand = 0.5 * (x**2 + u**2)
18integral_var = phase.add_integral(integrand)
19problem.minimize(integral_var)
20
21# Mesh and guess
22phase.mesh([8, 8, 8], [-1.0, -1 / 3, 1 / 3, 1.0])
23
24# Solve with adaptive mesh
25solution = mtor.solve_adaptive(
26 problem,
27 error_tolerance=1e-3,
28 min_polynomial_degree=5,
29 max_polynomial_degree=15,
30 nlp_options={"ipopt.print_level": 0, "ipopt.max_iter": 200},
31)
32
33# Results
34if solution.status["success"]:
35 print(f"Adaptive objective: {solution.status['objective']:.6f}")
36 solution.plot()
37
38
39else:
40 print(f"Failed: {solution.status['message']}")