0% found this document useful (0 votes)
25 views

Program As Libro

This document contains code for several numerical methods to solve nonlinear equations in MATLAB, including: 1. Fixed point method. Finds roots of equations with one variable using iterative fixed point method. 2. Newton-Raphson method. Finds roots of equations using Newton-Raphson iterative method. 3. Secant method. Finds roots of equations using secant method iterative approach. 4. Bisection method. Finds roots of equations using bisection method iterative approach. The document provides code examples to graph functions, apply each method, and check for convergence within a specified tolerance or maximum number of iterations. Various numerical methods are demonstrated for both real and complex equations.

Uploaded by

Jhon Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Program As Libro

This document contains code for several numerical methods to solve nonlinear equations in MATLAB, including: 1. Fixed point method. Finds roots of equations with one variable using iterative fixed point method. 2. Newton-Raphson method. Finds roots of equations using Newton-Raphson iterative method. 3. Secant method. Finds roots of equations using secant method iterative approach. 4. Bisection method. Finds roots of equations using bisection method iterative approach. The document provides code examples to graph functions, apply each method, and check for convergence within a specified tolerance or maximum number of iterations. Various numerical methods are demonstrated for both real and complex equations.

Uploaded by

Jhon Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

PROGRAMAS

ECUACIONES NO LINEALES

PUNTO FIJO:
disp('----------------------------------------------------------------
')
disp('METODO DEL PUNTO FIJO')
disp('SOLUCION DE ECUACIONES NO LINEALES CON UNA VARIABLE')
disp('----------------------------------------------------------------
')
disp('----------------------------------------------------------------
')
disp('SUBPROGRAMA PARA GRAFICAR LAS ECUACIONES NO LINEALES')
disp('=========================================')
syms x
a=input('ingrese intervalo inferior :');
e=input('ingrese espacios :');
b=input('ingrese intervalo inferior :');
x=[a:e:b];
y=input('ingrese f(x) :');
plot(x,y,'g')
title('GRAFICA DE LA FUNCION')
hold on
grid on
syms x
g(x)=input('ingrese la funcion despejada g(x) :');
%DATOS:
x0=input('ingrese valor inicial : ');
distancia=input('ingrese criterio de convergencia distancia : ');
maxima=input('ingrese el maximo numero de iteraciones : ');
i=1;
while i<=maxima
x=eval(g(x0));%hallando el x1(siguiente)
if abs(x-x0)<=distancia
disp([i-1 x])
end
i=i+1;
x0=x;%ACTUALIZANDO x
end
disp([i-1 x])

disp('================================================================
=')
disp('FINALIZA EL PROGRAMA')

disp('================================================================
=')

NEWTON-RAPHSON:
disp('----------------------------------------------------------------
--')
disp('METODO DE NEWTON-RAPHSON')
disp('----------------------------------------------------------------
--')
disp('----------------------------------------------------------------
')
disp('SUBPROGRAMA PARA GRAFICAR LAS ECUACIONES NO LINEALES')
disp('=========================================')
syms x
a=input('ingrese intervalo inferior :');
e=input('ingrese espacios :');
b=input('ingrese intervalo inferior :');
x=[a:e:b];
y=input('ingrese f(x) :');
plot(x,y,'b')
title('GRAFICA DE LA FUNCION')
hold on
grid on
disp('=========================================')
disp(' TERMINA ')
disp('=========================================')
disp('----------------------------------------------------------------
')
syms x
%f(x)=0
f(x)=input('ingrese la ecuacion :');
df(x)=diff(f(x));
%DATOS
x0=input('ingrese valor inicial :');
distancia=input('ingrese criterio de convergencia distancia : ');
maxima=input('ingrese maximo numero de iteraciones :');
i=1;
while i<maxima
x=x0-eval(f(x0))/eval(df(x0));%hallando el x1
if abs(x-x0)<distancia
disp([i-1 x]);
end
i=i+1;
x0=x;%actualizando
end
disp([i x])
disp('----------------------------------------------------------------
--')
disp('-----------------------------
FINALIZA-----------------------------')
disp('----------------------------------------------------------------
--')
SUBPROGRAMA PARA LOS GRAFICOS:
disp('=========================================')
disp('SUBPROGRAMA PARA GRAFICAR FUNCIONES ')
disp('=========================================')
syms x
a=input('ingrese intervalo inferior :');
e=input('ingrese espacios :');
b=input('ingrese intervalo inferior :');
x=a:e:b;
y=input('ingrese f(x) :');
plot(x,y,'r')
title('GRAFICA DE LA FUNCION')
disp('=========================================')
disp(' TERMINA ')
disp('=========================================')

METODO DE LA SECANTE:
clc
disp('----------------------------------------------------------------
')
disp('METODO DE LA SECANTE')
disp('----------------------------------------------------------------
')
disp('f(x)=0')
disp('----------------------------------------------------------------
')
disp('SUBPROGRAMA PARA GRAFICAR LAS ECUACIONES NO LINEALES')
disp('================================================================
')
syms x
a=input('ingrese intervalo inferior :');
e=input('ingrese espacios :');
b=input('ingrese intervalo superior :');
x=[a:e:b];
y=input('ingrese f(x) :');
plot(x,y,'g+')
title('GRAFICA DE LA FUNCION')
hold on
grid on
disp('================================================================
===')
syms x
f(x)=input('ingrese la ecuacion o funcion:');
x0=input('valor inicial 1: ');
x1=input('valor inicial 2: ');
dist=input('valor de distancia :');
eps1=input('valor de exactitud :');
maxit=input('maximo iteraciones: ');
i=1;
while i<maxit
x=x0-(x1-x0)*eval(f(x0))/(eval(f(x1))-eval(f(x0)));
if abs(x-x1)<dist
disp(x)
end
if abs(f(x))<eps1
disp(x)
end
x0=x1;
x1=x;
i=i+1;
end

METODO DE LA FALSA POSICION


disp('0000000000000000000000000000000000000000000000000000000000000000
000')
disp('METODO DE LA FALSA POSICION')
disp('0000000000000000000000000000000000000000000000000000000000000000
000')
syms x
f(x)=input('ingrese la ecuacion o funcion:');
xi=input('ingrese xizq');
xd=input('ingrese xder');
dist=input('ingrese criterio de distancia:');
eps1=input('ingrese criterio de exactitud:');
max=input('ingrese iteraciones como maximo:');
i=1;
fi=eval(f(xi));
fd=eval(f(xd));
while i<max
xm=(xi*fd-xd*fi)/(fd-fi);
fm=eval(f(xm));
if abs(fm)<eps1
disp(xm)
end
if abs(xd-xi)<dist
xm=(xd+xi)/2;
fprintf('la raiz es:')
disp(xm)
end
if fd*fm>0
xd=xm;
fd=fm;
end
if fd*fm<0
xi=xm;
fi=fm;
end
i=i+1;
end
disp('0000000000000000000000000000000000000000000000000000000000000000
000')
disp(' FINALIZA
')
disp('0000000000000000000000000000000000000000000000000000000000000000
000')

METODO DE LA BISECCION
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
disp('METODO DE LA BISECCION')
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
syms x
f(x)=input('ingrese la ecuacion o funcion:');
xi=input('ingrese xizq:');
xd=input('ingrese xder:');
dist=input('ingrese criterio de distancia:');
eps1=input('ingrese criterio de exactitud:');
a=xd-xi;
max=(log(a)-log(dist))/log(2);
i=1;
fi=eval(f(xi));
fd=eval(f(xd));
while i<max
xm=(xi+xd)/2;
fm=eval(f(xm));
if abs(fm)<eps1
disp(xm)
end
if abs(xd-xi)<dist
xm=(xd+xi)/2;
fprintf('la raiz es:')
disp(xm)
end
if fd*fm>0
xd=xm;
fd=fm;
end
if fd*fm<0
xi=xm;
fi=fm;
end
i=i+1;
disp(xm)
end
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
disp(' FINALIZA
')
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')

ACELERACION DE CONVERGENCIA MEDIANTE AITKEN


disp('ACELERACION DE CONVERGENCIA MEDIANTE AITKEN')
format long
x0=input('colocar el valor inicial:');
x1=input('ingrese segundo valor:');
x2=input('ingrese tercer valor:');
eps=input('colocar el criterio de convergencia:');
n=input('ingrese hasta que iteracion se desarrollara este programa:');
for i=1:n
x=x0-(x1-x0)^2/(x2-2*x1+x0);
dist=abs(x-x0);
disp(x)
if dist<eps
break
end
x0=x;
end
disp('----------------------------------------------------------------
')
disp('------------------------------
FIN-------------------------------')
disp('----------------------------------------------------------------
')

ACELERACION DE CONVERGENCIA MEDIANTE STEFFENSEN


disp('--------------------------------------------------------------')
disp('ACELERACION DE CONVERGENCIA MEDIANTE METODO DE STEFFENSEN')
disp('-------------------------------------------------------------')
syms x
g(x)=input('ingrese la funcion despejada g(x):');
x0=input('ingrese el valor inicial:');
dist=input('ingrese criterio de convergencia de distancia:');
max=input('ingrese maximo numero de iteraciones:');
i=1;
while i<max
x1=eval(g(x0));
x2=eval(g(x1));
x=x0-(x1-x0)^2/(x2-2*x1+x0);
if abs(x-x0)<dist
disp(x)
end
i=i+1;
x0=x;%actualizando x
end
fprintf('EL ULTIMO')
disp('--------------------------------------------------------------')
disp('------------------------------FIN-----------------------------')
disp('--------------------------------------------------------------')

ACELERACION DE CONVERGENCIA MEDIANTE ILLINOIS


disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
disp('ACELERACION DE CONVERGENCIA MEDIANTE EL METODO DE ILLINOIS')
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
syms x
f(x)=input('ingrese la ecuacion o funcion:');
xi=input('ingrese xizq:');
xd=input('ingrese xder:');
dist=input('ingrese criterio de distancia:');
eps1=input('ingrese criterio de exactitud:');
max=input('ingrese iteraciones como maximo:');
i=1;
fi=eval(f(xi));
fd=eval(f(xd));
while i<max
xm=(xi*fd-xd*fi)/(fd-fi);
fm=eval(f(xm));
if abs(fm)<eps1
disp(xm)
end
if abs(xd-xi)<dist
xm=(xd+xi)/2;
disp(xm)
end
if fd*fm>0
xd=xi;
fd=fi;
end
if fd*fm<0
fd=fd/2;
xi=xm;
f0=fm;
end
i=i+1;
end
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
disp(' FIN
')
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')

METODO DE NEWTON RAPHSON PARA COMPLEJOS


disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
disp('NEWTON-RAPHSON PARA COMPLEJOS')
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
%dar como valor inicial el complejo: 1i
syms x
%f(x)=0
f(x)=input('ingrese la ecuacion :');
df(x)=diff(f(x));
%DATOS
x0=input('ingrese valor inicial :');
distancia=input('ingrese criterio de convergencia distancia : ');
maxima=input('ingrese maximo numero de iteraciones :');
i=1;
while i<maxima
x=x0-eval(f(x0))/eval(df(x0));%hallando el x1
if abs(x-x0)<distancia
disp(x);
end
i=i+1;
x0=x;%actualizando
end
disp(x)
disp('----------------------------------------------------------------
--')
disp('-----------------------------
FINALIZA-----------------------------')
disp('----------------------------------------------------------------
--')

METODO DE MULLER
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
disp('METODO DE MULLER')
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
eps=0.00001;eps1=0.000001;
f(x)=input('ingrese la funcion o ecuacion:');
x0=input('ingrese primer valor inicial:');
x1=input('ingrese segundo valor inicial:');
x2=input('ingrese tercer valor inicial:');
n=input('ingrese numero de iteraciones:');
for i=1:n
f0=eval(f(x0));
f1=eval(f(x1));
f2=eval(f(x2));
f10=(f1-f0)/(x1-x0);
f21=(f2-f1)/(x2-x1);
f210=(f21-f10)/(x2-x0);
a2=f210;
a1=f21-(x2+x1)*a2;
a0=f2-x2*(f21-x1*a2);
d1=-a1+(a1^2-4*a0*a2)^.5;
d2=-a1-(a1^2-4*a0*a2)^.5;
if abs (d1)>abs(d2)
x3=2*a0/d1;
else
x3=2*a0/d2;
end
f3=eval(f(x3));
dist=abs(x3-x2);
disp([x3 dist])
if or((dist<eps),(abs(f3)<eps1))
break
else
x0=x1;x1=x2;x2=x3;
end
end
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')
disp('------------------------------FIN-----------------------------')
disp('<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
')

SISTEMAS DE ECUACIONES LINEALES

You might also like