Build mathematical modelsLesson 37 of 48 · 8 min
Optimise inside the permitted region
Compare stationary candidates with feasible boundary values.
Maths refresher: Interior points and boundaries
An optimum can occur at a flat interior point or at an edge where movement is restricted.
The stationary point is . On it is not feasible; comparing the feasible boundaries gives the maximum at .
Optimisation asks for the best value within a stated feasible region. Solving a derivative equal to zero finds interior stationary candidates, but those candidates may be infeasible or may fail to be the desired maximum or minimum.
For a smooth function on a closed bounded interval, examine feasible stationary points and the endpoints. The example maximises on the teaching interval zero to four. Its unconstrained stationary point lies outside that interval.
Keep the objective, feasible domain and candidate evaluation together. A solver cannot infer an omitted budget or physical bound from the variable name. More complex constrained problems can need specialised optimisation methods, but this small case makes the boundary issue visible.
Can the derivative-zero point be rejected because the model does not permit that input?
Write a prediction (optional)
Exact optimisation of an authored model
Select Run Python with the code unchanged.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
Tools
About Python
Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗
Ctrl+Enter or ⌘+Enter runs Python.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
Worked text output
Objective: x*(10 - x) Unconstrained stationary points: [5] Feasible candidates: [0, 4] Best feasible x: 4 Best value: 24
Read the starter result
Unconstrained stationary points includes 5, which lies outside the starter’s permitted region. Compare Feasible candidates with Best feasible x to see which values actually determine the answer.
Edit and compare
Replace upper = 4 with upper = 8. The upper bound applies to the endpoint candidate and the stationary-point filter. Select Run Python. Compare Feasible candidates and Best feasible x with the first run. Which point becomes available?
Scope. This closed-interval polynomial permits a complete candidate check; general constrained optimisation can be much harder.
Try a fresh case
An unconstrained optimum violates a physical bound. What should you report?
Need a hint?
Hint 1
Check whether each candidate belongs to the permitted region.
Hint 2
Include boundaries when the domain includes them.