Métodos númericos
Enviado por basanchezb • 1 de Diciembre de 2019 • Ensayo • 11.065 Palabras (45 Páginas) • 162 Visitas
Programa 1
xi=0; xs=14; xr=0;
es=0.1; iter=1; bandera=100;
while bandera>es, xrold=xr;
fxi=(exp(-xi) ;
xr=(xi+xs)/2;
er=abs((xr-xrold)/xr)*(100);
printf('Iteracion = %2.0f xl= %2.5f xu= %2.5f xr= %2.5f er= %3.5f \n', iter, xi, xs, xr, er);
fxr=(xr)^(10) -1;
test=fxi*fxr; if test < 0 then xs=xr;
elseif test > 0 then xi=xr;
else break; end;
if er < es then bandera=er;
else iter=iter+1;
end;
end
Programa 2 de la regla falsa:
xi=0; xs=1; xr=0;
es=0.01; iter=1; bandera=100;
while bandera>es, xrold=xr;
fxs=(exp(-xs)-xs);
fxi=(exp(-xi)-xi);
xr=((xs*fxi)-(xi*fxs))/(fxi-fxs);
er=abs((xr-xrold)/xr)*(100);
printf('Iteracion = %2.0f xi= %2.5f xs= %2.5f xr= %2.5f er= %3.5f \n', iter, xi, xs, xr, er);
fxr=(exp(-xr)-xr);
test=fxi*fxr; if test < 0 then xs=xr;
elseif test > 0 then xi=xr;
else break; end;
if er < es then bandera=er;
else iter=iter+1;
end;
end
PROGRAMA 3 DE FALSA POSiCION
xi=0; xs=1.3; xr=0;
es=0.1; iter=1; bandera=100;
while bandera>;es, xrold=xr;
fxs=(xs)^(10) -1;
fxi=(xi)^(10) -1;
xr=(xs*fxi-xi*fxs)/(fxi-fxs);
er=abs((xr-xrold)/xr)*(100);
printf(‘;Iteracion = %2.0f xl= %2.5f xu= %2.5f xr= %2.5f er= %3.5f \n’;, iter, xi, xs, xr, er);
fxr=(xr)^(10) -1;
test=fxi*fxr; if test < 0 then xs=xr;
elseif test > 0 then xi=xr;
else break; end;
if er < es then bandera=er;
else iter=iter+1;
end;
end
PROGRAMA 4 DE FALSA POSICIÓN CON BISECCION
xi=0; xs=1.3; xr=0;
es=0.01; iter=1; bandera=100;
while bandera>es, xrold=xr; xr= ((xi+xs)/2)
er=abs((xr-xrold)/xr)*(100);
printf('Iteracion = %2.0f xi= %2.5f xs= %2.5f xr= %2.5f er= %3.5f \n', iter, xi, xs, xr, er);
fxr=((xr^(10))-1);
fxi=((xi^(10))-1);
test=fxi*fxr; if test < 0 then xs=xr;
elseif test > 0 then xi=xr;
else break; end;
if er < es then bandera=er;
else iter=iter+1;
end;
end
PROGRAMA 5 FALSA POSICION MODIFICADA
xl=0; xu=1.3; xr=0; fxl=0; fxu=0 ;fxr=0; imax=100; iu=0; il=0;
es=0.01; iter=1; bandera=100;
fxl= ((xl)^10)-1;
fxu= ((xu)^10)-1;
while bandera>es, xrold=xr;
xr=xu-fxu*(xl-xu)/(fxl-fxu);
fxr= ((xr)^10)-1;
er=abs((xr-xrold)/xr)*(100);
printf('Iteracion =%2.0f xi=%2.5f xs= %2.5f xr= %2.5f er= %3.5f \n', iter, xl, xu, xr, er);
test=fxl*fxr;
if test < 0 then
xu=xr;
fxu= ((xu)^10)-1;
iu=0;
il=il+1;
if il >= 2 then fxl=fxl/2;
end;
elseif test > 0 then
xl=xr;
fxl=((xl)^10)-1;
il=0;
iu=iu+1;
if iu>=2 then fxu= fxu/2;
end;
end;
if er < es then bandera=er;
else iter=iter+1;
end;
if iter >= imax then break;
end;
end
PROGRAMA 6 PUNTO FIJO
xr=0; iter=0; bandera=100; es=0.1;
while bandera>es, xrold=xr;
xr=exp(-xrold);
iter=iter + 1;
ea=abs(((xr-xrold)/xr))*100;
printf('iteracion=%2.0f xr=%2.5f xrold=%3.5f ea=%3.5f\n', iter , xr , xrold , ea);
if ea
end;
end
PROGRAMA 7 DE NEWTON-RAPHSON
xr=0; iter=0; bandera=100; es=0.1;
while bandera>es, xrold=xr;
xr=xrold -((exp(-xrold)- xrold)) /((-exp(-xrold)-1));
iter=iter + 1;
ea=abs(((xr-xrold)/xr))*100;
printf('iteracion=%2.0f xr=%2.5f xrold=%3.5f ea=%3.5f\n', iter , xr , xrold , ea);
if ea
end;
end
PROGRAMA 8 SECANTE
xr=0; iter=0; bandera=100; es=0.1;
xrold=1;
xr2old=0;
while bandera>es;
fxr2old=((exp(-xr2old))- xr2old);
fxrold=((exp(-xrold))-xrold);
xr=((xrold*fxr2old)-(xr2old*fxrold))/(fxr2old-fxrold);
...