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
const polynomial = new Polynomial([1,2,3]); // 3x^2 + 2x + 1 | |
const y1 = polynomial.evaluate(1); // 6 |
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
describe('newton\'s method', () => { | |
it('solves polynomial functions from a guess within 0.5', () => { | |
const solverTest = (polynomial, x) => { | |
if (polynomial.degree <= 0) { | |
return true; // no fun solving constant functions | |
}; | |
// polynomial(x) = y, so we make a new polynomial | |
// polynomialWithZero such that polynomialWithZero(x) = 0 | |
const y = polynomial.evaluate(x); |
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
const shrink = polynomial => { | |
const arrayShrinker = jsc.shrink.array; | |
const arrayIntShrinker = arrayShrinker(jsc.integer.shrink); | |
const coefficientSets = arrayIntShrinker(polynomial.coefficients); | |
return coefficientSets.map(Polynomial.create); | |
}; |
OlderNewer