0

Apologies if this has been asked before, I’m a little stuck. If I had two variables

a = 3x+4y
b = 2x+2y

How could I make it so that a+b = 5x+4y? The way I’ve been currently doing it is with numpy and the imaginary variable. However that doesn’t extend to more than one.

My current one variable code looks like this:

from numpy import *
a = 1+3j
b = 2+7j

Then I can just you the real and imag functions to get the appropriate coefficients.

Thanks

asked Jan 29, 2020 at 19:51
2
  • 4
    The way I’ve been currently doing it ... -> Please edit your question and show us your code Commented Jan 29, 2020 at 19:53
  • 1
    Are you sure you need numpy to run your example code? Commented Jan 29, 2020 at 20:04

1 Answer 1

4

You can use Sympy.

from sympy import symbols
x = symbols('x')
y = symbols('y')
a = symbols('a')
b = symbols('b')

And define your equation using the python variables defined above

expr1 = 5*x + 4*y
expr2 = a + b
answered Jan 29, 2020 at 19:54
Sign up to request clarification or add additional context in comments.

1 Comment

How would I then get the coefficient infront of the x? Such as in expression one it is five?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.