davidedc / Algebrite

Computer Algebra System in Javascript (Typescript)
http://algebrite.org
MIT License
966 stars 59 forks source link

Obtaining the inverse of a function #129

Closed jarble closed 3 years ago

jarble commented 4 years ago

Does Algebrite have a function that can obtain a function's inverse, similar to the inv(M) function for matrices?

For example, the inverse of 3x + 2 would be (x-2)/3.

davidedc commented 3 years ago

hi @jarble, to do what you ask, one needs to isolate a variable, i.e. solve an equation. Algebrite can solve (some) polynomials (so far).

So, for example, your case can be handled like so: 1) Solve the equation y=3x+2 by doing roots(y=3x+2), which gives: 1/3*y-2/3 2) then substitute y with x.

You can do both steps at once with:

subst(x,y,roots(y=3x+2))

which gives what you desire:

1/3*x-2/3