Struggling to understand how NLsolve works

Real stupid question here, but I’m trying to get this simple system of equations to solve using NLsolve. I know this is simple enough that I don’t need a nonlinear solver, but I’m just using this for the time being so I can eventually use it for actual nonlinear equations.


a = 20
b = 1
c = 1

function lrnNLS(pq)
    p,q = pq
    pmom = a - b*q - p
    qmom = a - 2*b*q - c 
    return(pmom, qmom)
    
end 

guess = [1.0, 1.0]
a,b = guess
#q = 7
rezzy = nlsolve(lrnNLS, guess)

I’m trying to get this to solve the system of equations (with a, b, and c defined as above):
p = a - bq
a - 2bq - c = 0

but for some reason it is either failing to converge or returning incorrect values. This is working fine with fsolve in python, so I’m lost as to what the issue is here in Julia. Any help is greatly appreciated!

Best,
Chuck

Ah, I should’ve just run your example first - I misunderstood NLsolve. The issue is that you redefine a, b = guess in your code, which then gets used in lrnNLS, so the system you are solving has a=b=1 instead of a=b=20.

That one’s on me. Thanks for the speedy response Daniel.