Ask Your Question

Defining a relationship between symbolic variables

asked 2019-03-02 23:04:25 -0500

anonymous user


How can I define a+b+c=1 in Sage after doing var('a','b','c')? How would I make sage remember this equation so that it substitutes that value when calculating (a+b+c)².expand() for example?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2019-03-03 18:27:52 -0500

Juanjo gravatar image

You can save the equation in a variable and apply it through the .subs method. Try, for example, the following code:

eq = a+b+c==1
print (a^2 + 2*a*b + b^2 + 2*a*c + 2*b*c + c^2).factor().subs(eq)
print (1/a + 1/b + c/(a*b)).simplify_rational().subs(eq)
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



Asked: 2019-03-02 23:04:25 -0500

Seen: 53 times

Last updated: Mar 03