Created
May 1, 2022 16:16
-
-
Save ilsubyeega/9a8419a41a20120050e5380b3e1e05b7 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
| const original = (x) => (x - 1) * (x - 2) * (x - 3) * (x - 4) | |
| const h = 1e-8 | |
| const prime = (f => x => (f(x + h) - f(x)) / h)(original) | |
| let max = 100 | |
| let max_x = -1 | |
| for (let i = 0; i <= 10; i += 0.00005) { | |
| const res = Math.abs(prime(i)) | |
| if (res < max) { | |
| max = res | |
| max_x = i | |
| } | |
| if (res.toFixed(3) === "0.000") console.log(i, res.toFixed(8)) | |
| } | |
| // x, f(x), f'(x) | |
| console.log(max_x.toFixed(3), original(max_x).toFixed(3), max.toFixed(3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment