fix critical issue

This commit is contained in:
Simon Gardling 2022-03-09 21:48:38 -05:00
parent 450ed827ad
commit 8ab13c79c3
2 changed files with 15 additions and 9 deletions

View File

@ -9,12 +9,12 @@
3. Smart display of graph 3. Smart display of graph
- Display of intersections between functions - Display of intersections between functions
- Add docs about roots and extrema - Add docs about roots and extrema
- Caching of roots and extrema
- add configs for toggling display of roots and extrema
4. Fix integral line 4. Fix integral line
5. re-add euler's number (well it works if you use capital e like `E^x`) 5. re-add euler's number (well it works if you use capital e like `E^x`)
6. allow constants in min/max integral input (like pi or euler's number) 6. allow constants in min/max integral input (like pi or euler's number)
7. sliding values for functions (like a user-interactable slider that adjusts a variable in the function, like desmos) 7. sliding values for functions (like a user-interactable slider that adjusts a variable in the function, like desmos)
8. Keybinds 8. Keybinds
9. nth derivative support (again) 9. nth derivative support (again)
10. add configs for toggling display of roots and extrema 10. Update function tests
11. reduce jittering of roots and extrema points
12. Update function tests

View File

@ -44,6 +44,9 @@ pub struct FunctionEntry {
sum: RiemannSum, sum: RiemannSum,
} }
// How many times should newton's method iterate?
const NEWTON_LOOPS: usize = 50;
impl FunctionEntry { impl FunctionEntry {
// Creates Empty Function instance // Creates Empty Function instance
pub fn empty() -> Self { pub fn empty() -> Self {
@ -290,9 +293,10 @@ impl FunctionEntry {
// Do 50 iterations of newton's method, should be more than accurate // Do 50 iterations of newton's method, should be more than accurate
let x = { let x = {
let mut x1: f64 = last_ele.unwrap().x; let mut x1: f64 = last_ele.unwrap().x;
for _ in 0..50 { let mut x2: f64;
x1 = last_ele.unwrap().x for _ in 0..NEWTON_LOOPS {
- (self.function.get(x1) / self.function.derivative(x1)) x2 = x1 - (self.function.get(x1) / self.function.derivative(x1));
x1 = x2;
} }
x1 x1
}; };
@ -317,9 +321,11 @@ impl FunctionEntry {
// Do 50 iterations of newton's method, should be more than accurate // Do 50 iterations of newton's method, should be more than accurate
let x = { let x = {
let mut x1: f64 = last_ele.unwrap().x; let mut x1: f64 = last_ele.unwrap().x;
for _ in 0..50 { let mut x2: f64;
x1 = last_ele.unwrap().x for _ in 0..NEWTON_LOOPS {
- (self.function.derivative(x1) / self.function.get_derivative_2(x1)) x2 = x1
- (self.function.derivative(x1) / self.function.get_derivative_2(x1));
x1 = x2;
} }
x1 x1
}; };