Professional Documents
Culture Documents
“ejercicios resueltos”
INDICE
1. DEDICATORIA .......................................................................................................................................... 3
2. INTRODUCCION ....................................................................................................................................... 4
3. PORTADAS DELOS 2 LIBROS USADOS .................................................................................................... 5
4. RESOLUCION DE EJERCICIOS ................................................................................................................... 7
4.1. ECUACIONES NO LINEALES
4.2. ECUACIONES LINEALES
4.3. EIGEN VALORES (VALORES PROPIOS)
4.4. APROXIMACION FUNCIONAL
4.5. INTERPOLACION
4.6. INTEGRACION,DIFERENCIACION
4.7. ECUACIONES DIFERENCIALES ORDINARIAS
4.8. ECUACIONES DIFERENCIALES PARCIALES
5. ANEXO DEL PROGRAMA USADO PARA LA RESOLUCION DE EJERCICIOS “MATLAB” .......................... 182
DEDICATORIA
Primeramente a dios por habernos permitido llegar hasta este punto y habernos dado salud,
darnos lo necesario para seguir adelante día a día para lograr nuestros objetivos.
A nuestros familiares por habernos apoyado en todo momento, por sus consejos, sus valores,
por la motivación constante que nos ha permitido ser personas de bien, pero más que nada.
A nuestra universidad por su gran apoyo y motivación para la culminación de nuestros estudios
profesionales, por su apoyo ofrecido en este trabajo, por habernos transmitidos los
conocimientos obtenidos y habernos llevado pasó a paso en el aprendizaje.
INTRODUCCION
El planeta Urano fue descubierto en 1781 por un inteligente astrónomo aficionado, Willeam
Herschel (1738 – 1822), con un telescopio de frabricación casera. Teniendo en cuenta las leyes
de Kepler, la prevista órbita de Urano fue rápidamente calculada a partir de unas pocas
observaciones muy separadas entre sí. Se encontró que la distancia media de Urano al Sol era
aproximadamente el doble que la de Saturno y que una órbita completa requería 84 años. En
1830 los datos empíricos acumulados pusieron de manifiesto desviaciones inexplicables de la
órbita prevista. Algunos astrónomos llegaron a pensar que la ley de gravitación universal de
Newton no fuera válida para distancias tan grandes como la de Urano al Sol; otros
sospecharon que las perturbaciones fueran debidas a un cometa aún no descubierto o a un
planeta más lejano. Un estudiante de bachillerato de la Universidad de Cambridge, John Couch
Adams (1819 – 1892), estaba intrigado por la posibilidad de un planeta desconocido. Se asignó
la difícil tares de calcular la influencia de un tal planeta en las posiciones observadas de Urano,
suponiendo válida la ley de gravitación de Newton. Completó su Texto integro transcrito del
libro de Apostol; Calculus, vol 2.
El cálculo en series empezó a florecer hacia fines del siglo XVII, con el desarrollo del cálculo. A
principios del siglo XVIII Jacob Stirling y Brook Taylor sentaron los fundamentos del cálculo de
diferencias finitas, que ahora desempeña un papel central en el análisis numérico. Con la
predicción de la existencia y la localización del planeta Neptuno por Adam y Leverrier en 1845,
la importancia cinetífica del análisis numérico quedó establecida de una vez y para siempre. A
fines del siglo XIX, el empleo de las máquinas de cálculo atomático estimuló más aún el
desarrolllo del análisis numérico. Tal desarrollo ha sido explosivo desde la terminación de la
Segunda Guerra Mundial a causa del progreso en las máquinas de cálculo electrónicas de alta
velocidad.
ECUACIONES NO LINEALES
PSEUDOCODIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE BISECCIÓN
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-5;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=(a+b)/2;
disc=F(x)*F(a);
if disc<eps
xf=x;
elseif disc>eps
x0=x;
end
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCION
METODO DE LA SECANTE
PSEUDOCODIGO SECANTE
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE SECANTE
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=a-(b-a)*F(a)/(F(b)-F(a));
x0=xf;
xf=x;
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN:
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE FALSA POSICIÓN
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=(a*F(b)-b*F(a))/(F(b)-F(a));
disc=F(x)*F(a);
if disc<eps
xf=x;
elseif disc>eps
x0=x;
end
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN:
MÉTODO DE MULLER
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE MÜLLER
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el los valores iniciales:\n')
ab=input('\n[a,b,c] = ');
x0=ab(1);
x1=ab(2);
x2=ab(3);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
h0=x1-x0;
h1=x2-x1;
d0=(F(x1)-F(x0))/h0;
d1=(F(x2)-F(x1))/h1;
a=(d1-d0)/(h1+h0);
b=a*h1+d1;
c=F(x2);
rad=sqrt(b^2-4*a*c);
if abs(b+rad)>abs(b-rad)
den=b+rad;
else
den=b-rad;
end
dxr=-2*c/den;
x=x2+dxr;
error=abs(dxr)/x;
x0=x1;
x1=x2;
x2=x;
I=I+1;
mat(I-1,:)=[x F(x) error*100];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter x F(x) error(%)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE NEWTON RAPHSON
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el valor inicial:\n')
x0=input('\nXo = ');
I=1;
error=1;
eps=1e-7;
maxit=31;
h=0.1; %paso para diferencias finitas
while error>eps & I<maxit
a=x0;
% diferencias finitas hacia adelante
Xad=[a+h a+2*h a+3*h a+4*h a+5*h];
dF=(-F(Xad(2))+4*F(Xad(1))-3*F(a))/(2*h);
x=a-F(a)/dF;
xad=x0;
x0=x;
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) dF x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter x0 F(x0) dF(x0) x F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
CONCLUSIÓN
Comparando los 5 metodos, primero podemos ver que el método de muller es menos efectivo
dado que no se acerca o converge mucho a la verdadera solución, luego; a pesar de que el
método de bisección tiene varias iteraciones, nos da un valor un tanto menos cercano a los
demás, finalmente vemos que el método de newton raphson, secante y muller nos arrojan
prácticamente los mismos valores, afirmando que los mas efectivos serian estos tres, no
obstante se toman en cuenta los errores con los que trabaja cada método, considerando esto
se puede decir que el método de newton raphson es el mas eficaz, pero reiterando que los tres
métodos mencionados anteriormente tambien son eficientes.
MÉTODO DE BISECCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE BISECCIÓN
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-5;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=(a+b)/2;
disc=F(x)*F(a);
if disc<eps
xf=x;
elseif disc>eps
x0=x;
end
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
METODO DE LA SECANTE
PSEUDOCODIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE SECANTE
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=a-(b-a)*F(a)/(F(b)-F(a));
x0=xf;
xf=x;
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE FALSA POSICIÓN
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=(a*F(b)-b*F(a))/(F(b)-F(a));
disc=F(x)*F(a);
if disc<eps
xf=x;
elseif disc>eps
x0=x;
end
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
MÉTODO DE MULLER
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE MÜLLER
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el los valores iniciales:\n')
ab=input('\n[a,b,c] = ');
x0=ab(1);
x1=ab(2);
x2=ab(3);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
h0=x1-x0;
h1=x2-x1;
d0=(F(x1)-F(x0))/h0;
d1=(F(x2)-F(x1))/h1;
a=(d1-d0)/(h1+h0);
b=a*h1+d1;
c=F(x2);
rad=sqrt(b^2-4*a*c);
if abs(b+rad)>abs(b-rad)
den=b+rad;
else
den=b-rad;
end
dxr=-2*c/den;
x=x2+dxr;
error=abs(dxr)/x;
x0=x1;
x1=x2;
x2=x;
I=I+1;
mat(I-1,:)=[x F(x) error*100];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter x F(x) error(%)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE NEWTON RAPHSON
')
disp('================================================================
======')
syms ('x')
SOLUCIÓN
CONCLUSIÓN
Utilizando estos 5 metodos y Comparandolos, primero podemos ver que en este caso el
método de bisección es el menos efectivo dado que no se acerca o converge mucho a la
verdadera solución, luego; el metodod de muller tampoco se acerca mucho a lo encontrado
con otros métodos, finalmente vemos que el método de newton raphson, secante y falsa
posicion nos arrojan soluciones muy cercanas , pero concluyendo que los mas efectivos serian
secante y newton raphson, no obstante se toman en cuenta los errores con los que trabaja
cada método, considerando esto nos podemos inclinar por el método de newton raphson que
seria el mas eficaz, dado que requiere menos iteraciones y el error es casi 0, de todas maneras
el método de la secante también es muy eficaz.
MÉTODO DE LA BISECCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE BISECCIÓN
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-5;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=(a+b)/2;
disc=F(x)*F(a);
if disc<eps
xf=x;
elseif disc>eps
x0=x;
end
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
MÉTODO DE LA SECANTE
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE SECANTE
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=a-(b-a)*F(a)/(F(b)-F(a));
x0=xf;
xf=x;
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE FALSA POSICIÓN
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el intervalo de valores iniciales:\n')
ab=input('\n[a,b] = ');
x0=ab(1);
xf=ab(2);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
a=x0;
b=xf;
x=(a*F(b)-b*F(a))/(F(b)-F(a));
disc=F(x)*F(a);
if disc<eps
xf=x;
elseif disc>eps
x0=x;
end
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) b F(b) x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter a F(a) b F(b) x
F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
MÉTODO DE MULLER
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE MÜLLER
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el los valores iniciales:\n')
ab=input('\n[a,b,c] = ');
x0=ab(1);
x1=ab(2);
x2=ab(3);
I=1;
error=1;
eps=1e-7;
maxit=31;
while error>eps & I<maxit
h0=x1-x0;
h1=x2-x1;
d0=(F(x1)-F(x0))/h0;
d1=(F(x2)-F(x1))/h1;
a=(d1-d0)/(h1+h0);
b=a*h1+d1;
c=F(x2);
rad=sqrt(b^2-4*a*c);
if abs(b+rad)>abs(b-rad)
den=b+rad;
else
den=b-rad;
end
dxr=-2*c/den;
x=x2+dxr;
error=abs(dxr)/x;
x0=x1;
x1=x2;
x2=x;
I=I+1;
mat(I-1,:)=[x F(x) error*100];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter x F(x) error(%)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
======')
disp(' MÉTODO DE NEWTON RAPHSON
')
disp('================================================================
======')
syms ('x')
fprintf('\nIngrese la función en términos de x:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el intervalo para graficar la función:\n')
xif=input('\n[Xo,Xf] = ');
xx=xif(1):0.1:xif(2);
Fxx=F(xx);
plot(xx,Fxx,'b','LineWidth',2)
grid on
fprintf('\nIngrese el valor inicial:\n')
x0=input('\nXo = ');
I=1;
error=1;
eps=1e-7;
maxit=31;
h=0.1; %paso para diferencias finitas
while error>eps & I<maxit
a=x0;
% diferencias finitas hacia adelante
Xad=[a+h a+2*h a+3*h a+4*h a+5*h];
dF=(-F(Xad(2))+4*F(Xad(1))-3*F(a))/(2*h);
x=a-F(a)/dF;
xad=x0;
x0=x;
error=abs(F(x));
I=I+1;
mat(I-1,:)=[a F(a) dF x F(x)];
end
[fil col]=size(mat);
iter=1:fil;
mat=[iter' mat];
disp(' ')
disp(' TABLA DE ITERACIONES
')
disp(' iter x0 F(x0) dF(x0) x F(x)')
disp(mat)
fprintf(' Solución aproximada: x = %11.8f \n',x);
fprintf(' con F(x) = %12.8f\n',F(x));
SOLUCIÓN:
CONCLUSIÓN
Utilizando estos 5 metodos y Comparandolos, esta vez se ve que los 5 nos dan una solución
reltivamente cercana, pero diremos que la menos efectiva fue la de bisección, luego los 4
metodos restantes nos dieron una solución prácticamente igual, pero dado al error y el
numero de iteraciones las mas efectivas fueron la de muller y la de newton raphson,
considerando también el método de la secante, finalmente podemos afirmar que el de muller
esta vez fue el mas efectivo, claro considerando la diferencia casi nula en la solución con los
métodos de newton raphson y secante.
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE NEWTON-RAPHSON PARA SISTEMAS
')
disp('================================================================
===')
syms x
fprintf('\nIngrese el número de ecuaciones:\n')
N=input('\nN = ');
SOLUCIÓN
CONCLUSIÓN
Se utilizo este metodo porque es el mas conveniente dada la cantidad de iteraciones que hace
y el error con el que trabaja además de que es el mas eficiente para la obtención de las
soluciones dado que también utiliza el jacobiano para los cálculos.
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE NEWTON-RAPHSON PARA SISTEMAS
')
disp('================================================================
===')
syms x
fprintf('\nIngrese el número de ecuaciones:\n')
N=input('\nN = ');
SOLUCIÓN
CONCLUSIÓN
Nuevamente se utilizo este metodo porque es el mas conveniente además esta vez se trataba
de un sistema de ecuaciones no lineales mas complejo que el anterior, dada la cantidad de
iteraciones que hace y el error con el que trabaja es el mas eficiente para la obtención de las
soluciones dado que también utiliza el jacobiano para los cálculos.
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE NEWTON-RAPHSON PARA SISTEMAS
')
disp('================================================================
===')
syms x
fprintf('\nIngrese el número de ecuaciones:\n')
N=input('\nN = ');
SOLUCIÓN
CONCLUSIÓN
Para este ejercicio también se empleo el metodo de newton raphson para sistemas dado que
es el más apropiado por el numeo de iteraciones que realiza y su cercanía a las soluciones
esperadas, además utiliza el jacobiano para los cálculos.
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE ELIMINACIÓN GAUSSIANA
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
for k=1:N-1
for m=k+1:N
MT=-A(m,k)/A(k,k);
A(m,:)=A(m,:)+MT*A(k,:);
B(m)=B(m)+MT*B(k);
end
end
x(N)=B(N)/A(N,N);
for k=N-1:-1:1
ind=N-k;
x(k)=0;
for m=1:ind
x(k)=x(k)-A(k,k+m)*x(k+m);
end
x(k)=(B(k)+x(k))/A(k,k);
end
disp(' ')
disp(' RAÍCES')
disp(x')
SOLUCIÓN
MÉTODO DE GAUSS-JORDAN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE GAUSS-JORDAN
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
for k=1:N
B(k)=B(k)/A(k,k);
A(k,:)=A(k,:)/A(k,k);
for m=1:N
if m~=k
MT=-A(m,k);
A(m,:)=A(m,:)+MT*A(k,:);
B(m)=B(m)+MT*B(k);
end
end
end
x=B;
disp(' ')
disp(' RAÍCES')
disp(x)
SOLUCIÓN
MÉTODO DE FACTORIZACIÓN LU
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE FACTORIZACIÓN LU
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
U=A;
for I=1:N-1
for J=I+1:N
MT=-U(J,I)/U(I,I);
U(J,:)=U(J,:)+MT*U(I,:);
end
end
L=eye(N);
L(2:N,1)=A(2:N,1)/U(1,1);
for I=2:N-1
for J=I+1:N
MT=0;
for k=1:I-1
MT=MT-L(J:N,k).*U(k,I);
end
L(J:N,I)=(A(J:N,I)+MT)./U(I,I);
end
end
aux(1)=B(1);
for k=2:N
ind=k-1;
aux(k)=0;
for m=1:ind
aux(k)=aux(k)-L(k,k-m)*aux(k-m);
end
aux(k)=B(k)+aux(k);
end
x(N)=aux(N)/U(N,N);
for k=N-1:-1:1
ind=N-k;
x(k)=0;
for m=1:ind
x(k)=x(k)-U(k,k+m)*x(k+m);
end
x(k)=(aux(k)+x(k))/U(k,k);
end
disp(' ')
disp(' RAÍCES')
disp(x')
SOLUCIÓN
MÉTODO DE JACOBI
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE JACOBI
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
fprintf('\nIngrese el vector de valores iniciales\n')
fprintf('\nXo = \n')
x0=input('');
eps=1e-4;
maxit=31;
N=length(B);
DA=diag(A);
D=diag(DA);
A=A-D;
M=-inv(D)*A;
h=inv(D)*B;
x(:,1)=x0;
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 55
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
error=1;
J=2;
while error>eps & J<maxit
x(:,J)=M*x(:,J-1)+h;
error=max(abs(x(:,J)-x(:,J-1)));
J=J+1;
end
nit=J-2;
disp(' ')
disp(' TABLA DE ITERACIONES')
disp(x')
disp(' RAÍCES')
disp(x(:,nit+1)')
SOLUCIÓN
MÉTODO DE GAUSS-SEIDEL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE GAUSS-SEIDEL
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
fprintf('\nIngrese el vector de valores iniciales\n')
fprintf('\nXo = \n')
x0=input('');
eps=1e-4;
maxit=31;
N=length(B);
DA=diag(A);
D=diag(DA);
A=A-D;
for I=1:N
L(I:N,I)=A(I:N,I);
U(I,I:N)=A(I,I:N);
end
M=-inv(D+L)*U;
h=inv(D+L)*B;
x(:,1)=x0;
error=1;
J=2;
while error>eps & J<maxit
x(:,J)=M*x(:,J-1)+h;
error=max(abs(x(:,J)-x(:,J-1)));
J=J+1;
end
nit=J-2;
disp(' ')
disp(' TABLA DE ITERACIONES')
disp(x')
disp(' RAÍCES')
disp(x(:,nit+1)')
SOLUCIÓN
CONCLUSIÓN
Comparando los 5 metodos, primero podemos ver que el método de JACOBI a pesar de tantas
iteraciones no muestra soluciones relativamente iguales a la de los otros métodos empleados,
luego se ve también que los otros 4 metodos restantes arrojan las mismas soluciones, siendo
el método de GAUSS SEIDEL el que emplea mas iteraciones en comparación con los métodos
restantes, los 4 metodos resultan eficaces, pero reiterando que todos los métodos
mencionados anteriormente son eficientes.
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE ELIMINACIÓN GAUSSIANA
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
for k=1:N-1
for m=k+1:N
MT=-A(m,k)/A(k,k);
A(m,:)=A(m,:)+MT*A(k,:);
B(m)=B(m)+MT*B(k);
end
end
x(N)=B(N)/A(N,N);
for k=N-1:-1:1
ind=N-k;
x(k)=0;
for m=1:ind
x(k)=x(k)-A(k,k+m)*x(k+m);
end
x(k)=(B(k)+x(k))/A(k,k);
end
disp(' ')
disp(' RAÍCES')
disp(x')
SOLUCIÓN
MÉTODO DE GAUSS-JORDAN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE GAUSS-JORDAN
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
for k=1:N
B(k)=B(k)/A(k,k);
A(k,:)=A(k,:)/A(k,k);
for m=1:N
if m~=k
MT=-A(m,k);
A(m,:)=A(m,:)+MT*A(k,:);
B(m)=B(m)+MT*B(k);
end
end
end
x=B;
disp(' ')
disp(' RAÍCES')
disp(x)
SOLUCIÓN
MÉTODO DE FACTORIZACIÓN LU
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE FACTORIZACIÓN LU
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
U=A;
for I=1:N-1
for J=I+1:N
MT=-U(J,I)/U(I,I);
U(J,:)=U(J,:)+MT*U(I,:);
end
end
L=eye(N);
L(2:N,1)=A(2:N,1)/U(1,1);
for I=2:N-1
for J=I+1:N
MT=0;
for k=1:I-1
MT=MT-L(J:N,k).*U(k,I);
end
L(J:N,I)=(A(J:N,I)+MT)./U(I,I);
end
end
aux(1)=B(1);
for k=2:N
ind=k-1;
aux(k)=0;
for m=1:ind
aux(k)=aux(k)-L(k,k-m)*aux(k-m);
end
aux(k)=B(k)+aux(k);
end
x(N)=aux(N)/U(N,N);
for k=N-1:-1:1
ind=N-k;
x(k)=0;
for m=1:ind
x(k)=x(k)-U(k,k+m)*x(k+m);
end
x(k)=(aux(k)+x(k))/U(k,k);
end
disp(' ')
disp(' RAÍCES')
disp(x')
SOLUCIÓN
CONCLUSIÓN
Esta vez se utilizo tres métodos diferentes, resultando las mismas soluciones por estos tres
métodos en este caso diremos que los tres métodos (eliminacion Gaussiana, Gauss Jordan y
factorizaion LU) convergen en una misma solución la cual comparándola con el libro es muy
cercana.
MÉTODO DE JACOBI
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE JACOBI
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
fprintf('\nIngrese el vector de valores iniciales\n')
fprintf('\nXo = \n')
x0=input('');
eps=1e-4;
maxit=31;
N=length(B);
DA=diag(A);
D=diag(DA);
A=A-D;
M=-inv(D)*A;
h=inv(D)*B;
x(:,1)=x0;
error=1;
J=2;
while error>eps & J<maxit
x(:,J)=M*x(:,J-1)+h;
error=max(abs(x(:,J)-x(:,J-1)));
J=J+1;
end
nit=J-2;
disp(' ')
disp(' TABLA DE ITERACIONES')
disp(x')
disp(' RAÍCES')
disp(x(:,nit+1)')
SOLUCIÓN
MÉTODO DE GAUSS-SEIDEL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE GAUSS-SEIDEL
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
fprintf('\nIngrese el vector de valores iniciales\n')
fprintf('\nXo = \n')
x0=input('');
eps=1e-4;
maxit=31;
N=length(B);
DA=diag(A);
D=diag(DA);
A=A-D;
for I=1:N
L(I:N,I)=A(I:N,I);
U(I,I:N)=A(I,I:N);
end
M=-inv(D+L)*U;
h=inv(D+L)*B;
x(:,1)=x0;
error=1;
J=2;
while error>eps & J<maxit
x(:,J)=M*x(:,J-1)+h;
error=max(abs(x(:,J)-x(:,J-1)));
J=J+1;
end
nit=J-2;
disp(' ')
disp(' TABLA DE ITERACIONES')
disp(x')
disp(' RAÍCES')
disp(x(:,nit+1)')
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE ELIMINACIÓN GAUSSIANA
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
for k=1:N-1
for m=k+1:N
MT=-A(m,k)/A(k,k);
A(m,:)=A(m,:)+MT*A(k,:);
B(m)=B(m)+MT*B(k);
end
end
x(N)=B(N)/A(N,N);
for k=N-1:-1:1
ind=N-k;
x(k)=0;
for m=1:ind
x(k)=x(k)-A(k,k+m)*x(k+m);
end
x(k)=(B(k)+x(k))/A(k,k);
end
disp(' ')
disp(' RAÍCES')
disp(x')
SOLUCIÓN
MÉTODO DE GAUSS-JORDAN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE GAUSS-JORDAN
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
for k=1:N
B(k)=B(k)/A(k,k);
A(k,:)=A(k,:)/A(k,k);
for m=1:N
if m~=k
MT=-A(m,k);
A(m,:)=A(m,:)+MT*A(k,:);
B(m)=B(m)+MT*B(k);
end
end
end
x=B;
disp(' ')
disp(' RAÍCES')
disp(x)
SOLUCIÓN
MÉTODO DE FACTORIZACIÓN LU
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE FACTORIZACIÓN LU
')
disp('================================================================
===')
fprintf('\nIngrese la matriz de coeficientes:\n')
fprintf('\nA = \n')
A=input('');
fprintf('\nIngrese el vector de términos independientes:\n')
fprintf('\nB = \n')
B=input('');
eps=1e-4;
maxit=31;
N=length(B);
U=A;
for I=1:N-1
for J=I+1:N
MT=-U(J,I)/U(I,I);
U(J,:)=U(J,:)+MT*U(I,:);
end
end
L=eye(N);
L(2:N,1)=A(2:N,1)/U(1,1);
for I=2:N-1
for J=I+1:N
MT=0;
for k=1:I-1
MT=MT-L(J:N,k).*U(k,I);
end
L(J:N,I)=(A(J:N,I)+MT)./U(I,I);
end
end
aux(1)=B(1);
for k=2:N
ind=k-1;
aux(k)=0;
for m=1:ind
aux(k)=aux(k)-L(k,k-m)*aux(k-m);
end
aux(k)=B(k)+aux(k);
end
x(N)=aux(N)/U(N,N);
for k=N-1:-1:1
ind=N-k;
x(k)=0;
for m=1:ind
x(k)=x(k)-U(k,k+m)*x(k+m);
end
x(k)=(aux(k)+x(k))/U(k,k);
end
disp(' ')
disp(' RAÍCES')
disp(x')
SOLUCIÓN
CONCLUSIÓN
Comparando los 5 metodos, primero podemos ver que el método de JACOBI a pesar de tantas
iteraciones no muestra soluciones relativamente iguales a la de los otros métodos empleados,
luego se ve también que los otros 4 metodos restantes arrojan las mismas soluciones
exceptuando al método de GAUSS SEIDEL que se elja un tanto de los tres métodos restantes,
los 3 metodos resultan eficaces, pero reiterando que todos los métodos mencionados
anteriormente son eficientes.
INTERPOLACION (GERALD)
MÉTODO DE LAGRANGE
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE LAGRANGE
')
disp('================================================================
===')
format short
fprintf('\nIngrese los datos como vectores:\n')
X=input('\nX = ');
FX=input('\nF(X) = ');
fprintf('\nIngrese el valor que desea interpolar:\n')
Xint=input('\nx = ');
N=length(X);
FXint=0;
syms x
for I=1:N
g=1;
for J=1:N
if I~=J
g=g*(x-X(J))/(X(I)-X(J));
end
end
FXint=FXint+g*FX(I);
end
FXint=char(vpa(simplify(FXint),7));
disp(' ')
disp(' POLINOMIO INTERPOLADOR')
fprintf(' P(x) = ')
disp(FXint)
FXint=inline(FXint,'x');
fprintf(' Valor interpolado: f(x) = %f \n',FXint(Xint));
SOLUCIÓN
MÉTODO DE NEWTON
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE NEWTON
')
disp('================================================================
===')
format short
fprintf('\nIngrese los datos como vectores:\n')
X=input('\nX = ');
FX=input('\nF(X) = ');
fprintf('\nIngrese el valor que desea interpolar:\n')
Xint=input('\nx = ');
N=length(X);
FXint=0;
for I=1:N-1
T(I,1)=(FX(I+1)-FX(I))/(X(I+1)-X(I));
end
for J=2:N-1
for I=J:N-1
T(I-J+1,J)=(T(I-J+2,J-1)-T(I-J+1,J-1))/(X(I+1)-X(I-J+1));
end
end
syms x
for I=1:N-1
P=1;
for J=1:I
P=P*(x-X(J));
end
FXint=FXint+T(1,I)*P;
end
FXint=FXint+FX(1);
FXint=char(vpa(simplify(FXint),7));
disp(' ')
disp(' POLINOMIO INTERPOLADOR')
fprintf(' P(x) = ')
disp(FXint)
FXint=inline(FXint,'x');
fprintf(' Valor interpolado: f(x) = %f \n',FXint(Xint));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE SPLINE CÚBICO
')
disp('================================================================
===')
format short
fprintf('\nIngrese los datos como vectores:\n')
X=input('\nX = ');
FX=input('\nF(X) = ');
fprintf('\nIngrese el valor que desea interpolar:\n')
Xint=input('\nx = ');
N=length(X);
for I=1:N-1
h(I)=X(I+1)-X(I);
e(I)=(FX(I+1)-FX(I))/h(I);
end
for I=1:N-2
for J=1:N-2
if I==J
A(I,J)=(h(I)+h(I+1))/3;
elseif J==I-1
A(I,J)=h(I)/6;
elseif J==I+1
A(I,J)=h(J)/6;
end
end
end
for I=2:N-1
cte(I-1)=e(I)-e(I-1);
end
r=inv(A)*cte';
r=[0;r;0];
for I=1:N-1
a(I)=(r(I+1)-r(I))/(6*h(I));
b(I)=r(I)/2;
c(I)=(FX(I+1)-FX(I))/h(I)-(r(I+1)/6+r(I)/3)*h(I);
d(I)=FX(I);
end
for I=1:N-1
dd(I)=d(I)-c(I)*X(I)+b(I)*X(I)^2-a(I)*X(I)^3;
cc(I)=c(I)-2*b(I)*X(I)+3*a(I)*X(I)^2;
bb(I)=b(I)-3*a(I)*X(I);
aa(I)=a(I);
end
mat=[aa' bb' cc' dd'];
for I=1:N-1
if Xint>X(I) & Xint<X(I+1)
FXint=aa(I)*Xint^3+bb(I)*Xint^2+cc(I)*Xint+dd(I);
end
end
disp(' ')
disp(' COEFICIENTES DEL POLINOMIO INTERPOLADOR')
disp(' a b c d')
disp(mat)
fprintf(' Valor interpolado: f(x) = %f \n',FXint);
SOLUCIÓN
CONCLUSIÓN
Esta vez utilizando tres métodos diferentes, se ve que el resultado de lagrange y newton
prácticamente nos da la misma expresión, resultando que spline cubico se aproxima
relativamente.
MÉTODO DE LAGRANGE
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE LAGRANGE
')
disp('================================================================
===')
format short
fprintf('\nIngrese los datos como vectores:\n')
X=input('\nX = ');
FX=input('\nF(X) = ');
fprintf('\nIngrese el valor que desea interpolar:\n')
Xint=input('\nx = ');
N=length(X);
FXint=0;
syms x
for I=1:N
g=1;
for J=1:N
if I~=J
g=g*(x-X(J))/(X(I)-X(J));
end
end
FXint=FXint+g*FX(I);
end
FXint=char(vpa(simplify(FXint),7));
disp(' ')
disp(' POLINOMIO INTERPOLADOR')
fprintf(' P(x) = ')
disp(FXint)
FXint=inline(FXint,'x');
fprintf(' Valor interpolado: f(x) = %f \n',FXint(Xint));
SOLUCIÓN
MÉTODO DE NEWTON
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE NEWTON
')
disp('================================================================
===')
format short
fprintf('\nIngrese los datos como vectores:\n')
X=input('\nX = ');
FX=input('\nF(X) = ');
for I=1:N-1
T(I,1)=(FX(I+1)-FX(I))/(X(I+1)-X(I));
end
for J=2:N-1
for I=J:N-1
T(I-J+1,J)=(T(I-J+2,J-1)-T(I-J+1,J-1))/(X(I+1)-X(I-J+1));
end
end
syms x
for I=1:N-1
P=1;
for J=1:I
P=P*(x-X(J));
end
FXint=FXint+T(1,I)*P;
end
FXint=FXint+FX(1);
FXint=char(vpa(simplify(FXint),7));
disp(' ')
disp(' POLINOMIO INTERPOLADOR')
fprintf(' P(x) = ')
disp(FXint)
FXint=inline(FXint,'x');
fprintf(' Valor interpolado: f(x) = %f \n',FXint(Xint));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE SPLINE CÚBICO
')
disp('================================================================
===')
format short
fprintf('\nIngrese los datos como vectores:\n')
X=input('\nX = ');
FX=input('\nF(X) = ');
fprintf('\nIngrese el valor que desea interpolar:\n')
Xint=input('\nx = ');
N=length(X);
for I=1:N-1
h(I)=X(I+1)-X(I);
e(I)=(FX(I+1)-FX(I))/h(I);
end
for I=1:N-2
for J=1:N-2
if I==J
A(I,J)=(h(I)+h(I+1))/3;
elseif J==I-1
A(I,J)=h(I)/6;
elseif J==I+1
A(I,J)=h(J)/6;
end
end
end
for I=2:N-1
cte(I-1)=e(I)-e(I-1);
end
r=inv(A)*cte';
r=[0;r;0];
for I=1:N-1
a(I)=(r(I+1)-r(I))/(6*h(I));
b(I)=r(I)/2;
c(I)=(FX(I+1)-FX(I))/h(I)-(r(I+1)/6+r(I)/3)*h(I);
d(I)=FX(I);
end
for I=1:N-1
dd(I)=d(I)-c(I)*X(I)+b(I)*X(I)^2-a(I)*X(I)^3;
cc(I)=c(I)-2*b(I)*X(I)+3*a(I)*X(I)^2;
bb(I)=b(I)-3*a(I)*X(I);
aa(I)=a(I);
end
mat=[aa' bb' cc' dd'];
for I=1:N-1
if Xint>X(I) & Xint<X(I+1)
FXint=aa(I)*Xint^3+bb(I)*Xint^2+cc(I)*Xint+dd(I);
end
end
disp(' ')
disp(' COEFICIENTES DEL POLINOMIO INTERPOLADOR')
disp(' a b c d')
disp(mat)
fprintf(' Valor interpolado: f(x) = %f \n',FXint);
SOLUCIÓN
CONCLUSIÓN
MÉTODO DE LAGRANGE
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE LAGRANGE
')
disp('================================================================
===')
format short
fprintf('\nIngrese los datos como vectores:\n')
X=input('\nX = ');
FX=input('\nF(X) = ');
fprintf('\nIngrese el valor que desea interpolar:\n')
Xint=input('\nx = ');
N=length(X);
FXint=0;
syms x
for I=1:N
g=1;
for J=1:N
if I~=J
g=g*(x-X(J))/(X(I)-X(J));
end
end
FXint=FXint+g*FX(I);
end
FXint=char(vpa(simplify(FXint),7));
disp(' ')
disp(' POLINOMIO INTERPOLADOR')
fprintf(' P(x) = ')
disp(FXint)
FXint=inline(FXint,'x');
fprintf(' Valor interpolado: f(x) = %f \n',FXint(Xint));
SOLUCIÓN
MÉTODO DE NEWTON
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE NEWTON
')
disp('================================================================
===')
format short
for I=1:N-1
T(I,1)=(FX(I+1)-FX(I))/(X(I+1)-X(I));
end
for J=2:N-1
for I=J:N-1
T(I-J+1,J)=(T(I-J+2,J-1)-T(I-J+1,J-1))/(X(I+1)-X(I-J+1));
end
end
syms x
for I=1:N-1
P=1;
for J=1:I
P=P*(x-X(J));
end
FXint=FXint+T(1,I)*P;
end
FXint=FXint+FX(1);
FXint=char(vpa(simplify(FXint),7));
disp(' ')
disp(' POLINOMIO INTERPOLADOR')
fprintf(' P(x) = ')
disp(FXint)
FXint=inline(FXint,'x');
fprintf(' Valor interpolado: f(x) = %f \n',FXint(Xint));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE SPLINE CÚBICO
')
disp('================================================================
===')
format short
fprintf('\nIngrese los datos como vectores:\n')
X=input('\nX = ');
FX=input('\nF(X) = ');
fprintf('\nIngrese el valor que desea interpolar:\n')
Xint=input('\nx = ');
N=length(X);
for I=1:N-1
h(I)=X(I+1)-X(I);
e(I)=(FX(I+1)-FX(I))/h(I);
end
for I=1:N-2
for J=1:N-2
if I==J
A(I,J)=(h(I)+h(I+1))/3;
elseif J==I-1
A(I,J)=h(I)/6;
elseif J==I+1
A(I,J)=h(J)/6;
end
end
end
for I=2:N-1
cte(I-1)=e(I)-e(I-1);
end
r=inv(A)*cte';
r=[0;r;0];
for I=1:N-1
a(I)=(r(I+1)-r(I))/(6*h(I));
b(I)=r(I)/2;
c(I)=(FX(I+1)-FX(I))/h(I)-(r(I+1)/6+r(I)/3)*h(I);
d(I)=FX(I);
end
for I=1:N-1
dd(I)=d(I)-c(I)*X(I)+b(I)*X(I)^2-a(I)*X(I)^3;
cc(I)=c(I)-2*b(I)*X(I)+3*a(I)*X(I)^2;
bb(I)=b(I)-3*a(I)*X(I);
aa(I)=a(I);
end
mat=[aa' bb' cc' dd'];
for I=1:N-1
if Xint>X(I) & Xint<X(I+1)
FXint=aa(I)*Xint^3+bb(I)*Xint^2+cc(I)*Xint+dd(I);
end
end
disp(' ')
disp(' COEFICIENTES DEL POLINOMIO INTERPOLADOR')
disp(' a b c d')
disp(mat)
fprintf(' Valor interpolado: f(x) = %f \n',FXint);
SOLUCIÓN
CONCLUSIÓN
También utilizando tres métodos diferentes, se ve que el resultado de lagrange y newton nos
dan una expresión similar pero que difiere de todas maneras, luego spline cubico se aproxima
relativamente, en este caso el mejor método seria el de lagrange.
APROXIMACION (GERALD)
MÉTODO DE CHEBYSHEV
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE CHEBYSHEV
')
disp('================================================================
===')
syms x
fprintf('\nIngrese la función:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el grado del polinomio aproximado:\n')
N=input('\nN = ');
fprintf('\nIngrese el intervalo en el que desea aproximar:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
d=pi/(2*N+2);
C=zeros(1,N+1);
for I=1:N+1
X(I)=cos((2*I-1)*d);
end
X=(b-a)*X/2+(a+b)/2;
xx=X;
Y=F(xx);
for I=1:N+1
z=(2*I-1)*d;
for J=1:N+1
C(J)=C(J)+Y(I)*cos((J-1)*z);
end
end
C=2*C/(N+1);
C(1)=C(1)/2;
T=[0 0 0 0 0 0 0 1;...
0 0 0 0 0 0 1 0;...
0 0 0 0 0 2 0 -1;...
0 0 0 0 4 0 -3 0;...
0 0 0 8 0 -8 0 1;...
0 0 16 0 -20 0 5 0;...
0 32 0 -48 0 18 0 -1;...
64 0 -112 0 56 0 -7 0];
for I=1:N+1
P(I,:)=C(I)*T(I,8-N:8);
end
for I=1:N+1
CP(I)=sum(P(:,I));
end
poli=CP(N+1);
for I=1:N
poli=poli+CP(length(CP)-I)*x^I;
end
FXint=char(vpa(poli,4));
disp(' ')
disp(' POLINOMIO APROXIMADO')
fprintf(' P(x) = ')
disp(FXint)
disp(' ')
FXint=inline(FXint,'x');
FXint=vectorize(FXint);
int=a:0.1:b;
mat=[int' F(int)' FXint(int)' (F(int)-FXint(int))'];
disp(' VALORES APROXIMADOS')
disp(' x f(x) Chebyshev error')
disp(mat)
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE MÍNIMOS CUADRADOS
')
disp('================================================================
===')
syms x
fprintf('\nIngrese la función:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el grado del polinomio aproximado:\n')
P=input('\nN = ');
fprintf('\nIngrese el intervalo en el que desea aproximar:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
X=a:0.1:b;
FX=F(X);
N=P+1;
for k=1:2*P+1
aa(k,1)=sum(X.^(k-1));
end
for k=1:N
A(:,k)=aa(k:N+k-1);
end
for k=1:N
Y(k,1)=sum(FX.*X.^(k-1));
end
CP=inv(A)*Y;
poli=CP(1);
for I=1:P
poli=poli+CP(I+1)*x^I;
end
FXint=char(vpa(poli,4));
disp(' ')
disp(' POLINOMIO APROXIMADO')
fprintf(' P(x) = ')
disp(FXint)
disp(' ')
FXint=inline(FXint,'x');
FXint=vectorize(FXint);
int=a:0.1:b;
mat=[int' F(int)' FXint(int)' (F(int)-FXint(int))'];
disp(' VALORES APROXIMADOS')
disp(' x f(x) Min. Cuad. error')
disp(mat)
SOLUCIÓN
MÉTODO DE CHEBYSHEV
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE CHEBYSHEV
')
disp('================================================================
===')
syms x
fprintf('\nIngrese la función:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el grado del polinomio aproximado:\n')
N=input('\nN = ');
fprintf('\nIngrese el intervalo en el que desea aproximar:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
d=pi/(2*N+2);
C=zeros(1,N+1);
for I=1:N+1
X(I)=cos((2*I-1)*d);
end
X=(b-a)*X/2+(a+b)/2;
xx=X;
Y=F(xx);
for I=1:N+1
z=(2*I-1)*d;
for J=1:N+1
C(J)=C(J)+Y(I)*cos((J-1)*z);
end
end
C=2*C/(N+1);
C(1)=C(1)/2;
T=[0 0 0 0 0 0 0 1;...
0 0 0 0 0 0 1 0;...
0 0 0 0 0 2 0 -1;...
0 0 0 0 4 0 -3 0;...
0 0 0 8 0 -8 0 1;...
0 0 16 0 -20 0 5 0;...
0 32 0 -48 0 18 0 -1;...
64 0 -112 0 56 0 -7 0];
for I=1:N+1
P(I,:)=C(I)*T(I,8-N:8);
end
for I=1:N+1
CP(I)=sum(P(:,I));
end
poli=CP(N+1);
for I=1:N
poli=poli+CP(length(CP)-I)*x^I;
end
FXint=char(vpa(poli,4));
disp(' ')
disp(' POLINOMIO APROXIMADO')
fprintf(' P(x) = ')
disp(FXint)
disp(' ')
FXint=inline(FXint,'x');
FXint=vectorize(FXint);
int=a:0.1:b;
mat=[int' F(int)' FXint(int)' (F(int)-FXint(int))'];
disp(' VALORES APROXIMADOS')
disp(' x f(x) Chebyshev error')
disp(mat)
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE MÍNIMOS CUADRADOS
')
disp('================================================================
===')
syms x
fprintf('\nIngrese la función:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el grado del polinomio aproximado:\n')
P=input('\nN = ');
fprintf('\nIngrese el intervalo en el que desea aproximar:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
X=a:0.1:b;
FX=F(X);
N=P+1;
for k=1:2*P+1
aa(k,1)=sum(X.^(k-1));
end
for k=1:N
A(:,k)=aa(k:N+k-1);
end
for k=1:N
Y(k,1)=sum(FX.*X.^(k-1));
end
CP=inv(A)*Y;
poli=CP(1);
for I=1:P
poli=poli+CP(I+1)*x^I;
end
FXint=char(vpa(poli,4));
disp(' ')
disp(' POLINOMIO APROXIMADO')
fprintf(' P(x) = ')
disp(FXint)
disp(' ')
FXint=inline(FXint,'x');
FXint=vectorize(FXint);
int=a:0.1:b;
mat=[int' F(int)' FXint(int)' (F(int)-FXint(int))'];
disp(' VALORES APROXIMADOS')
disp(' x f(x) Min. Cuad. error')
disp(mat)
SOLUCIÓN
CONCLUSIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 100
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
MÉTODO DE CHEBYSHEV
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE CHEBYSHEV
')
disp('================================================================
===')
syms x
fprintf('\nIngrese la función:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el grado del polinomio aproximado:\n')
N=input('\nN = ');
fprintf('\nIngrese el intervalo en el que desea aproximar:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
d=pi/(2*N+2);
C=zeros(1,N+1);
for I=1:N+1
X(I)=cos((2*I-1)*d);
end
X=(b-a)*X/2+(a+b)/2;
xx=X;
Y=F(xx);
for I=1:N+1
z=(2*I-1)*d;
for J=1:N+1
C(J)=C(J)+Y(I)*cos((J-1)*z);
end
end
C=2*C/(N+1);
C(1)=C(1)/2;
T=[0 0 0 0 0 0 0 1;...
0 0 0 0 0 0 1 0;...
0 0 0 0 0 2 0 -1;...
0 0 0 0 4 0 -3 0;...
0 0 0 8 0 -8 0 1;...
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 101
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
0 0 16 0 -20 0 5 0;...
0 32 0 -48 0 18 0 -1;...
64 0 -112 0 56 0 -7 0];
for I=1:N+1
P(I,:)=C(I)*T(I,8-N:8);
end
for I=1:N+1
CP(I)=sum(P(:,I));
end
poli=CP(N+1);
for I=1:N
poli=poli+CP(length(CP)-I)*x^I;
end
FXint=char(vpa(poli,4));
disp(' ')
disp(' POLINOMIO APROXIMADO')
fprintf(' P(x) = ')
disp(FXint)
disp(' ')
FXint=inline(FXint,'x');
FXint=vectorize(FXint);
int=a:0.1:b;
mat=[int' F(int)' FXint(int)' (F(int)-FXint(int))'];
disp(' VALORES APROXIMADOS')
disp(' x f(x) Chebyshev error')
disp(mat)
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 102
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE MÍNIMOS CUADRADOS
')
disp('================================================================
===')
syms x
fprintf('\nIngrese la función:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el grado del polinomio aproximado:\n')
P=input('\nN = ');
fprintf('\nIngrese el intervalo en el que desea aproximar:\n')
ab=input('\n[a,b] = ');
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 103
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
a=ab(1);
b=ab(2);
X=a:0.1:b;
FX=F(X);
N=P+1;
for k=1:2*P+1
aa(k,1)=sum(X.^(k-1));
end
for k=1:N
A(:,k)=aa(k:N+k-1);
end
for k=1:N
Y(k,1)=sum(FX.*X.^(k-1));
end
CP=inv(A)*Y;
poli=CP(1);
for I=1:P
poli=poli+CP(I+1)*x^I;
end
FXint=char(vpa(poli,4));
disp(' ')
disp(' POLINOMIO APROXIMADO')
fprintf(' P(x) = ')
disp(FXint)
disp(' ')
FXint=inline(FXint,'x');
FXint=vectorize(FXint);
int=a:0.1:b;
mat=[int' F(int)' FXint(int)' (F(int)-FXint(int))'];
disp(' VALORES APROXIMADOS')
disp(' x f(x) Min. Cuad. error')
disp(mat)
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 104
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
CONCLUSIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 105
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
MÉTODO DE CHEBYSHEV
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE CHEBYSHEV
')
disp('================================================================
===')
syms x
fprintf('\nIngrese la función:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el grado del polinomio aproximado:\n')
N=input('\nN = ');
fprintf('\nIngrese el intervalo en el que desea aproximar:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
d=pi/(2*N+2);
C=zeros(1,N+1);
for I=1:N+1
X(I)=cos((2*I-1)*d);
end
X=(b-a)*X/2+(a+b)/2;
xx=X;
Y=F(xx);
for I=1:N+1
z=(2*I-1)*d;
for J=1:N+1
C(J)=C(J)+Y(I)*cos((J-1)*z);
end
end
C=2*C/(N+1);
C(1)=C(1)/2;
T=[0 0 0 0 0 0 0 1;...
0 0 0 0 0 0 1 0;...
0 0 0 0 0 2 0 -1;...
0 0 0 0 4 0 -3 0;...
0 0 0 8 0 -8 0 1;...
0 0 16 0 -20 0 5 0;...
0 32 0 -48 0 18 0 -1;...
64 0 -112 0 56 0 -7 0];
for I=1:N+1
P(I,:)=C(I)*T(I,8-N:8);
end
for I=1:N+1
CP(I)=sum(P(:,I));
end
poli=CP(N+1);
for I=1:N
poli=poli+CP(length(CP)-I)*x^I;
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 106
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
end
FXint=char(vpa(poli,4));
disp(' ')
disp(' POLINOMIO APROXIMADO')
fprintf(' P(x) = ')
disp(FXint)
disp(' ')
FXint=inline(FXint,'x');
FXint=vectorize(FXint);
int=a:0.1:b;
mat=[int' F(int)' FXint(int)' (F(int)-FXint(int))'];
disp(' VALORES APROXIMADOS')
disp(' x f(x) Chebyshev error')
disp(mat)
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 107
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 108
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE MÍNIMOS CUADRADOS
')
disp('================================================================
===')
syms x
fprintf('\nIngrese la función:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese el grado del polinomio aproximado:\n')
P=input('\nN = ');
fprintf('\nIngrese el intervalo en el que desea aproximar:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
X=a:0.1:b;
FX=F(X);
N=P+1;
for k=1:2*P+1
aa(k,1)=sum(X.^(k-1));
end
for k=1:N
A(:,k)=aa(k:N+k-1);
end
for k=1:N
Y(k,1)=sum(FX.*X.^(k-1));
end
CP=inv(A)*Y;
poli=CP(1);
for I=1:P
poli=poli+CP(I+1)*x^I;
end
FXint=char(vpa(poli,4));
disp(' ')
disp(' POLINOMIO APROXIMADO')
fprintf(' P(x) = ')
disp(FXint)
disp(' ')
FXint=inline(FXint,'x');
FXint=vectorize(FXint);
int=a:0.1:b;
mat=[int' F(int)' FXint(int)' (F(int)-FXint(int))'];
disp(' VALORES APROXIMADOS')
disp(' x f(x) Min. Cuad. error')
disp(mat)
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 109
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
CONCLUSIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 110
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 111
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
DIFERENCIACION (GERALD)
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS HACIA ADELANTE
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xad=[x+h x+2*h x+3*h x+4*h x+5*h];
DER=(-F(Xad(2))+4*F(Xad(1))-3*F(x))/(2*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 112
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS HACIA ATRÁS
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xat=[x-h x-2*h x-3*h x-4*h x-5*h];
DER=(3*F(x)-4*F(Xat(1))+F(Xat(2)))/(2*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 113
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS CENTRALES
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xat=[x-h x-2*h x-3*h x-4*h x-5*h];
Xad=[x+h x+2*h x+3*h x+4*h x+5*h];
DER=(-F(Xad(2))+8*F(Xad(1))-8*F(Xat(1))+F(Xat(2)))/(12*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
CONCLUSIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 114
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 115
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS HACIA ADELANTE
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xad=[x+h x+2*h x+3*h x+4*h x+5*h];
DER=(-F(Xad(2))+4*F(Xad(1))-3*F(x))/(2*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 116
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS HACIA ATRÁS
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xat=[x-h x-2*h x-3*h x-4*h x-5*h];
DER=(3*F(x)-4*F(Xat(1))+F(Xat(2)))/(2*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 117
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS CENTRALES
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xat=[x-h x-2*h x-3*h x-4*h x-5*h];
Xad=[x+h x+2*h x+3*h x+4*h x+5*h];
DER=(-F(Xad(2))+8*F(Xad(1))-8*F(Xat(1))+F(Xat(2)))/(12*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
CONCLUSIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 118
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
Utilizando tres métodos diferentes, en este caso se ve que el resultado de diferencias finitas
hacia atrás nos da un valor relativamente lejano al de los otros dos métodos, por lo tanto
diremos que diferencias finitas hacia adelante y diferencias finitas centrales son más efectivos.
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 119
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS HACIA ADELANTE
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xad=[x+h x+2*h x+3*h x+4*h x+5*h];
DER=(-F(Xad(2))+4*F(Xad(1))-3*F(x))/(2*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 120
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS HACIA ATRÁS
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xat=[x-h x-2*h x-3*h x-4*h x-5*h];
DER=(3*F(x)-4*F(Xat(1))+F(Xat(2)))/(2*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 121
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE DIFERENCIAS FINITAS CENTRALES
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea derivar:\n')
s=input('\nf(x) = ','s');
F=inline(s,'x');
fprintf('\nIngrese el valor para la derivada:\n')
x=input('\nx = ');
h=0.1;
Xat=[x-h x-2*h x-3*h x-4*h x-5*h];
Xad=[x+h x+2*h x+3*h x+4*h x+5*h];
DER=(-F(Xad(2))+8*F(Xad(1))-8*F(Xat(1))+F(Xat(2)))/(12*h);
disp(' ')
disp(' RESULTADO')
fprintf(' Derivada aproximada: D = %11.8f \n',DER);
SOLUCIÓN
CONCLUSIÓN
Utilizando tres métodos diferentes, en este caso se ve que los tres métodos nos dan una
solución muy cercana, pero el menos cercano es esta vez el de diferencias finitas centrales, por
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 122
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
lo tanto diremos que diferencias finitas hacia adelante y diferencias finitas hacia atras son los
más efectivos.
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 123
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
INTEGRACION (GERALD)
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DEL TRAPECIO
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
N=1;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
k=1;
Irt(k)=(h/2)*sum(fx);
tol=1;
while tol>0.0001
N=2*N;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
Sp=length(fx);
k=k+1;
Irt(k)=(h/2)*(fx(1)+2*sum(fx(2:Sp-1))+fx(Sp));
tol=abs(Irt(k)-Irt(k-1));
end
Irt(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Irt(k));
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 124
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE SIMPSOM 1/3
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=2;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
k=1;
Is1(k)=(h/3)*(fx(1)+4*fx(2)+fx(3));
tol=1;
while tol>0.0001
N=2*N;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
Sp=length(fx);
k=k+1;
Is1(k)=(h/3)*(fx(1)+4*sum(fx(2:2:Sp-1))+2*sum(fx(3:2:Sp-
2))+fx(Sp));
tol=abs(Is1(k)-Is1(k-1));
end
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 125
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
Is1(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Is1(k));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE SIMPSOM 3/8
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=3;
H=(b-a)/N;
X=(a:H:b);
fx=F(X);
k=1;
Is3(k)=3*H/8*(fx(1)+3*fx(2)+3*fx(3)+4*fx(4));
tol=1;
while tol>0.0001
N=2*N;
H=(b-a)/N;
X=(a:H:b);
fx=F(X);
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 126
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
Sp=length(fx);
k=k+1;
Is3(k)=3*H/8*(fx(1)+3*sum(fx(2:3:Sp-2))+3*sum(fx(3:3:Sp-
1))+2*sum(fx(4:3:Sp-1))+fx(Sp));
tol=abs(Is3(k)-Is3(k-1));
end
Is3(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Is3(k));
SOLUCIÓN:
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE CUADRATURA DE GAUSS DE 2 PUNTOS
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=2;
H=(b-a)/(N/2);
R=[-1/sqrt(3) 1/sqrt(3)];
X=((b-a).*R+b+a)/2;
fx=F(X);
k=1;
Igauss2(k)=(H/2)*sum(fx);
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 127
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
tol=1;
c1=a;
c2=b;
while tol>0.0001
N=2*N;
H=(c2-c1)/(N/2);
n=(a:H:b);
X=[];
for I=1:length(n)-1
c1=n(I);
c2=n(I+1);
X=[X ((c2-c1).*R+c2+c1)/2];
end
fx=F(X);
k=k+1;
Igauss2(k)=H/2*sum(fx);
tol=abs(Igauss2(k)-Igauss2(k-1));
end
Igauss2(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Igauss2(k));
SOLUCIÓN
MÉTODO DE ROMBERG
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE ROMBERG
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 128
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=1;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
k=1;
Ir(k,k)=(h/2)*sum(fx);
tol=1;
while tol>0.0001
N=2*N;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
Sp=length(fx);
k=k+1;
Ir(k,1)=(h/2)*(fx(1)+2*sum(fx(2:Sp-1))+fx(Sp));
for m=2:k
Ir(k,m)=(1/(4^(m-1)-1))*(4^(m-1)*Ir(k,m-1)-Ir(k-1,m-1));
end
tol=abs(Ir(k,m-1)-Ir(k,m));
end
Ir(m,k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Ir(m,k));
SOLUCIÓN
CONCLUSIÓN
Comparando los 5 metodos, podemos ver que todos nos dan una solución bastante similar,
pero la menos aproximada en este caso seria por el método del trapecio, luego la de Simpson
1/3, las restantes nos dan una solución técnicamente igual, pero para este ejercicio el mejor
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 129
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
método seria el de cuadratura de gauss 2 puntos, acotando también los errores con los que
trabaja cada método, pero de todas maneras los 5 metodos empleados fueron eficientes.
MÉTODO DE ROMBERG
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE ROMBERG
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=1;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
k=1;
Ir(k,k)=(h/2)*sum(fx);
tol=1;
while tol>0.0001
N=2*N;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
Sp=length(fx);
k=k+1;
Ir(k,1)=(h/2)*(fx(1)+2*sum(fx(2:Sp-1))+fx(Sp));
for m=2:k
Ir(k,m)=(1/(4^(m-1)-1))*(4^(m-1)*Ir(k,m-1)-Ir(k-1,m-1));
end
tol=abs(Ir(k,m-1)-Ir(k,m));
end
Ir(m,k);
disp(' ')
disp(' RESULTADO')
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 130
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE CUADRATURA DE GAUSS DE 2 PUNTOS
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=2;
H=(b-a)/(N/2);
R=[-1/sqrt(3) 1/sqrt(3)];
X=((b-a).*R+b+a)/2;
fx=F(X);
k=1;
Igauss2(k)=(H/2)*sum(fx);
tol=1;
c1=a;
c2=b;
while tol>0.0001
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 131
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
N=2*N;
H=(c2-c1)/(N/2);
n=(a:H:b);
X=[];
for I=1:length(n)-1
c1=n(I);
c2=n(I+1);
X=[X ((c2-c1).*R+c2+c1)/2];
end
fx=F(X);
k=k+1;
Igauss2(k)=H/2*sum(fx);
tol=abs(Igauss2(k)-Igauss2(k-1));
end
Igauss2(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Igauss2(k));
SOLUCIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE SIMPSOM 3/8
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 132
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=3;
H=(b-a)/N;
X=(a:H:b);
fx=F(X);
k=1;
Is3(k)=3*H/8*(fx(1)+3*fx(2)+3*fx(3)+4*fx(4));
tol=1;
while tol>0.0001
N=2*N;
H=(b-a)/N;
X=(a:H:b);
fx=F(X);
Sp=length(fx);
k=k+1;
Is3(k)=3*H/8*(fx(1)+3*sum(fx(2:3:Sp-2))+3*sum(fx(3:3:Sp-
1))+2*sum(fx(4:3:Sp-1))+fx(Sp));
tol=abs(Is3(k)-Is3(k-1));
end
Is3(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Is3(k));
SOLUCIÓN:
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 133
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 134
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DEL TRAPECIO
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);
N=1;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
k=1;
Irt(k)=(h/2)*sum(fx);
tol=1;
while tol>0.0001
N=2*N;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
Sp=length(fx);
k=k+1;
Irt(k)=(h/2)*(fx(1)+2*sum(fx(2:Sp-1))+fx(Sp));
tol=abs(Irt(k)-Irt(k-1));
end
Irt(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Irt(k));
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 135
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
CONCLUSIÓN
Comparando los 5 metodos, podemos ver que todos nos dan una solución bastante similar,
trapecio y romberg nos dan casi la misma solución, pero la menos aproximada en este caso,
Simpson 3/8 da una solución similar pero que se aleja de los resultados en las ultimas cifras,
por lo tanto las mas efectivas seria Simpson 1/3 y cuadratura de gauss de 2 puntos, acotando
también los errores con los que trabaja cada método, pero de todas maneras los 5 metodos
empleados fueron bastante eficientes.
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DEL TRAPECIO
')
disp('================================================================
===')
syms ('x')
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 136
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
PSEUDOCÓDIGO
clc
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 137
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
clear all
disp('================================================================
===')
disp(' MÉTODO DE SIMPSOM 1/3
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=2;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
k=1;
Is1(k)=(h/3)*(fx(1)+4*fx(2)+fx(3));
tol=1;
while tol>0.0001
N=2*N;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
Sp=length(fx);
k=k+1;
Is1(k)=(h/3)*(fx(1)+4*sum(fx(2:2:Sp-1))+2*sum(fx(3:2:Sp-
2))+fx(Sp));
tol=abs(Is1(k)-Is1(k-1));
end
Is1(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Is1(k));
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 138
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE SIMPSOM 3/8
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=3;
H=(b-a)/N;
X=(a:H:b);
fx=F(X);
k=1;
Is3(k)=3*H/8*(fx(1)+3*fx(2)+3*fx(3)+4*fx(4));
tol=1;
while tol>0.0001
N=2*N;
H=(b-a)/N;
X=(a:H:b);
fx=F(X);
Sp=length(fx);
k=k+1;
Is3(k)=3*H/8*(fx(1)+3*sum(fx(2:3:Sp-2))+3*sum(fx(3:3:Sp-
1))+2*sum(fx(4:3:Sp-1))+fx(Sp));
tol=abs(Is3(k)-Is3(k-1));
end
Is3(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Is3(k));
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 139
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN:
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE CUADRATURA DE GAUSS DE 2 PUNTOS
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=2;
H=(b-a)/(N/2);
R=[-1/sqrt(3) 1/sqrt(3)];
X=((b-a).*R+b+a)/2;
fx=F(X);
k=1;
Igauss2(k)=(H/2)*sum(fx);
tol=1;
c1=a;
c2=b;
while tol>0.0001
N=2*N;
H=(c2-c1)/(N/2);
n=(a:H:b);
X=[];
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 140
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
for I=1:length(n)-1
c1=n(I);
c2=n(I+1);
X=[X ((c2-c1).*R+c2+c1)/2];
end
fx=F(X);
k=k+1;
Igauss2(k)=H/2*sum(fx);
tol=abs(Igauss2(k)-Igauss2(k-1));
end
Igauss2(k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Igauss2(k));
SOLUCIÓN
MÉTODO DE ROMBERG
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE ROMBERG
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función que desea integrar:\n')
s=input('\nf(x) = ','s');
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 141
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
c=inline(s,'x');
F=vectorize(c);
fprintf('\nIngrese los límites de integración:\n')
ab=input('\n[a,b] = ');
a=ab(1);
b=ab(2);%%
N=1;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
k=1;
Ir(k,k)=(h/2)*sum(fx);
tol=1;
while tol>0.0001
N=2*N;
h=(b-a)/N;
x=a:h:b;
fx=F(x);
Sp=length(fx);
k=k+1;
Ir(k,1)=(h/2)*(fx(1)+2*sum(fx(2:Sp-1))+fx(Sp));
for m=2:k
Ir(k,m)=(1/(4^(m-1)-1))*(4^(m-1)*Ir(k,m-1)-Ir(k-1,m-1));
end
tol=abs(Ir(k,m-1)-Ir(k,m));
end
Ir(m,k);
disp(' ')
disp(' RESULTADO')
fprintf(' Integral aproximada: I = %11.8f \n',Ir(m,k));
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 142
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
CONCLUSIÓN
Comparando los 5 metodos, podemos ver que todos nos dan una solución bastante similar,
trapecio y romberg nos dan una solución relativamente parecida, pero la menos
aproximada,en este caso, Simpson 1/3 da una solución similar pero que se aleja de los
resultados en las ultimas cifras, por lo tanto las mas efectivas seria Simpson 3/8 y cuadratura
de gauss de 2 puntos, acotando también los errores con los que trabaja cada método, pero de
todas maneras los 5 metodos empleados fueron bastante eficientes.
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 143
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE RUNGE KUTTA para EDO de 2do orden
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función:\n')
s=input('\nf(t,y,dy) = ','s');
c=inline(s,'t','y','dy');
F=vectorize(c);
fprintf('\nIngrese los valores iniciales:\n')
to=input('\nto = ');
yo=input('\nyo = ');
ypo=input('\ndyo = ');
fprintf('\nIngrese t para calcular y(t), dy(t):\n')
t=input('\nt = ');
N=30;
h=(t-to)/N;
y(1)=yo;
t(1)=to;
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 144
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
yp(1)=ypo;
for I=2:N+1
k1=F(t(I-1),y(I-1),yp(I-1));
k2=F(t(I-1)+h/2,y(I-1)+h/2*yp(I-1)+h/8*k1,yp(I-1)+h/2*k1);
k3=F(t(I-1)+h/2,y(I-1)+h/2*yp(I-1)+h/8*k1,yp(I-1)+h/2*k2);
k4=F(t(I-1)+h,y(I-1)+h*yp(I-1)+h/2*k3,yp(I-1)+k3);
yp(I)=yp(I-1)+h/6*(k1+2*k2+2*k3+k4);
y(I)=y(I-1)+h*(yp(I-1)+h/6*(k1+k2+k3));
t(I)=t(I-1)+h;
end
iter=1:(N+1);
rpta=[iter' t' y' yp'];
disp(' ')
disp(' TABLA DE ITERACIONES ')
disp(' iter t y(t) dy(t)')
disp(rpta)
fprintf(' Solución aproximada:\n');
fprintf(' y(t) = %11.8f \n',y(N+1));
fprintf(' dy(t) = %11.8f \n',yp(N+1))
fprintf(' para t = %12.8f\n',t(N+1));
plot3(t,y,yp)
xlabel('t','Color','red')
ylabel('y(t)','Color','red')
zlabel('dy(t)','Color','red')
axis([t(1) t(N) min(y) max(y) min(yp) max(yp)])
grid on
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 145
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 146
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
CONCLUSIÓN
Este método es el mas efectivo por eso fue el empleado en este caso ya que es para segundo
orden, la solución que nos da es muy aproximada a la correcta, teniendo en cuenta el margen
de error.
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE RUNGE KUTTA
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función:\n')
s=input('\nf(t,y) = ','s');
c=inline(s,'t','y');
F=vectorize(c);
fprintf('\nIngrese los valores iniciales:\n')
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 147
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
to=input('\nto = ');
yo=input('\nyo = ');
fprintf('\nIngrese t para calcular y(t):\n')
t=input('\nt = ');
N=30;
h=(t-to)/N;
y(1)=yo;
t(1)=to;
for I=2:N+1
k1=F(t(I-1),y(I-1));
k2=F(t(I-1)+h/2,y(I-1)+h/2*k1);
k3=F(t(I-1)+h/2,y(I-1)+h/2*k2);
k4=F(t(I-1)+h,y(I-1)+h*k3);
y(I)=y(I-1)+h/6*(k1+2*k2+2*k3+k4);
t(I)=t(I-1)+h;
end
iter=1:(N+1);
rpta=[iter' t' y'];
disp(' ')
disp(' TABLA DE ITERACIONES ')
disp(' iter t y(t)')
disp(rpta)
fprintf(' Solución aproximada: y(t) = %11.8f \n',y(N+1));
fprintf(' para t = %12.8f\n',t(N+1));
plot(t,y)
xlabel('t','Color','red')
ylabel('y(t)','Color','red')
axis([t(1) t(N) min(y) max(y)])
grid on
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 148
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 149
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 150
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
MÉTODO DE EULER
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE EULER
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función:\n')
s=input('\nf(t,y) = ','s');
c=inline(s,'t','y');
F=vectorize(c);
fprintf('\nIngrese los valores iniciales:\n')
to=input('\nto = ');
yo=input('\nyo = ');
fprintf('\nIngrese t para calcular y(t):\n')
t=input('\nt = ');
N=30;
h=(t-to)/N;
y(1)=yo;
t(1)=to;
for I=2:N+1
y(I)=y(I-1)+h*F(t(I-1),y(I-1));
t(I)=t(I-1)+h;
end
iter=1:(N+1);
rpta=[iter' t' y'];
disp(' ')
disp(' TABLA DE ITERACIONES ')
disp(' iter t y(t)')
disp(rpta)
fprintf(' Solución aproximada: y(t) = %11.8f \n',y(N+1));
fprintf(' para t = %12.8f\n',t(N+1));
plot(t,y)
xlabel('t','Color','red')
ylabel('y(t)','Color','red')
axis([t(1) t(N) min(y) max(y)])
grid on
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 151
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 152
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE RUNGE KUTTA
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función:\n')
s=input('\nf(t,y) = ','s');
c=inline(s,'t','y');
F=vectorize(c);
fprintf('\nIngrese los valores iniciales:\n')
to=input('\nto = ');
yo=input('\nyo = ');
fprintf('\nIngrese t para calcular y(t):\n')
t=input('\nt = ');
N=30;
h=(t-to)/N;
y(1)=yo;
t(1)=to;
for I=2:N+1
k1=F(t(I-1),y(I-1));
k2=F(t(I-1)+h/2,y(I-1)+h/2*k1);
k3=F(t(I-1)+h/2,y(I-1)+h/2*k2);
k4=F(t(I-1)+h,y(I-1)+h*k3);
y(I)=y(I-1)+h/6*(k1+2*k2+2*k3+k4);
t(I)=t(I-1)+h;
end
iter=1:(N+1);
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 153
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 154
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 155
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 156
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
MÉTODO DE EULER
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE EULER
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función:\n')
s=input('\nf(t,y) = ','s');
c=inline(s,'t','y');
F=vectorize(c);
fprintf('\nIngrese los valores iniciales:\n')
to=input('\nto = ');
yo=input('\nyo = ');
fprintf('\nIngrese t para calcular y(t):\n')
t=input('\nt = ');
N=30;
h=(t-to)/N;
y(1)=yo;
t(1)=to;
for I=2:N+1
y(I)=y(I-1)+h*F(t(I-1),y(I-1));
t(I)=t(I-1)+h;
end
iter=1:(N+1);
rpta=[iter' t' y'];
disp(' ')
disp(' TABLA DE ITERACIONES ')
disp(' iter t y(t)')
disp(rpta)
fprintf(' Solución aproximada: y(t) = %11.8f \n',y(N+1));
fprintf(' para t = %12.8f\n',t(N+1));
plot(t,y)
xlabel('t','Color','red')
ylabel('y(t)','Color','red')
axis([t(1) t(N) min(y) max(y)])
grid on
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 157
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 158
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
CONCLUSIÓN
Comparando los 2 metodos, con diferentes puntos, podemos ver que ambos nos dan una
solución bastante similar, pero en este caso el método de Euler resulta mas efectivo,
considerando el margen de error, pero de todas maneras runge kutta resulta también muy
eficiente.
MÉTODO DE EULER
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE EULER
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función:\n')
s=input('\nf(t,y) = ','s');
c=inline(s,'t','y');
F=vectorize(c);
fprintf('\nIngrese los valores iniciales:\n')
to=input('\nto = ');
yo=input('\nyo = ');
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 159
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
h=(t-to)/N;
y(1)=yo;
t(1)=to;
for I=2:N+1
y(I)=y(I-1)+h*F(t(I-1),y(I-1));
t(I)=t(I-1)+h;
end
iter=1:(N+1);
rpta=[iter' t' y'];
disp(' ')
disp(' TABLA DE ITERACIONES ')
disp(' iter t y(t)')
disp(rpta)
fprintf(' Solución aproximada: y(t) = %11.8f \n',y(N+1));
fprintf(' para t = %12.8f\n',t(N+1));
plot(t,y)
xlabel('t','Color','red')
ylabel('y(t)','Color','red')
axis([t(1) t(N) min(y) max(y)])
grid on
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 160
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 161
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 162
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE RUNGE KUTTA
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la función:\n')
s=input('\nf(t,y) = ','s');
c=inline(s,'t','y');
F=vectorize(c);
fprintf('\nIngrese los valores iniciales:\n')
to=input('\nto = ');
yo=input('\nyo = ');
fprintf('\nIngrese t para calcular y(t):\n')
t=input('\nt = ');
N=30;
h=(t-to)/N;
y(1)=yo;
t(1)=to;
for I=2:N+1
k1=F(t(I-1),y(I-1));
k2=F(t(I-1)+h/2,y(I-1)+h/2*k1);
k3=F(t(I-1)+h/2,y(I-1)+h/2*k2);
k4=F(t(I-1)+h,y(I-1)+h*k3);
y(I)=y(I-1)+h/6*(k1+2*k2+2*k3+k4);
t(I)=t(I-1)+h;
end
iter=1:(N+1);
rpta=[iter' t' y'];
disp(' ')
disp(' TABLA DE ITERACIONES ')
disp(' iter t y(t)')
disp(rpta)
fprintf(' Solución aproximada: y(t) = %11.8f \n',y(N+1));
fprintf(' para t = %12.8f\n',t(N+1));
plot(t,y)
xlabel('t','Color','red')
ylabel('y(t)','Color','red')
axis([t(1) t(N) min(y) max(y)])
grid on
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 163
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 164
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
CONCLUSIÓN
Comparando los 2 metodos, podemos ver que en este caso no nos dan una solución similar,
el método de Euler resulta ser mas efectivo, considerando el margen de error, pero de todas
maneras runge kutta resulta también muy eficiente.
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 165
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO CRANK NICOLSON
')
disp('================================================================
===')
disp(' Método para resolver EDP parabólicas
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la condición inicial:\n')
s1=input('\ny(x,0) = ','s');
c1=inline(s1,'x');
Fx=vectorize(c1);
fprintf('\nIngrese las condiciones de frontera:\n')
s2=input('\ny(0,t) = ','s');
c2=inline(s2,'x');
G1t=vectorize(c2);
s3=input('\ny(L,t) = ','s');
c3=inline(s3,'x');
G2t=vectorize(c3);
fprintf('\nIngrese los tamaños de paso:\n')
DX=input('\ndx = ');
DT=input('\ndt = ');
fprintf('\nIngrese los valores finales:\n')
XF=input('\nx = ');
TF=input('\nt = ');
fprintf('\nIngrese el coeficiente de la 2da derivada parcial:\n')
alfa=input('\nalfa = ');
NX=XF/DX+1;
NT=TF/DT+1;
beta=alfa*DT/DX^2;
for I=2:NX-1
T(I)=Fx(DX*(I-1));
end
T(1)=(Fx(0)+G1t(0));
T(NX)=(Fx(XF)+G2t(0));
mat(1,:)=T(1:NX);
for I=1:NX-2
A(I)=beta;
B(I)=-2-2*beta;
C(I)=beta;
end
for I=1:NT-1
T(1)=G1t(DT*I);
T(NX)=G2t(DT*I);
for J=1:NX-2
D(J)=-beta*T(J)-(2-2*beta)*T(J+1)-beta*T(J+2);
end
D(1)=D(1)-beta*T(1);
D(NX-2)=D(NX-2)-beta*T(NX);
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 166
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
V(1)=B(1);
for J=2:NX-2
V(J)=B(J)-(A(J)*C(J-1))/V(J-1);
end
W(1)=D(1)/V(1);
for J=2:NX-2
W(J)=(D(J)-A(J)*W(J-1))/V(J);
end
X(NX-2)=W(NX-2);
for J=1:NX-3
K=NX-2-J;
X(K)=W(K)-(C(K)*X(K+1))/V(K);
end
for J=1:NX-2
T(J+1)=X(J);
end
mat(I+1,:)=T(1:NX);
IT(I,1)=I*DT;
end
for I=1:NX-1
IX(I)=I*DX;
end
IT=[0;0;IT];
IX=[0 IX];
mat=[IT [IX;mat]];
disp(' ')
disp(' TABLA DE DISTRIBUCIÓN ')
disp(mat)
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 167
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 168
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 169
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
CONCLUSIÓN
Este método de crank nicolson resulta ser muy eficiente para este tipo de ejercicios por eso
se eligio, ya que su solución es muy aproximada a la verdadera, y el margen de error es
considerablemente permisible, además se observa la cantidad de iteraciones que realiza.
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 170
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO CRANK NICOLSON
')
disp('================================================================
===')
disp(' Método para resolver EDP parabólicas
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la condición inicial:\n')
s1=input('\ny(x,0) = ','s');
c1=inline(s1,'x');
Fx=vectorize(c1);
fprintf('\nIngrese las condiciones de frontera:\n')
s2=input('\ny(0,t) = ','s');
c2=inline(s2,'x');
G1t=vectorize(c2);
s3=input('\ny(L,t) = ','s');
c3=inline(s3,'x');
G2t=vectorize(c3);
fprintf('\nIngrese los tamaños de paso:\n')
DX=input('\ndx = ');
DT=input('\ndt = ');
fprintf('\nIngrese los valores finales:\n')
XF=input('\nx = ');
TF=input('\nt = ');
fprintf('\nIngrese el coeficiente de la 2da derivada parcial:\n')
alfa=input('\nalfa = ');
NX=XF/DX+1;
NT=TF/DT+1;
beta=alfa*DT/DX^2;
for I=2:NX-1
T(I)=Fx(DX*(I-1));
end
T(1)=(Fx(0)+G1t(0));
T(NX)=(Fx(XF)+G2t(0));
mat(1,:)=T(1:NX);
for I=1:NX-2
A(I)=beta;
B(I)=-2-2*beta;
C(I)=beta;
end
for I=1:NT-1
T(1)=G1t(DT*I);
T(NX)=G2t(DT*I);
for J=1:NX-2
D(J)=-beta*T(J)-(2-2*beta)*T(J+1)-beta*T(J+2);
end
D(1)=D(1)-beta*T(1);
D(NX-2)=D(NX-2)-beta*T(NX);
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 171
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
V(1)=B(1);
for J=2:NX-2
V(J)=B(J)-(A(J)*C(J-1))/V(J-1);
end
W(1)=D(1)/V(1);
for J=2:NX-2
W(J)=(D(J)-A(J)*W(J-1))/V(J);
end
X(NX-2)=W(NX-2);
for J=1:NX-3
K=NX-2-J;
X(K)=W(K)-(C(K)*X(K+1))/V(K);
end
for J=1:NX-2
T(J+1)=X(J);
end
mat(I+1,:)=T(1:NX);
IT(I,1)=I*DT;
end
for I=1:NX-1
IX(I)=I*DX;
end
IT=[0;0;IT];
IX=[0 IX];
mat=[IT [IX;mat]];
disp(' ')
disp(' TABLA DE DISTRIBUCIÓN ')
disp(mat)
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 172
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
CONCLUSIÓN
En esta ocasión el método de crank nicolson no realiza tantas iteraciones debido a las
condiciones del problema, pero resulta ser muy eficiente para este tipo de ejercicios, ya que
su solución es muy aproximada a la verdadera, y el margen de error es considerablemente
permisible.
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 173
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO CRANK NICOLSON
')
disp('================================================================
===')
disp(' Método para resolver EDP parabólicas
')
disp('================================================================
===')
syms ('x')
fprintf('\nIngrese la condición inicial:\n')
s1=input('\ny(x,0) = ','s');
c1=inline(s1,'x');
Fx=vectorize(c1);
fprintf('\nIngrese las condiciones de frontera:\n')
s2=input('\ny(0,t) = ','s');
c2=inline(s2,'x');
G1t=vectorize(c2);
s3=input('\ny(L,t) = ','s');
c3=inline(s3,'x');
G2t=vectorize(c3);
fprintf('\nIngrese los tamaños de paso:\n')
DX=input('\ndx = ');
DT=input('\ndt = ');
fprintf('\nIngrese los valores finales:\n')
XF=input('\nx = ');
TF=input('\nt = ');
fprintf('\nIngrese el coeficiente de la 2da derivada parcial:\n')
alfa=input('\nalfa = ');
NX=XF/DX+1;
NT=TF/DT+1;
beta=alfa*DT/DX^2;
for I=2:NX-1
T(I)=Fx(DX*(I-1));
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 174
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
end
T(1)=(Fx(0)+G1t(0));
T(NX)=(Fx(XF)+G2t(0));
mat(1,:)=T(1:NX);
for I=1:NX-2
A(I)=beta;
B(I)=-2-2*beta;
C(I)=beta;
end
for I=1:NT-1
T(1)=G1t(DT*I);
T(NX)=G2t(DT*I);
for J=1:NX-2
D(J)=-beta*T(J)-(2-2*beta)*T(J+1)-beta*T(J+2);
end
D(1)=D(1)-beta*T(1);
D(NX-2)=D(NX-2)-beta*T(NX);
V(1)=B(1);
for J=2:NX-2
V(J)=B(J)-(A(J)*C(J-1))/V(J-1);
end
W(1)=D(1)/V(1);
for J=2:NX-2
W(J)=(D(J)-A(J)*W(J-1))/V(J);
end
X(NX-2)=W(NX-2);
for J=1:NX-3
K=NX-2-J;
X(K)=W(K)-(C(K)*X(K+1))/V(K);
end
for J=1:NX-2
T(J+1)=X(J);
end
mat(I+1,:)=T(1:NX);
IT(I,1)=I*DT;
end
for I=1:NX-1
IX(I)=I*DX;
end
IT=[0;0;IT];
IX=[0 IX];
mat=[IT [IX;mat]];
disp(' ')
disp(' TABLA DE DISTRIBUCIÓN ')
disp(mat)
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 175
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
CONCLUSIÓN
Este método de crank nicolson resulta ser muy eficiente para este tipo de ejercicios por eso
se eligio, y comparando con las condiciones y resultados del problema vemos que realmente
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 176
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
MÉTODO DE POTENCIACIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE POTENCIACIÓN
')
disp('================================================================
===')
Nc=length(A);
for I=1:Nc
[Ev Ld B]=Met_Potenciacion(A);
Valp(I)=Ld;
Vecp(:,I)=Ev;
A=B;
end
disp(' ')
disp(' VALORES PROPIOS')
disp(Valp)
disp(' VECTORES PROPIOS')
disp(Vecp)
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 177
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
CONCLUSIÓN
MÉTODO DE POTENCIACIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE POTENCIACIÓN
')
disp('================================================================
===')
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 178
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
Nc=length(A);
for I=1:Nc
[Ev Ld B]=Met_Potenciacion(A);
Valp(I)=Ld;
Vecp(:,I)=Ev;
A=B;
end
disp(' ')
disp(' VALORES PROPIOS')
disp(Valp)
disp(' VECTORES PROPIOS')
disp(Vecp)
SOLUCIÓN
CONCLUSIÓN
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 179
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
MÉTODO DE POTENCIACIÓN
PSEUDOCÓDIGO
clc
clear all
disp('================================================================
===')
disp(' MÉTODO DE POTENCIACIÓN
')
disp('================================================================
===')
Nc=length(A);
for I=1:Nc
[Ev Ld B]=Met_Potenciacion(A);
Valp(I)=Ld;
Vecp(:,I)=Ev;
A=B;
end
disp(' ')
disp(' VALORES PROPIOS')
disp(Valp)
disp(' VECTORES PROPIOS')
disp(Vecp)
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 180
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
SOLUCIÓN
CONCLUSIÓN
Para aplicar el método de las potencias se supone que la matriz A de n x n tiene n valores
característicos con un conjunto asociado de vectores característicos
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 181
|METODOS NUMERICOS
[UNSCH] INGENIERIA CIVIL
ANEXO
El arte de calcular, que es distinto a la ciencia del cálculo, se basa en cálculos 182
|METODOS NUMERICOS