# Calling Mathematica into Julia to symbolically solve a system of non-linear equations

**URL:** <https://discourse.julialang.org/t/calling-mathematica-into-julia-to-symbolically-solve-a-system-of-non-linear-equations/80518>\
**Category:** Specific Domains\
**Tags:** question, nonlinear, symbolics, mathematica\
**Created:** [May 5, 2022, 1:51am UTC](https://discourse.julialang.org/t/calling-mathematica-into-julia-to-symbolically-solve-a-system-of-non-linear-equations/80518 "2022-05-05T01:51:26Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [May 5, 2022, 2:51am UTC](https://discourse.julialang.org/t/calling-mathematica-into-julia-to-symbolically-solve-a-system-of-non-linear-equations/80518/4 "2022-05-05T02:51:53Z")

</div>

> [@MAC](#):
>
> 10 equations with 8 variables

This is over-determined, so may not have a solution, but clearly it does since you provide one.

> [@amrods](#):
>
> You can use [`JuMP`](https://jump.dev) for that.

Here is how you might do it with JuMP and the [Gurobi](https://github.com/jump-dev/Gurobi.jl) solver:

> **JuMP Example**
>
> ```julia
> using JuMP
> using Gurobi
> 
> ## Parameters:
> kb1 = 0.01;
> K1 = 10.0;
> d1 = 1.0;
> l11 = 1.0;
> m11 = 0.01;
> l12 = 1.0;
> m12 = 5.0;
> kb2 = 0.01;
> K2 = 30.0;
> d2 = 1.0;
> l22 = 1.0;
> m22 = 0.01;
> l21 = 1.0;
> m21 = 5.0;
> 
> ## Model def.:
> model = JuMP.Model(Gurobi.Optimizer)
> JuMP.set_optimizer_attribute(model, "NonConvex", 2)
> 
> ## Variables:
> V = @variables(model, begin
> X10
> M1
> X11
> M2
> X12
> X20
> X22
> X21
> end)
> 
> C = @constraints(model, begin
> m11*X11 + m12*X12 - l11*M1*X10 - l12*M2*X10 == 0 
> K1*X11 + kb1*X10 + m11*X11 + m21*X21 - d1*M1 - l11*M1*X10 - l21*M1*X20 == 0 
> l11*M1*X10 - m11*X11 == 0 
> m12*X12 + kb2*X20 + K2*X22 + m22*X22 - d2*M2 - l12*M2*X10 - l22*M2*X20 == 0 
> l12*M2*X10 - m12*X12 == 0 
> m21*X21 + m22*X22 - l21*M1*X20 - l22*M2*X20 == 0 
> l22*M2*X20 - m22*X22 == 0
> l21*M1*X20 - m21*X21 == 0 
> X10 + X12 + X11 == 1 
> X20 + X21 + X22 == 1 
> M1 >= 0 
> M2 >= 0
> end)
> 
> optimize!(model)
> 
> result_dict = Dict(V .=> value.(V))
> primal_feasibility_report(model, result_dict)
> 
> # Provided solution:
> feas_pt = Dict(X10 => 0.000999999, M1 => 9.93007, X11 => 0.993006, M2 => 29.9701, 
> X12 => 0.00599402, X20 => 0.000333333, X22 => 0.999005, 
> X21 => 0.000662005)
> 
> primal_feasibility_report(model, feas_pt)
> 
> ```

---

_[View the full topic](https://discourse.julialang.org/t/calling-mathematica-into-julia-to-symbolically-solve-a-system-of-non-linear-equations/80518)._
