Solving for only half the solution in NonlinearSolve.jl

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:

 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```

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.

1 Like