Skip to content

Instantly share code, notes, and snippets.

@Reflej0
Last active April 29, 2017 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reflej0/97daef42826a914db1f2e0621138d631 to your computer and use it in GitHub Desktop.
Save Reflej0/97daef42826a914db1f2e0621138d631 to your computer and use it in GitHub Desktop.
Algoritmo de Newton Raphson de Cálculo Numérico en Scilab.
function [raizaproximada, iteraciones] = newton(funcion, aproximacioninicial, Tolerancia, Iteracionesmaximas)
aprox= aproximacioninicial;
while 1
raizaproximada = aprox - funcion(aprox)/numderivative(funcion, aprox);
errorabsoluto = abs((raizaproximada-aprox)/raizaproximada)*100;
aprox = raizaproximada;
iteraciones = iteraciones + 1;
if(errorabsoluto < Tolerancia | iteraciones == Iteracionesmaximas ) then
break
end
end
endfunction
//Datos
function y = primera(x)
y = %e^x + 2^-x + 2*cos(x) - 6;
endfunction
A = 1;
B = 2;
Tolerancia = 0.00001;
Iteracionesmaximas = 100;
[raizaproximada, iteraciones] = newton(primera, A-B, Tolerancia, Iteracionesmaximas)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment