Muller Newton-Raphson editor
Enviado por wbda • 13 de Junio de 2013 • Trabajo • 413 Palabras (2 Páginas) • 555 Visitas
MULLER NEWTON-RAPHSON
EDITOR
function raiz=NewtonRaphson(f,fderiv,x)
error=0.0005;
maxiter=50;
k=0;
fprintf('%5d%15.10f\n',k,x);
while 1
x0=x;
x=x0-f(x0)/fderiv(x0);
k=k+1;
fprintf('%5d%15.10f\n',k,x);
if (abs(x-x0)<=error || k==maxiter)
break
end
end
if k<maxiter
raiz=x;
end
VENTANA DE COMANDOS
3. Resuelva las siguientes ecuaciones aplicando el método de Newton-Raphson:
a) x3-5x2+25x -2=0
>> f=inline('(x^3)-(5.*(x^2))+(25*x)-2')
f =
Inline function:
f(x) = (x^3)-(5.*(x^2))+(25*x)-2
>> fderiv=inline('(3*x^2)-(10*x)+25')
fderiv =
Inline function:
fderiv(x) = (3*x^2)-(10*x)+25
>> NewtonRaphson(f,fderiv,1)
0 1.0000000000
1 -0.0555555556
2 0.0776154641
3 0.0812977895
4 0.0813004578
ans =
0.0813
>>
b) x2-4x+1=0
>> f=inline('x^2-4*x+1')
f =
Inline function:
f(x) = x^2-4*x+1
>> fderiv=inline('2*x-4')
fderiv =
Inline function:
fderiv(x) = 2*x-4
>> NewtonRaphson(f,fderiv,5)
0 5.0000000000
1 4.0000000000
2 3.7500000000
3 3.7321428571
4 3.7320508100
ans =
3.7321
c) x4-4x3+6x+4=0
>> f=inline('(x^4)-(4.*(x^3))+(6*x)+4')
f =
Inline function:
f(x) = (x^4)-(4.*(x^3))+(6*x)+4
>> fderiv=inline('(4.*(x^3))-(12.*(x^2))+6')
fderiv =
Inline function:
fderiv(x) = (4.*(x^3))-(12.*(x^2))+6
>> NewtonRaphson(f,fderiv,1)
0 1.0000000000
1 4.5000000000
2 3.8995098039
3 3.5463970753
4 3.3957035576
5 3.3663077676
6 3.3652314310
7 3.3652300134
ans =
3.3652
>>
d) 24x3+12x2+2x+1=0
>> f=inline('(24.*(x^3))+(12.*(x^2))+(2*x)+1')
f =
Inline function:
f(x) = (24.*(x^3))+(12.*(x^2))+(2*x)+1
...