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
Christopher Nethercott
451 gold badge1 silver badge7 bronze badges
-
4The way I’ve been currently doing it ... -> Please edit your question and show us your codeOcaso Protal– Ocaso Protal2020年01月29日 19:53:47 +00:00Commented Jan 29, 2020 at 19:53
-
1Are you sure you need numpy to run your example code?Ed Ward– Ed Ward2020年01月29日 20:04:03 +00:00Commented Jan 29, 2020 at 20:04
1 Answer 1
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
Alireza Tajadod
3271 silver badge8 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Christopher Nethercott
How would I then get the coefficient infront of the x? Such as in expression one it is five?
lang-py