Guest User

Untitled

a guest
Jun 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function bisection(equation, a, b, tolerance) {
  2. let epsilon = 0.00001;
  3. let interaction = 0;
  4. self.equation = equation;
  5.  
  6. while ((b - a) > epsilon )
  7. {
  8. midpoint = math.eval((a + b) / 2);
  9.  
  10. y_m = solve(midpoint);
  11. console.log("ponto medio:" + midpoint);
  12. console.log("função sobre ponto médio:"+y_m);
  13. y_a = solve(a);
  14. console.log("ponto a:"+a);
  15. console.log("função sobre ponto a:" + y_a);
  16.  
  17. if ( (y_m > 0 && y_a < 0) || (y_m < 0 && y_a > 0) )
  18. {
  19. b = midpoint;
  20. }
  21. else
  22. {
  23. a = midpoint;
  24. }
  25. }
  26. return math.eval((a + b) / 2);
  27. }
  28.  
  29. function solve(value) {
  30. return math.eval(self.equation.replace(/[a-zA-Z]+/g, value));
  31. }
Add Comment
Please, Sign In to add comment