# Solving for only half the solution in NonlinearSolve.jl

**URL:** <https://discourse.julialang.org/t/solving-for-only-half-the-solution-in-nonlinearsolve-jl/96163>\
**Category:** Performance\
**Tags:** question, package, nonlinearsolve\
**Created:** [March 16, 2023, 4:19am UTC](https://discourse.julialang.org/t/solving-for-only-half-the-solution-in-nonlinearsolve-jl/96163 "2023-03-16T04:19:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KZ-Spectra](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@KZ-Spectra](https://discourse.julialang.org/u/KZ-Spectra)\
**Post date:** [March 16, 2023, 4:19am UTC](https://discourse.julialang.org/t/solving-for-only-half-the-solution-in-nonlinearsolve-jl/96163/1 "2023-03-16T04:19:33Z")

</div>

```
using NonlinearSolve, LinearAlgebra, Plots

# Parameters: p = [h, \omega]
N=15

g(u,p) = p[1]*Tridiagonal(fill(1,N), fill(-2,N+1), fill(1,N))*u - u.^3 - p[2]*u 

probg = NonlinearProblem{false}(g, [0.3; fill(0.3, N-1); 0.3], [0.6, -0.4])

solver = solve(probg, NewtonRaphson(), reltol = 1e-9)

```

In the above code, I utilize the `NonlinearSolve.jl` package to solve an elliptic nonlinear problem. The solutions are generally symmetric. Below is the output of the above code. Note the symmetry of the solution.

To save computation time, I would like to solve for only half the solution. How do I specify that in this package?

Example:

````julia
 9.165610097608932e-13
 2.704903846479506e-12
 4.63792285826381e-12
 5.947401561035362e-12
 6.6334560728468356e-12
 6.943120557656446e-12
 7.068988650731425e-12
 7.112134991181518e-12
 7.112134991181518e-12
 7.068988650731425e-12
 6.9431205305513916e-12
 6.633456045741781e-12
 5.947401533930308e-12
 4.63792285826381e-12
 2.7049038871370876e-12
 9.165610097608932e-13```
````

---

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [March 16, 2023, 4:50am UTC](https://discourse.julialang.org/t/solving-for-only-half-the-solution-in-nonlinearsolve-jl/96163/2 "2023-03-16T04:50:19Z")

</div>

I suppose you’d have to write the objective function to take an input vector of half the size and “expand” to the full vector inside the function. Then you just simply use the solver as usual.
