How to Solve Equations with java?

Cong De Peng picture Cong De Peng · Sep 16, 2009 · Viewed 85.3k times · Source

I have three equations like the following ones:

  • x + y + z = 100;
  • x + y - z = 50;
  • x - y - z = 10;

How can I find the values of x, y, and z with Java?

String equation1="x+y+z=100;";
String equation2="x+y-z=50;";
String equation3="x-y-z=10;";

int[] SolveEquations(equation1,equation2,equation3) {
   // to do
   // how to do?    
} 

Do you have any possible solutions or other common frameworks?

Answer

Xinus picture Xinus · Sep 16, 2009

You can use determinant to calculate values of x y and z. Logic can be found out here http://www.intmath.com/Matrices-determinants/1_Determinants.php

And then you need to implement it in java using 3 dimensional arrays.