# How to solve a nonlinear system with redundancy with NonlinearSolve.jl

**URL:** https://discourse.julialang.org/t/how-to-solve-a-nonlinear-system-with-redundancy-with-nonlinearsolve-jl/117840
**Category:** Modelling & Simulations
**Tags:** nonlinearsolve
**Created:** [August 5, 2024, 12:31pm UTC](https://discourse.julialang.org/t/how-to-solve-a-nonlinear-system-with-redundancy-with-nonlinearsolve-jl/117840 "2024-08-05T12:31:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![VPBML](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vpbml/32/212617_2.png) [@VPBML](https://discourse.julialang.org/u/VPBML)
#### Post date: [August 5, 2024, 12:31pm UTC](https://discourse.julialang.org/t/how-to-solve-a-nonlinear-system-with-redundancy-with-nonlinearsolve-jl/117840/1 "2024-08-05T12:31:07Z")

</div>

Hi,

I have problem using NonlinearSolve.jl to solve the following nonlinear system. The reason of the problem is because of the redundancy among the last 3 equations. I wonder if it is possible for NonlinearSolve.jl to somehow automatically remove this redundancy and succesfully solve the system.  
I need NonlinearSolve.jl to do that automatically since it will work on many nonlinear systems generated by other codes. Thanks for your help!

```julia
using ModelingToolkit, NonlinearSolve
@variables ir1 ir2 ir3 yA yF SP
eqs = [0 ~ ir2 - min(ir1, yA*SP),
    0 ~ ir2 - yF,
    0 ~ ir3 - max(ir1, yF),
    0 ~ ir3 - yA*SP,
    0 ~ yA - 1.0,
    0 ~ yF - 2.0,
    0 ~ SP*yA - yF]

@named sys = NonlinearSystem(eqs, [ir1, ir2, ir3, yA, yF, SP], [])
sys = structural_simplify(sys)
u0 = [ir1 .=> 3.0, ir2 .=> 3.0, ir3 .=> 3.0, yA => 1.0, yF => 2.0, SP .=> 2.0]
prob = NonlinearProblem(sys, u0)
sol = solve(prob, NewtonRaphson())

```

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [August 5, 2024, 1:11pm UTC](https://discourse.julialang.org/t/how-to-solve-a-nonlinear-system-with-redundancy-with-nonlinearsolve-jl/117840/2 "2024-08-05T13:11:32Z")

</div>

You don’t have a fully-determined system, so is this what you’re looking for?

```julia
julia> sys = structural_simplify(sys; fully_determined=false)
Model sys with 3 equations
Unknowns (2):
  ir1
  SP
Parameters (0):

julia> equations(sys)
3-element Vector{Equation}:
 0 ~ ir2 - min(ir1, SP*yA)
 0 ~ ir3 - max(ir1, yF)
 0 ~ -yF + SP*yA

julia> observed(sys)
4-element Vector{Equation}:
 yA ~ 1.0
 yF ~ 2.0
 ir3 ~ SP*yA
 ir2 ~ yF

```
