Skip to content

Instantly share code, notes, and snippets.

@jasperkennis
Created February 19, 2017 12:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jasperkennis/7f138cb837031518a5da4790a61693c4 to your computer and use it in GitHub Desktop.
Finding the max value of y
#!/usr/bin/env php
<?php
$points = [
[6.13, 73],
[5.76, 77.7],
[5.39, 78.6]
];
$x1 = $points[0][0];
$x2 = $points[1][0];
$x3 = $points[2][0];
echo "x1: $x1, x2: $x2, x3: $x3 \n";
$y1 = $points[0][1];
$y2 = $points[1][1];
$y3 = $points[2][1];
echo "y1: $y1, y2: $y2, y3: $y3 \n";
$k1 = $y1 / (($x1 - $x2) * ($x1 - $x3));
$k2 = $y2 / (($x2 - $x1) * ($x2 - $x3));
$k3 = $y3 / (($x3 - $x2) * ($x3 - $x1));
echo "k1: $k1, k2: $k2, k3: $k3\n";
$x = (($k1 * ($x2 + $x3)) + ($k2 * ($x1 + $x3)) + ($k3 * ($x2 + $x1))) / (2 * ($k1 + $k2 + $k3));
echo "x: $x\n";
$y = $k1 * ($x - $x2) * ($x - $x3) + $k2 * ($x - $x1) * ($x - $x3) + $k3 * ($x - $x2) * ($x - $x1);
echo "f(x): $y\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment