Solving systems of nonlinear equations
This example demonstrates how to solve systems of nonlinear equations using a problem-oriented approach.
We will use the functions of the [JuMP.jl] library(https://github.com/jump-dev/JuMP .jl) for the formulation of the optimization problem and the library of nonlinear optimization Ipopt.jl.
Installing Libraries
If the latest version of the package is not installed in your environment JuMP, uncomment and run the cell below:
Pkg.add(["Ipopt", "JuMP"])
#Pkg.add("JuMP");
To launch a new version of the library after the installation is complete, click on the "Personal Account" button:
Then click on the "Stop" button:
Restart the session by clicking the "Start Engee" button:
Task description
We'll find solutions and for the system of nonlinear equations presented below, using a problem-oriented approach:
\begin{cases} exp(-exp(-(x_1+x_2)))=x_2(1+x_1^2) \ \x_1cos(x_2)+x_2sin(x_1)={\frac{{1}}{2}}\end
Connecting libraries
Connect the library JuMP:
using JuMP;
Connect the library of the nonlinear solver Ipopt:
using Ipopt;
Creating an optimization task
Create an optimization task using the function Model() and specify the name of the solver in parentheses.:
sys_prob = Model(Ipopt.Optimizer)
Create a variable x containing two values – and :
@variable(sys_prob, x[1:2]);
Set the first non-linear condition using a macro @NLconstraint:
@NLconstraint(sys_prob, exp(-exp(-(x[1] + x[2]))) == x[2] * (1 + x[1]^2))
Set the second non-linear condition using a macro @NLconstraint:
@NLconstraint(sys_prob, x[1] * cos(x[2]) + x[2] * sin(x[1]) == 1/2)
Setting initial values for optimization variables can help to manage the optimization process more effectively. Solve the problem starting from the point [0,0]. To do this, use the function set_start_value() and set the initial values for $x_1$ and $x_2$:
set_start_value(x[1], 0.0);
set_start_value(x[2], 0.0);
Solving the optimization problem
Solve the optimization problem:
optimize!(sys_prob)
Save the values x in the variable:
sol_x = value.(x);
Output the optimization results:
println("Solution: x = ", sol_x)
The solutions we found for the system of nonlinear equations:
Conclusion
In this example, we have found solutions for a system of nonlinear equations using a problem-oriented approach. We used the library JuMP for the formulation of our problem and the library of the nonlinear solver Ipopt to find solutions to the problem.