Created
January 27, 2020 02:35
-
-
Save aresnick/d8c7818de536503cad7d731cf0a45651 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
# A quick sketch of a few ways that variables in computer programming relate to algebraic variables | |
A common (a la Bednarz, Kieran, & Lee, 1996; KuΜchemann, 1981; | |
MacGregor & Stacey, 1993; Malle, 1993; Usiskin, 1988) breakdown | |
of the functions of variable are into: | |
π β placeholder for number | |
β βΒ an unknown number | |
π βΒ a varying quantity | |
π βΒ a generalized number | |
π¨ βΒ and a parameter | |
I've annotated the code below with emoji indicating which of the uses above are entailed. | |
*/ | |
var l; // π | |
l = 5; | |
////////// | |
// Find the intersection of two functions discretely | |
var y1 = (x) => x * x; // π, π, π¨ | |
var y2 = (x) => x; // π, π, π¨ | |
var find_intersections = function(f1, f2, domain_start, domain_end, epsilon = 0.0001, step_size = 0.01) { // π, π, π¨ | |
intersections = []; // β | |
x = domain_start; // π | |
while (x <= domain_end) { // π, π | |
if (Math.abs(f1(x) - f2(x)) <= epsilon) { // π | |
intersections.push(x); // β | |
} | |
x += step_size; // π | |
} | |
return intersections; // π | |
}; | |
console.log(find_intersections(y1, y2, 0, 100)); | |
////////// | |
// Represent the addition of complex numbers | |
var Complex = function(real, imaginary) { // π, π¨ | |
this.real = (typeof real === 'undefined') ? this.real : parseFloat(real); // π, β | |
this.imaginary = (typeof imaginary === 'undefined') ? this.imaginary : parseFloat(imaginary); // π, β | |
}; | |
Complex.add = function(c1, c2) { // π, π¨ | |
return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary); // π, π, π¨ | |
}; | |
var x = new Complex(1, 0); // π | |
var y = new Complex(0, 1); // π | |
console.log(Complex.add(x, y)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment