Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to solve a nonlinear equation system numerically?

I am new to sagemath and am having some trouble by printing the solution of a nonlinear equation system in a numerical way. I tried it with print(soln[0].n(160)) but that didn't work. Has someone an idea how to overcome this problme?

var('x y')
eq1 = x*y^2 - 5*y + 4*x - 3 == 0
eq2 = x*y - 2*x + 2 == 0
solutions = solve([eq1,eq2],x,y)
sol_n = solutions[0] # save only the negative results
sol_p = solutions[1] # save only the positive results
print(sol_n[0])
print(sol_n[1])
print(sol_p[0])
print(sol_p[1])

Resulting (exact) output:

x == -1/16*I*sqrt(7) + 21/16
y == -1/14*I*sqrt(7) + 1/2
x == 1/16*I*sqrt(7) + 21/16
y == 1/14*I*sqrt(7) + 1/2