Created
October 26, 2014 05:18
-
-
Save younata/54cb2165359d4c413edd to your computer and use it in GitHub Desktop.
MathKit
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
import MathKit | |
let p = SimplePolynomial(string: "3x^2 + x + 1") | |
let p2 = SimplePolynomial(string: "(x)(y)") | |
let p3 = SimplePolynomial(string: "thisIsOneLongVariable^2") | |
p + p2 // returns 3x^2 + x + (x)(y) + 1 | |
p - p2 // returns 3x^2 + x - (x)(y) + 1 | |
p * p2 // don't feel like figuring that one out. | |
p.valueAt(["x": 1]) // returns 5 | |
p2.polynomialAt(["x": 1]) // returns y | |
p.differentiate("x") // returns 6x + 1 | |
p2.differentiate("x") // returns y | |
p2.gradient() // returns an object equivalent to: ["x": SimplePolynomial(string: "y"), "y": SimplePolynomial(string: "x")] | |
p.solve() // returns nil because this doesn't have any roots (there is no value of x such that f(x) = 0) | |
p2.solve() // returns [["x": 0], ["y": 0]] | |
p.of(p2, at: "x") // returns 3x^2y^2 + (x)(y) + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment