Last active
May 20, 2018 12:33
-
-
Save BenMorel/3798ff53a54daaa267969526d3a28b93 to your computer and use it in GitHub Desktop.
Solve 2 equations with 2 unknowns in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Solves the following equations: | |
* | |
* a·x + b·y = c | |
* d·x + e·y = f | |
* | |
* Returns an array with [x, y] | |
*/ | |
function solve($a, $b, $c, $d, $e, $f) | |
{ | |
$x = $c * $e - $b * $f; | |
$y = $a * $f - $c * $d; | |
$z = $a * $e - $b * $d; | |
return [$x / $z, $y / $z]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment