Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bisection(equation, a, b, tolerance) {
- let epsilon = 0.00001;
- let interaction = 0;
- self.equation = equation;
- while ((b - a) > epsilon )
- {
- midpoint = math.eval((a + b) / 2);
- y_m = solve(midpoint);
- console.log("ponto medio:" + midpoint);
- console.log("função sobre ponto médio:"+y_m);
- y_a = solve(a);
- console.log("ponto a:"+a);
- console.log("função sobre ponto a:" + y_a);
- if ( (y_m > 0 && y_a < 0) || (y_m < 0 && y_a > 0) )
- {
- b = midpoint;
- }
- else
- {
- a = midpoint;
- }
- }
- return math.eval((a + b) / 2);
- }
- function solve(value) {
- return math.eval(self.equation.replace(/[a-zA-Z]+/g, value));
- }
Add Comment
Please, Sign In to add comment