0

I've been working with the algebra.js JavaScript library for a while and I can't find an answer to my problem.
I have a number of equations that varies in type;
(Linear, Radical, Quadratic, and Exponential)
And I need to switch the sides of two or more variables.
An example to the solution would be in a linear equation as follows:

x = 2y - 6 ----> y = (x/2) + 3

This simple example works because the x is in the simplest form and the equation is linear. However, when the equation looks like this:
7a + 4b = 9c + 5d and I want to move the 9c to the left in order for it to look like this:
9c = 7a + 4b - 5d
It can't be done.

Moreover, these are all linear examples which makes them simple to process without using the library. But when it comes to an equation that looks like this:
y = z*(a^x)*b^(1-x)
and I want the left side to be (a^x), it doesn't seem that there is a way to do it.

So, is there any way to transfer a variable or a term to be alone in one side of the equation regardless to solving an equation?
It doesn't have to be algebra.js. It can be any library or code using JavaScript.

Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75

1 Answers1

0

Have you read thru algebra.js documentation already? There is a direct statement how to do this -- see solve linear equation chapter, multiple variables subchapter, and its example:

var eq = new Equation(...)
var xAnswer = eq.solveFor("x");
var yAnswer = eq.solveFor("y");

Same solveFor() applies to other equation types as well.

andy
  • 757
  • 5
  • 13
  • I'm sorry the question wasn't clear enough. I'm not trying to solve the equation for a variable. The question is better explained now. –  Nov 28 '17 at 09:55
  • When you apply `eq.solveFor("c")` on `7a + 4b = 9c + 5d` you will get `c` as left-side but you want `9c`? I do not see a way to stop library from simplifying expression *too much* or solving it completely. – andy Nov 28 '17 at 10:20
  • The problem with this approach is that the library will try to solve the equation and as mentioned, the equations that I have are not all linear. As a matter of fact most of them are not. So, if I try to solve this equation `7a^2 + 4b = 9c^2 * 5d^3` for the `c` variable, it is going to give an error because it can't be solved. Instead, asking for putting one term `9c^2` is an easier process but I can't seem to figure out how to apply it using existing libraries to get this result: `9c^2 = (7a^2 + 4b)/5d^3` –  Nov 28 '17 at 11:29