Ask Your Question
1

How to solve a nonlinear equation system numerically?

asked 2017-12-10 16:41:17 +0100

anonymous user

Anonymous

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
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-12-10 17:13:34 +0100

tmonteil gravatar image

updated 2017-12-10 17:45:09 +0100

The result you get are expressions (see the == sign):

sage: a = sol_n[0]
sage: a
x == -1/16*I*sqrt(7) + 21/16

What you could do is to get their right-hand side, with the rhs method:

sage: a.rhs()
-1/16*I*sqrt(7) + 21/16
sage: a.rhs().n(160)
1.3125000000000000000000000000000000000000000000 - 0.16535945694153691190635098460245377660689119894*I
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-12-10 15:52:15 +0100

Seen: 1,461 times

Last updated: Dec 10 '17