using NonlinearSolve, LinearAlgebra, Plots
N₂=14
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.1; fill(0.3, N₂-1); 0.1], [0.6, 1])
solver₂ = solve(probg₂, NewtonRaphson(), reltol = 1e-9) # solution is given as a vector
plot(solver₂, xlabel="x", ylabel="gₙ", linewidth=2, label=false, color="green", size=(450, 300))
scatter!(solver₂, xlabel="n", ylabel="gₙ", color="red", label=false, size=(450, 300))
The above code produces a vector of data points, solver_2, and then I plot those data points via the Plot.jl package and the scatter() function. See the below figure 1 for the plot resulting from the above code.
Question: How do I center the horizontal axis such that the peak of the graph is centered at the grid point n=0
?
Attempt: Via the documentation here API · Plots I include xlims=(-7.5, 7.5)
, but this does not produce the desired result. See figure 2.
Fig 1:
Fig 2: