Simple optimization with CasADi (0-10 points)
Description
Implement a solution using CasADi for the following optimization problem.
Minimize:
f(x, y, z, p) = 3x^4 + y^3 + z^2 + 2xy + 4z ,
assuming following constraints:
\begin{array}{ccc}
x, y, z & \geq & 0 \\
8x + 4y + 2z - p_1 & = & 0 \\
p_2x + y - z - 1 & = & 0 \\
\end{array}
where:
p =
\left[ \begin{array}{ccc}
p_1 \\
p_2 \\
\end{array} \right]
=
\left [ \begin{array}{ccc}
5.0 \\
1.0 \\
\end{array} \right ]
Remarks
- CasADi installation
pip install casadi
- Provide a well-documented code explaining your approach, variable definitions, and the optimization process.
Example of optimization with CasADi
import casadi as ca
# Create a CasADi function for the objective
x = ca.MX.sym('x')
objective = x**2 - 10*x + 100.0
obj_func = ca.Function('obj_func', [x], [objective])
# Create an optimization problem
opti = ca.Opti()
# Add the variable to the optimization problem
x_opti = opti.variable()
# Use the CasADi function within the optimization problem
opti.minimize(obj_func(x_opti))
# Choose solver
opts = {'ipopt': {'print_level': 0}}
opti.solver('ipopt', opts)
# Solve the optimization problem
sol = opti.solve()
# Get the optimal solution
optimal_x = sol.value(x_opti)
print("Optimal solution:", optimal_x)