0% found this document useful (0 votes)
12 views2 pages

Code Solve GF or FG

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Code Solve GF or FG

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Code for the solve of graph to function or function to graph

var mode = "gf"; // gf / fg

// for gf
var tablex = [-3, -2, -1, 0, 1];
var tabley = [-7, -3, -7, -16, -25];
var waygoing = 0; // 1 for up, 0 for down

// for fg
var func = "" // coming soon

// Formula = "(x - d) = a(x - f)^2"

if (tablex.length > 4 && tabley.length > 4) {


var scratchpaper = "";
if (waygoing == 0) {
var highestpoint = -99999;
var highestpointindex = 0;
var nextpointindex = 0;
for (var findhigh = 0; findhigh < tabley.length; findhigh++) {
if (highestpoint < tabley[findhigh]) {
highestpoint = tabley[findhigh];
highestpointindex = findhigh;
nextpointindex = findhigh - 1;
}
}
console.log("Found variables (d,f) and (x,y)! Time to solve...");
scratchpaper = "Scratch Written:\n";
var dVarVer = -highestpoint;
var fVarVer = -tablex[highestpointindex];
var yVarVer = tabley[0];
var xVarVer = tablex[0];
scratchpaper += "d = " + dVarVer + "\nf = " + fVarVer + "\nx = " +
xVarVer + "\ny = " + yVarVer + "\n";
var leftsideofequals = yVarVer + dVarVer;
var rightsideofequals = xVarVer + fVarVer;
scratchpaper += "(" + yVarVer + " - " + dVarVer + ") = a(" + xVarVer +
" - " + fVarVer + ")^2\n";
scratchpaper += "" + leftsideofequals + " = a(" + rightsideofequals +
")^2\n";
var realrightsideofequals = (rightsideofequals * rightsideofequals);
scratchpaper += "" + leftsideofequals + " = " + (rightsideofequals *
rightsideofequals) + "a\n";
var whatisa = leftsideofequals / realrightsideofequals;
scratchpaper += "a = " + whatisa + "\n";
scratchpaper += "\n\ny = " + whatisa + "(x + " + fVarVer + ")^2 - " +
dVarVer + "\nDone!";
}
if (waygoing == 1) {
var highestpoint = 99999999;
var highestpointindex = 0;
var nextpointindex = 0;
for (var findhigh = 0; findhigh < tabley.length; findhigh++) {
if (highestpoint > tabley[findhigh]) {
highestpoint = tabley[findhigh];
highestpointindex = findhigh;
nextpointindex = findhigh - 1;
}
}
console.log("Found variables (d,f) and (x,y)! Time to solve...");
scratchpaper = "Scratch Written:\n";
var dVarVer = -highestpoint;
var fVarVer = -tablex[highestpointindex];
var yVarVer = tabley[0];
var xVarVer = tablex[0];
scratchpaper += "d = " + dVarVer + "\nf = " + fVarVer + "\nx = " +
xVarVer + "\ny = " + yVarVer + "\n";
var leftsideofequals = yVarVer + dVarVer;
var rightsideofequals = xVarVer + fVarVer;
scratchpaper += "(" + yVarVer + " - " + dVarVer + ") = a(" + xVarVer +
" - " + fVarVer + ")^2\n";
scratchpaper += "" + leftsideofequals + " = a(" + rightsideofequals +
")^2\n";
var realrightsideofequals = (rightsideofequals * rightsideofequals);
scratchpaper += "" + leftsideofequals + " = " + (rightsideofequals *
rightsideofequals) + "a\n";
var whatisa = leftsideofequals / realrightsideofequals;
scratchpaper += "a = " + whatisa + "\n";
scratchpaper += "\n\ny = " + whatisa + "(x + " + fVarVer + ")^2 - " +
dVarVer + "\nDone!";
}
console.log(scratchpaper);
}
else {
console.log("Not enough!");
}

You might also like