0

I am using the following code to find x and y in this linear equation. I was wondering if there is a way to add two more constrains to the following equation? For example, how can we add x>0 , and y>0 to the following equation(3x+4y=7 and 5x+6y=8)to get a positive output?

from sympy import *
x, y = symbols(['x', 'y'])
system = [Eq(3*x + 4*y, 7), Eq(5*x + 6*y, 8)]
soln = solve(system, [x, y])
print(soln)

1 Answers1

0

You can declare the symbols x and y to be positive:

In [4]: from sympy import *
   ...: x, y = symbols(['x', 'y'])
   ...: system = [Eq(3*x + 4*y, 7), Eq(5*x + 6*y, 8)]
   ...: soln = solve(system, [x, y])
   ...: print(soln)
{x: -5, y: 11/2}

In [5]: from sympy import *
   ...: x, y = symbols(['x', 'y'], positive=True)
   ...: system = [Eq(3*x + 4*y, 7), Eq(5*x + 6*y, 8)]
   ...: soln = solve(system, [x, y])
   ...: print(soln)
[]
Oscar Benjamin
  • 12,649
  • 1
  • 12
  • 14
  • Hi Oscar, thanks for your reply. However, declaring x, and y positive like that doesn't produce any result. 'x, y =symbols(['x', 'y'], positive=True) system = [Eq(27*x + 1*y, 0.307), Eq(20*x + 1*y, 0.324)] soln = solve(system, [x, y]) soln' – Mehmet Fatih Yasar Aug 02 '22 at 17:37
  • 1
    There is no solution to those equations for positive x and y because the unique solution in the reals requires negative x. – Oscar Benjamin Aug 02 '22 at 23:56