Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test_the_formula(A, B, x1, x2)
- {
- const E = x => Math.sqrt(x**3 + A*x + B);
- const y1 = E(x1);
- const y2 = E(x2);
- const m = (y2 - y1)/(x2-x1);
- const x3_a = m**2 - x1 - x2;
- const x3_b = (m**2*x1 + x1**2 + A - 2*m*y1)/x2;
- return Math.abs(x3_a - x3_b) < 0.00000001;
- }
- function test()
- {
- for (let A = 1; A < 100; A++)
- for (let B = 1; B < 100; B++)
- {
- let x1 = Math.floor(Math.random()*10) + 1;
- let x2 = x1;
- while (x1 == x2)
- x2 = Math.floor(Math.random()*10) + 1;
- if ( ! test_the_formula(A, B, x1, x2))
- {
- console.log(`A = ${A}; B = ${B}; x1 = ${x1}; x2 = ${x2}`);
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement