Skip to content

Instantly share code, notes, and snippets.

@antonyalkmim
Last active April 5, 2016 13:16
Show Gist options
  • Save antonyalkmim/2b325f02fe95ce5a5e9e13ce6a1c7a66 to your computer and use it in GitHub Desktop.
Save antonyalkmim/2b325f02fe95ce5a5e9e13ce6a1c7a66 to your computer and use it in GitHub Desktop.
Método de aproximação Newton para encontrar raízes de equações
var calculateX = function(xInit){
var x = xInit;
var err = Math.pow(10,-5);
var xAux = x;
var i = 0;
do{
xAux = x;
var f = (Math.pow(x,4) + 2*Math.pow(x,3) - 13*Math.pow(x,2) - 14*x + 24).toFixed(5);
var F = (4*Math.pow(x,3) + 6*Math.pow(x,2) - 26*x - 14).toFixed(5);
x = (x - (f/F)).toFixed(5);
console.log(++i);
}while(err <= Math.abs(x-xAux).toFixed(7));
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment