Jason
Jason

Reputation: 2298

How to solve/simplify for a symbolic variable with sageMath

So I want to solve/simplify (not sure the correct term to use here) for the symbolic variable 'a' in this equation:

a == -1 - ((f - af) / n)

with sagemath. I should be expecting and answer of :

a == (-f - n) / (n- f)

I was able to do this using https://mathpapa.com/algebra-calculator.html but wasn't sure if this was possible with sagemath. I've tried a few ways using solve and simplify but couldn't get anything to work.

Upvotes: 2

Views: 1130

Answers (1)

Samuel Lelièvre
Samuel Lelièvre

Reputation: 3443

Do this in three steps.

First declare the symbolic variables in Sage's symbolic ring (SR):

sage: a, f, n = SR.var('a, f, n')

Then define the equation, writing multiplication a * f explicitly:

sage: equation = a == -1 - ((f - a*f) / n)

Solve the equation in terms of the variable a:

sage: solve(equation, a)
[a == (f + n)/(f - n)]

Upvotes: 1

Related Questions