Está en la página 1de 229

Dra. Ing.

Selva Soledad Rivera


Prof. Adjunta

1
ALGORITMIA

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Estructura secuencial

Ej: Calcular el área de un triángulo

disp('Ingrese la base');
b=input('');
disp('Ingrese la altura');
a=input('');
area=b*a/2;
disp('El área del triágulo es = ');
disp(area); 3

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


for i=a:b:c
sentencia1
for i=1:3

disp('El valor ingresado es '); sentencia n
disp(i) end
end

 El valor ingresado es i disp(….) disp(i)


 1 1 'El valor 1
ingresado es
2 'El valor 2
 El valor ingresado es ingresado es
 2 3 'El valor 3
ingresado es
4 Fin del lazo
 El valor ingresado es 4

 3
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
Ej: Calcular la sumatoria de los números
desde el 1 al 10.

%%%SUMATORIA%%%%%
suma=0;
for i=1:10
suma=suma+i;
end
disp('La sumatoria es igual a = ');
disp(suma)
5
% encontrar si el punto pertenece al plano IF
ELSE
x=input('Ingrese la abscisa'); END

y=input('Ingrese la ordenada');

if(y<3)&&(x+y)>1&&y<(2*x +1)&&(y>x)
disp('El punto pertenece al plano')
else
disp('El punto no pertenece al plano')
end
6

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Leer componentes de un vector

for j=1:5
disp('Ingrese la componente')
vec(j)= input(' ');
end j disp(…) vec(j)

1 Ingrese la componente vec(1)

2 Ingrese la componente vec(2)

3 Ingrese la componente vec(3)

4 Ingrese la componente vec(4)

5 Ingrese la componente vec(5) 7

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Escribir componentes de un vector
vec = [1 2 3 4 5] vector fila

vec = [1; 2; 3 ;4 ;5] vector columna


for j=1:200
vec(j)= input(‘Ingrese una componente: ’);
end
for j=1:200 a=0;
for i=1:10 vec=0:0.5:4.5;
vec(j)= j; vec(i)=a;
a=a+0.5;
end
8

end
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
%Mi primer gráfico
clc;clear all;
x=-10:0.1:10;
y1=zeros(1,201)+3;
y2=x;
y3=1-x;
y4=2*x+1;
plot(x,y1,x,y2,x,y3,x,y4)
title('Mi primer gráfico')
xlabel('X')
ylabel('Y')
legend('y1','y2','y3','y4')
9

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


EJERCICIO

Una estación meteorológica recibe


datos de temperatura en cada hora del
día. Desarrollar un algoritmo que reciba
dichos datos, y al final del día calcule el
promedio e imprima el resultado.
10
 % Estación meteorológica
 disp(‘Ingrese una temperatura por cada hora del día')
 N=24; % Asigna en N las 24 horas de un día
 for j=1:N % Varia j desde 1 hasta N
 disp('Ingrese la componente') % escribe
 vec(j)= input(' '); % lee desde teclado la temperatura
 end % fin del bloque variar
 sum=0; % Hace la suma de las componentes
 for j=1:N % Varia j desde 1 hasta N
 sum = sum + vec(j); % suma j vec(j) sum
 end % fin del bloque variar 1 vec(1) 0+vec(1)

 vm = sum/N; % Calcula el promedio 2 vec(2) vec(1)+vec(2)


3 vec(3) vec(1)+vec(2)+vec(3)
 disp ('El promedio es')
… …. 11 ……..
 disp (vm)
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
While (condición)
…. Sentencias
end
clc;
clear all; i disp(…) disp(i)
0
i=0; 1 El valor es disp(1)

while (i<=4) 2 El valor es disp(2)


3 El valor es disp(3)
i=i+1; 4 El valor es disp(4)
5 El valor es disp(5)
disp(‘El valor es ‘)
disp(i)
end
12

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


EJ: Sumar 1+2+3 usando while

clc;clear all;
i=0;
suma=0;
while i<=2
i=i+1
suma=suma+i
end
suma 13
Ej: Sume valores ingresados por teclado
mientras la suma sea menor que 200.
%%%USO de WHILE
flag=1;
suma=0;
while (flag==1)
aux=input('Ingrese un valor < 200 : ');
suma=suma+aux;
if suma>=200
flag=0;
end
end
disp(suma)
14
EJEMPLO

 Escribaun algoritmo que lea dos


puntos (X1,Y1) (X2, Y2), calcule el
punto medio (Xm;Ym) y repita la
operación hasta que el punto medio
tenga ordenada Ym nula. Escriba la
cantidad de iteraciones realizadas y
los puntos cuya Ym es nula.
15
 tol=0.0001; % Valor debajo del cual se considera CERO
 ym=1;
 iter=0; % contador de iteraciones
 while (abs(ym)> tol) % Bloque MIENTRAS
 iter = iter + 1; % acumula el número de iteraciones
 % Bloque ingreso de datos
 disp('Ingrese x1');x1=input(' '); disp('Ingrese y1') ; y1=input(' ');
 disp('Ingrese x2'); x2=input(' '); disp('Ingrese y2'); y2=input(' ');
 % Bloque de cálculo del Punto Medio
 xm=(x1+x2)/2; ym=(y1+y2)/2; disp('El valor de ym es'), ym
 end % FIN del Bloque MIENTRAS
 % Entrega de resultados
 disp ('El valor de ym es prácticamente nulo')
 disp ('El número de iteraciones fue'), iter
 disp ('El primer punto es'), x1, y1
 disp ('El segundo punto es'),x2, y2
16

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 tol=0.0001; % Valor debajo del cual se considera CERO
 flag=true % control de while
 iter=0; % contador de iteraciones
 while (flag==true) % Bloque MIENTRAS
 iter = iter + 1; % acumula el número de iteraciones
 % Bloque ingreso de datos
 disp('Ingrese x1');x1=input(' '); disp('Ingrese y1') ; y1=input(' ');
 disp('Ingrese x2'); x2=input(' '); disp('Ingrese y2'); y2=input(' ');
 % Bloque de cálculo del Punto Medio
 xm=(x1+x2)/2; ym=(y1+y2)/2; disp('El valor de ym es'), ym
 if (abs(ym)<tol)
 flag=false;
 end
 end % FIN del Bloque MIENTRAS
 % Entrega de resultados
 disp ('El valor de ym es prácticamente nulo')
 disp ('El número de iteraciones fue'), iter
17
 disp ('El primer punto es'), x1, y1
 disp ('El segundo punto es'),x2, y2 Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
Sumar dos vectores
 %suma de dos vectores de 5 componentes
 clc;clear;
 disp('Ingrese el vector a');
 for i=1:5
 a(i)=input('');
 end
 disp('Ingrese el vector b');
 for i=1:5
 b(i)=input('');
 end
 for i=1:5
 vector_suma(i)=a(i)+b(i);
 end
 disp('El vector a es'); disp(a);
 disp('El vector b es'); disp(b);
 disp('El vector suma es '); disp(vector_suma); 18

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Multiplicar dos vectores

 a = [a1 a2 a3] b = [b1 b2 b3]

 c = a x bT = a1 x bT1 + a2 x bT2 + a3 x bT3


 i=1 i=2 i=3

 c=0;

 for i=1:3
 Con matlab: c= a(i) x b(i)+c;
 end

19

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Multiplicar dos vectores
 % Multiplica dos vectores de 5 componentes
 clc;clear;
 disp('Ingrese el vector a');
 for i=1:5
 a(i)=input('');
 end
 disp('Ingrese el vector b');
 for i=1:5
 b(i)=input('');
 end
 c=0;
 for i=1:5
 c=a(i)*b(i)+c;
 end 20

 disp(c)
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
MATRICES

A=[1 2 3;4 5 6; 7 8 9] A(1,3)= 3

A=[15 25 36
46 55 56 A(3,3)=99;
70 81 99]

21
Leer una matriz 3 x 2
i j A(i,j) input
filas=3; 1 1 A(1,1) 55
columnas=2; 1 2 A(1,2) 67
1 3 A(1,3) 8
for i=1:filas 2 1 A(2,1) 2
for j=1:columnas 2 2 A(2,2) 90
2 3 A(2,3) 34
A(i,j)=input(' ')
end
A= [55 67 8
end
2 90 34 ]

22

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Sumar dos matrices 3 x 3

% Suma de dos matrices


 A=[1 2 2; 4 5 6; 7 8 9]
 B=ones(3,3)
 for i=1:3
 for j=1:3
 S(i,j)=A(i,j)+B(i,j);
 end
 end
23

S
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
Discretizar las funciones seno(x/2)
coseno(2*x), seno(x)/x y graficarlas en una Intervalo : [-2*pi;2*pi]
Incremento: pi/10
figura

24

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


%%%Discretizar las funciones seno(x/2) coseno(2*x),
%%%seno(x)/x y graficarlas en una figura
clc;clear all;
x=-2*pi:pi/10:2*pi;
y=sin(x/2);
z=cos(x*2);
p=sin(x)./x;
plot(x,y,x,z,x,p)
title('Gráfico de funciones')
xlabel('abscisas');ylabel('ordenadas');
legend('seno(x/2)','cos(2*x)','seno(x)/x')
25
Graficamos seno(x) y cos(x) y luego
agregamos la función tangente
clc;clear all;
x=-pi:pi/100:pi;
y=sin(x);
z=cos(x);
plot(x,y,'--b',x,z,'o-g')
p= 10^-15*tan(x);
hold on
plot(x,p,'r')
title('Gráfico de funciones')
xlabel('abscisas');ylabel('ordenadas');
legend('seno(x/2)','cos(2*x)','tan(x)')

26

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Ej:Armar una A=[10*seno(x)
-10*cos(x)
10^-15*tang(x)]
graficar cada fila de A en función de x=[-pi;pi] con
∆𝑥 = 𝑝𝑖/10

 clc; clear all;


 x=-pi:pi/10:pi;
 A=[10*sin(x);-10*cos(x);10^-
15*tan(x)];
 plot(x,A(1,:),x,A(2,:),x,A(3,:))

27
Uso de function/end
 function UsoDeFunciones
 clc;clear;
 base=4;
 altura=10;
 area=fa(base,altura);
 disp('El área es igual a '),
 disp(area)
 str=['El área es igual a ',num2str(area)];
 disp(str)
 end
 function devuelve=fa(b,h)
 devuelve=b*h/2; 28

 end
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
Ejercicios Integradores
 %Producto escalar
 for i=1:5
 b(i)=input ('íngrese componente'); Desarrolle un
 end
algoritmo para leer
dos vectores, calcular
 a=[ 2; 4; 6; 8; 10];
y entregar su producto
 sum=0; escalar.

 sum=sum+a(i)*b(i);
 end

29

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Ejercicios Integradores

 %Producto escalar
 for i=1:5 Desarrolle un
 b(i)=input ('íngrese componente'); algoritmo para leer
 end dos vectores, calcular
 a=[ 2; 4; 6; 8; 10]; y entregar su producto
 sum=0;
escalar.
for i=1:5
 sum=sum+a(i)*b(i);
 end

30

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Ejercicios Integradores

 %Producto escalar
 for i=1:5 Desarrolle un
 b(i)=input ('íngrese componente'); algoritmo para leer
 end dos vectores, calcular
 a=[ 2; 4; 6; 8; 10]; y entregar su producto
 sum=0;
escalar.
for i=1:5
 sum=sum+a(i)*b(i);
 end

disp('El producto escalar es'), sum

31

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 %Versor de un vector dado
 .

 N=input ('íngrese dimensión del vector');


 for i=1:N
 a(i)=input ('íngrese componente');
 end

Desarrolle un algoritmo para leer


 for i=1:N un vector, calcular su norma
 sum=sum+a(i)*a(i); cuadrática; y si es no nula
 end entregar el versor unitario.
 norma2 = sum^0.5 De lo contrario debe entregar la
leyenda “vector nulo”

 disp ('el vector es nulo')

 disp ('el versor es:')


 for i=1:N

 disp (' '), v(i)


 end 32

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 %Versor de un vector dado
 N=input ('íngrese dimensión del vector');
 for i=1:N
 a(i)=input ('íngrese componente');
 end
Desarrolle un algoritmo para leer
sum=0; un vector, calcular su norma
cuadrática; y si es no nula
 for i=1:N entregar el versor unitario.
 sum=sum+a(i)*a(i); De lo contrario debe entregar la
 end leyenda “vector nulo”
 norma2 = sum^0.5

 disp ('el vector es nulo')

 disp ('el versor es:')


 for i=1:N

 disp (' '), v(i)


 end 33

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 %Versor de un vector dado


 N=input ('íngrese dimensión del vector');
 for i=1:N
 a(i)=input ('íngrese componente');
 end
Desarrolle un algoritmo para leer
sum=0; un vector, calcular su norma
cuadrática; y si es no nula
 for i=1:N entregar el versor unitario.
 sum=sum+a(i)*a(i); De lo contrario debe entregar la
 end leyenda “vector nulo”
 norma2 = sum^0.5

if (norma2==0)
 disp ('el vector es nulo')

 disp ('el versor es:')


 for i=1:N

 disp (' '), v(i)


 end 34

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 %Versor de un vector dado
 N=input ('íngrese dimensión del vector');
 for i=1:N
 a(i)=input ('íngrese componente');
 end

sum=0; Desarrolle un algoritmo para leer


un vector, calcular su norma
 for i=1:N
cuadrática; y si es no nula
 sum=sum+a(i)*a(i);
entregar el versor unitario.
 end
De lo contrario debe entregar la
 norma2 = sum^0.5
leyenda “vector nulo”
if (norma2==0)
 disp ('el vector es nulo')
else
 disp ('el versor es:')
 for i=1:N

 disp (' '), v(i)


 end
35

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 %Versor de un vector dado
 N=input ('íngrese dimensión del vector');
 for i=1:N
 a(i)=input ('íngrese componente');
 end

sum=0; Desarrolle un algoritmo para leer


un vector, calcular su norma
 for i=1:N cuadrática; y si es no nula
 sum=sum+a(i)*a(i);
entregar el versor unitario.
 end
De lo contrario debe entregar la
 norma2 = sum^0.5
leyenda “vector nulo”
if (norma2==0)
 disp ('el vector es nulo')
else
 disp ('el versor es:')
 for i=1:N
v(i)=a(i) / norma2;
 disp (' '), v(i)
 end
36

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 %Versor de un vector dado
 N=input ('íngrese dimensión del vector');
 for i=1:N
 a(i)=input ('íngrese componente');
 end
sum=0; Desarrolle un algoritmo para leer
un vector, calcular su norma
 for i=1:N
cuadrática; y si es no nula
 sum=sum+a(i)*a(i);
entregar el versor unitario.
 end
De lo contrario debe entregar la
 norma2 = sum^0.5
leyenda “vector nulo”
if (norma2==0)
 disp ('el vector es nulo')
else
 disp ('el versor es:')
 for i=1:N
v(i)=a(i) / norma2;
 disp (' '), v(i)
 end

end 37

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


N=input ('íngrese dimensión del vector');
for i=1:N
a(i)=input ('íngrese componente'); Desarrolle un algoritmo para
end leer un vector, calcular su
norma infinita; y si es no nula
entregar el versor unitario.
for i=1:N De lo contrario debe entregar
if (abs(a(i)) > norinf) la leyenda “vector nulo”
norinf= abs(a(i));
end
end
if norinf==0
disp ('el vector es nulo')

disp ('el versor es:')

v(i)= a(i)/norinf;
disp (' '), v(i)

end 38

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


N=input ('íngrese dimensión del vector');
for i=1:N
a(i)=input ('íngrese componente'); Desarrolle un algoritmo para
end leer un vector, calcular su
norma infinita; y si es no nula
norinf=0; entregar el versor unitario.
for i=1:N De lo contrario debe entregar
if (abs(a(i)) > norinf) la leyenda “vector nulo”
norinf= abs(a(i));
end
end
if norinf==0
disp ('el vector es nulo')

disp ('el versor es:')

v(i)= a(i)/norinf;
disp (' '), v(i)

end 39

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


N=input ('íngrese dimensión del vector');
for i=1:N
a(i)=input ('íngrese componente');
end
norinf=0;
Desarrolle un algoritmo para
for i=1:N leer un vector, calcular su
if (abs(a(i)) > norinf) norma infinita; y si es no nula
norinf= abs(a(i)); entregar el versor unitario.
end De lo contrario debe entregar
end la leyenda “vector nulo”

if norinf==0
disp ('el vector es nulo')
else
disp ('el versor es:')

v(i)= a(i)/norinf;
disp (' '), v(i)

end 40

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


N=input ('íngrese dimensión del vector');
for i=1:N
a(i)=input ('íngrese componente');
end
norinf=0;
for i=1:N Desarrolle un algoritmo para
if (abs(a(i)) > norinf) leer un vector, calcular su
norinf= abs(a(i)); norma infinita; y si es no nula
end entregar el versor unitario.
end De lo contrario debe entregar
la leyenda “vector nulo”
if norinf==0
disp ('el vector es nulo')
else

disp ('el versor es:')


for i=1:N
v(i)= a(i)/norinf;
disp (' '), v(i)
41
end
end Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
 %Promedio Notas
 %Declaracion de variables
Desarrolle un algoritmo para leer
 i=1
un vector con las notas de los
 a(i)=input ('íngrese componente'); exámenes de un alumno. Cuando
 % lea un una nota negativa, debe
 (a(i)>= 0) detener la lectura, calcular el
 i = i + 1; promedio de las notas leídas, y
entregar el
 a(i)=input ('íngrese componente');
promedio y la cantidad de notas
leídas.
 dim=i-1;
 sum=0;
 for
 sum=sum+a(i);
 end
 %
 prom=sum/dim
 disp ('El promedio es'), prom 42

 disp ('El numero de notas es:'), dim Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
 %Promedio Notas
 %Declaracion de variables
Desarrolle un algoritmo para leer
 i=1
un vector con las notas de los
 a(i)=input ('íngrese componente'); exámenes de un alumno. Cuando
 % lea un una nota negativa, debe
 while (a(i)>= 0) detener la lectura, calcular el
 i = i + 1; promedio de las notas leídas, y
entregar el
 a(i)=input ('íngrese componente');
promedio y la cantidad de notas
leídas.
 dim=i-1;
 sum=0;
 for
 sum=sum+a(i);
 end
 %
 prom=sum/dim
 disp ('El promedio es'), prom 43

 disp ('El numero de notas es:'), dim Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
 %Promedio Notas
 %Declaracion de variables
Desarrolle un algoritmo para leer
 i=1
un vector con las notas de los
 a(i)=input ('íngrese componente'); exámenes de un alumno. Cuando
 % lea un una nota negativa, debe
 while (a(i)>= 0) detener la lectura, calcular el
 i = i + 1; promedio de las notas leídas, y
entregar el
 a(i)=input ('íngrese componente');
promedio y la cantidad de notas
end leídas.
 dim=i-1;
 sum=0;
 for
 sum=sum+a(i);
 end
 %
 prom=sum/dim
 disp ('El promedio es'), prom 44

 disp ('El numero de notas es:'), dim Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
 %Promedio Notas
 %Declaracion de variables
Desarrolle un algoritmo para leer
 i=1
un vector con las notas de los
 a(i)=input ('íngrese componente'); exámenes de un alumno. Cuando
 % lea un una nota negativa, debe
 while (a(i)>= 0) detener la lectura, calcular el
 i = i + 1; promedio de las notas leídas, y
entregar el
 a(i)=input ('íngrese componente');
promedio y la cantidad de notas
end leídas.
 dim=i-1;
 sum=0;
 for i=1:dim
 sum=sum+a(i);
 end
 %
 prom=sum/dim
 disp ('El promedio es'), prom 45

 disp ('El numero de notas es:'), dim Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
 tol=1e-12; Escriba un algoritmo que mientras
 max= ; la función f(x)=(3x2-12) sea
 k=1; distinto de cero o el número de
iteraciones sea menor que 100,
 x=input ('íngrese abscisa');
lea un valor de abscisa x0, calcule
 f= 3*x^2-12; la función f(x0) en ese valor x0, y
 A(1,k)=x; sólo entregue un valor de x0 tal
 A(2,k)=f; que la función f(x) es cero.
 %
 (abs(f) > tol …. k < max)
 k =k + 1;
 x=input ('íngrese componente');
 f= 3*x^2-12 ;
 A(1,k)=x;
 A(2,k)=f;

 disp(' '),A 46

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 tol=1e-12; Escriba un algoritmo que mientras
 max= 100; la función f(x)=(3x2-12) sea
 k=1; distinto de cero o el número de
iteraciones sea menor que 100,
 x=input ('íngrese abscisa');
lea un valor de abscisa x0, calcule
 f= 3*x^2-12; la función f(x0) en ese valor x0, y
 A(1,k)=x; sólo entregue un valor de x0 tal
 A(2,k)=f; que la función f(x) es cero.
 %
 (abs(f) > tol … k < max)
 k =k + 1;
 x=input ('íngrese componente');
 f= 3*x^2-12 ;
 A(1,k)=x;
 A(2,k)=f;

 disp(' '),A 47

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 tol=1e-12; Escriba un algoritmo que mientras
 max= 100; la función f(x)=(3x2-12) sea
 k=1; distinto de cero o el número de
iteraciones sea menor que 100,
 x=input ('íngrese abscisa');
lea un valor de abscisa x0, calcule
 f= 3*x^2-12; la función f(x0) en ese valor x0, y
 A(1,k)=x; sólo entregue un valor de x0 tal
 A(2,k)=f; que la función f(x) es cero.
 %
 while (abs(f) > tol … k < max)
 k =k + 1;
 x=input ('íngrese componente');
 f= 3*x^2-12 ;
 A(1,k)=x;
 A(2,k)=f;

 disp(' '),A 48

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 tol=1e-12; Escriba un algoritmo que mientras
 max= 100; la función f(x)=(3x2-12) sea
 k=1; distinto de cero o el número de
iteraciones sea menor que 100,
 x=input ('íngrese abscisa');
lea un valor de abscisa x0, calcule
 f= 3*x^2-12; la función f(x0) en ese valor x0, y
 A(1,k)=x; sólo entregue un valor de x0 tal
 A(2,k)=f; que la función f(x) es cero.
 %
 while (abs(f) > tol & k < max)
 k =k + 1;
 x=input ('íngrese componente');
 f= 3*x^2-12 ;
 A(1,k)=x;
 A(2,k)=f;

 disp(' '),A 49

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 tol=1e-12; Escriba un algoritmo que mientras
 max= 100; la función f(x)=(3x2-12) sea
 k=1;
distinto de cero o el número de
iteraciones sea menor que 100,
 x=input ('íngrese abscisa'); lea un valor de abscisa x0, calcule
 f= 3*x^2-12; la función f(x0) en ese valor x0, y
 A(1,k)=x; sólo entregue un valor de x0 tal
que la función f(x) es cero.
 A(2,k)=f;
 %
 while (abs(f) > tol & k < max)
 k =k + 1;
 x=input ('íngrese componente');
 f= 3*x^2-12 ;
 A(1,k)=x;
 A(2,k)=f;
end
50

 disp(' '),A %disp(''),A(:,k)


 for i=1:3
3 Escriba un algoritmo que lea dos
matrices de dimensión 3x3, las
 A(i,j)=input('Ingrese componente');
sume y entregue el resultado.
 end
 end
 for i=1:3
 for j=1:3

 end
 end
 for i=1:3
 for j=1:3
 S(i,j)= A(i,j)+B(i,j);
 end

3
51

 disp('La matriz suma es '),S


Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
 for i=1:3
for j=1:33 Escriba un algoritmo que lea dos
matrices de dimensión 3x3, las
 A(i,j)=input('Ingrese componente');
sume y entregue el resultado.
 end
 end
 for i=1:3
 for j=1:3

 end
 end
 for i=1:3
 for j=1:3
 S(i,j)= A(i,j)+B(i,j);
 end

3
52

 disp('La matriz suma es '),S


Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
 for i=1:3
for j=1:33 Escriba un algoritmo que lea dos
matrices de dimensión 3x3, las
 A(i,j)=input('Ingrese componente');
sume y entregue el resultado.
 end
 end
 for i=1:3
 for j=1:3

B(i,j)=input(‘Ingrese componente');
 end
 end
 for i=1:3
 for j=1:3
 S(i,j)= A(i,j)+B(i,j);
 end

3
53

 disp('La matriz suma es '),S


Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
 for i=1:3
for j=1:33 Escriba un algoritmo que lea dos
matrices de dimensión 3x3, las
 A(i,j)=input('Ingrese componente');
sume y entregue el resultado.
 end
 end
 for i=1:3
 for j=1:3

B(i,j)=input(‘Ingrese componente');
 end
 end
 for i=1:3
 for j=1:3
 S(i,j)= A(i,j)+B(i,j);
 end
 3end
54

 disp('La matriz suma es '),S


Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
ARREGLOS (ejercicios propuestos de la Guía de Estudio)

 7. Desarrollar un algoritmo que lea dos vectores de 100


componentes, y obtenga el modulo (la norma cuadrática) del
vector diferencia de los vectores leídos. Sólo si dicha norma es
no nula, debe escribir el nuevo vector diferencia normalizado
con dicha norma, de lo contrario debe escribir que la norma
del vector diferencia es nula

 8. Desarrollar un algoritmo que lea un vector de 100


componentes, obtenga la norma infinito del vector (valor
absoluto máximo de sus componentes). Si dicha norma es no
nula, debe escribirla y también escribir un nuevo vector
normalizado del vector leído con dicha norma infinito.
55

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


MATRICES (ejercicio propuesto de la Guía de Estudio)

14. Desarrollar un algoritmo que lea una matriz A(i,j) de


orden N. Luego, debe almacenar la norma infinito de
cada fila de la matriz A en un vector denominado
NormaFila. Seguidamente, debe calcular la norma
infinito del vector NormaFila. Finalmente, solo si este
último resultado es cero, debe entregar el mensaje
Matriz Nula; de otra forma, debe entregar el resultado
no nulo obtenido precedido del mensaje “la norma es”.
Recordar que la norma infinito es la mayor de las
componentes tomadas en valor absoluto.

56
Raíces de ecuaciones no
lineales
Bisección – Regula Falsi – Secante – Newton Raphson – Punto Fijo

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


bisección

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


BISECCIÓN
𝑓 𝑥 = 𝑥 3 − 27
𝑎+𝑏
𝑟=
2
Abs(f(r))

59

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


y
4
3,5

Calcular por el método de la 3


2,5

Bisección la raíz de 𝑓 𝑥 = 𝑒 −𝑥 − 𝑥
2
1,5
1

y graficarla en el [-1;1] 0,5


0
-1,5 -1 -0,5 0 0,5 1 1,5
-0,5
-1

k a b fa fb r fr error
0 -1 1 3,71828183 -0,63212056 0 1 1
1 0 1 1 -0,63212056 0,5 0,10653066 0,10653066
2 0,5 1 0,10653066 -0,63212056 0,75 -0,27763345 0,27763345
3 0,5 0,75 0,10653066 -0,27763345 0,625 -0,08973857 0,08973857
4 0,5 0,625 0,10653066 -0,08973857 0,5625 0,00728282 0,00728282
5 0,5625 0,625 0,00728282 -0,08973857 0,59375 -0,04149755 0,04149755
6 0,5625 0,59375 0,00728282 -0,04149755 0,578125 -0,01717584 0,01717584
7 0,5625 0,578125 0,00728282 -0,01717584 0,5703125 -0,00496376 0,00496376
60

8 0,5625 0,5703125 0,00728282 -0,00496376 0,56640625 0,0011552 0,0011552


Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
function raices_biseccion_con_subprograma
% rk+1 = (ak + bk)/2 fórmula de recurrencia
clc;clear;
iter=0;
error=1e-6;
a=-1; b=1;
itermax=1000; %nº máximo de iteraciones
r=(a+b)/2; % fórmula de recurrencia
B(1,:)=[' i r er']; %% encabezado de la tabla
disp(B)
while (abs(f(r))>error && (iter<itermax))
iter=iter+1;
r=(a+b)/2;
A(iter,:)=[iter r abs(f(r))];
if (f(a)*f(r))<0
b=r;
else
a=r;
end function funcion=f(x)
end funcion=exp(-x)-x;
disp(A) end
end

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación61


Regula - falsi

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


REGULA - FALSI
𝑓 𝑎𝑘
𝑟𝑘+1 = 𝑎𝑘 −
(𝑓 𝑎𝑘 − 𝑓 𝑏𝑘 )
(𝑎𝑘 − 𝑏𝑘 )
a b f(a) f(b) m r f( r) error
𝑓 𝑥 = 𝑥 3 − 27 1,5
2,4742268
4
4
-23,625
-11,8532826
37
37
24,25
32,0187055
2,4742268
2,84442549
-11,8532826
-3,98644642
11,8532826
3,98644642
2,84442549 4 -3,98644642 37 35,4684583 2,95681961 -1,14917001 1,14917001
2,95681961 4 -1,14917001 37 36,5700607 2,98824341 -0,31618567 0,31618567
2,98824341 4 -0,31618567 37 36,8825723 2,99681617 -0,08587212 0,08587212
2,99681617 4 -0,08587212 37 36,9681719 2,99913904 -0,02323926 0,02323926
2,99913904 4 -0,02323926 37 36,9913911 2,99976727 -0,00628312 0,00628312
2,99976727 4 -0,00628312 37 36,9976728 2,9999371 -0,0016983 0,0016983
2,9999371 4 -0,0016983 37 36,999371 2,999983 -0,00045901 0,00045901
2,999983 4 -0,00045901 37 36,99983 2,99999541 -0,00012406 0,00012406
2,99999541 4 -0,00012406 37 36,9999541 2,99999876 -3,3529E-05 3,3529E-05
2,99999876 4 -3,3529E-05 37 36,9999876 2,99999966 -9,062E-06 9,062E-06
2,99999966 4 -9,062E-06 37 36,9999966 2,99999991 -2,4492E-06 2,4492E-06
2,99999991 4 -2,4492E-06 37 36,9999991 2,99999998 -6,6194E-07 6,6194E-07
2,99999998 4 -6,6194E-07 37 36,9999998 2,99999999 -1,789E-07 1,789E-07
2,99999999 4 -1,789E-07 37 36,9999999 3 -4,8352E-08 4,8352E-08
3 4 -4,8352E-08 37 37 3 -1,3068E-08 1,3068E-08
56
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
Calcular por el método de 𝑓 𝑎𝑘
Regula-Falsi la raíz de 𝑓 𝑥 = 𝑟𝑘+1 = 𝑎𝑘 −
𝑒 −𝑥 − 𝑥 en el [-1;1] (𝑓 𝑎𝑘 − 𝑓 𝑏𝑘 )
(𝑎𝑘 − 𝑏𝑘 )
k a b f(a) f(b) m r f( r) error
0 -1 1 3,71828183 -0,63212056 -2,17520119 0,70939674 -0,21745586 0,21745586
1 -1 0,70939674 3,71828183 -0,21745586 -2,30241324 0,61494981 -0,07428178 0,07428178
2 -1 0,61494981 3,71828183 -0,07428178 -2,34840958 0,58331914 -0,02527607 0,02527607
3 -1 0,58331914 3,71828183 -0,02527607 -2,36437356 0,57262875 -0,00858798 0,00858798
4 -1 0,57262875 3,71828183 -0,00858798 -2,36983447 0,56900487 -0,00291639 0,00291639
5 -1 0,56900487 3,71828183 -0,00291639 -2,37169322 0,56777521 -0,0009902 0,0009902
6 -1 0,56777521 3,71828183 -0,0009902 -2,37232481 0,56735782 -0,00033618 0,00033618
7 -1 0,56735782 3,71828183 -0,00033618 -2,3725393 0,56721612 -0,00011413 0,00011413
8 -1 0,56721612 3,71828183 -0,00011413 -2,37261212 0,56716802 -3,8748E-05 3,8748E-05
9 -1 0,56716802 3,71828183 -3,8748E-05 -2,37263685 0,56715168 -1,3155E-05 1,3155E-05
10 -1 0,56715168 3,71828183 -1,3155E-05 -2,37264524 0,56714614 -4,466E-06 4,466E-06
11 -1 0,56714614 3,71828183 -4,466E-06 -2,37264809 0,56714426 -1,5162E-06 1,5162E-06
12 -1 0,56714426 3,71828183 -1,5162E-06 -2,37264906 0,56714362 -5,1474E-07 5,1474E-07
13 -1 0,56714362 3,71828183 -5,1474E-07 -2,37264938 0,5671434 -1,7475E-07 1,7475E-07
14 -1 0,5671434 3,71828183 -1,7475E-07 -2,3726495 0,56714333 -5,9328E-08 5,9328E-08
15 -1 0,56714333 3,71828183 -5,9328E-08 -2,37264953 0,5671433 64 -2,0142E-08 2,0142E-08

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


 %% raices Regula Falsi
 %% fórmula de recurrencia
 %% rk+1 = ak - ( f(ak)/m ) ◦ while (abs(fr)>error && (iter<15))
 %% m= (f(ak)-f(bk)) / (ak-bk) ◦ iter=iter+1;
 clc;clear; ◦ fa=a^3-27;
 iter=0; ◦ fb=b^3-27;
 error=1e-3; ◦ r=a- (fa/( (fa-fb)/(a-b)) );
 fr=100; ◦ fr=r^3-27;
 a=1.5; b=4; ◦ A(iter,:)=[iter a b r abs(fr)];
 %% encabezado de la tabla----------- ◦ if (fa*fr)<0
 disp(' iter a b r error') ◦ b=r;
 %% --------------------------------- ◦ else
◦ a=r;
◦ end
◦ end
65

◦ disp(A)
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
secante

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝑓 𝑥 = 𝑥 3 − 27
𝑓 𝑟𝑘
𝑟𝑘+1 = 𝑟𝑘 −
(𝑓 𝑟𝑘 − 𝑓 𝑟𝑘−1 )
(𝑟𝑘 − 𝑟𝑘−1 )
k r fr m error
0 1,5 -23,625
1 2,75 -6,203125 13,9375 0,45454545
2 3,19506726 5,61669983 26,5573898 0,13929825
3 2,98357435 -0,44106883 28,6428914 0,07088575
4 2,99897324 -0,02771301 26,843216 0,00513472
5 3,00000564 0,00015238 26,990811 0,00034413
6 3 -5,2163E-08 27,0000508 1,8818E-06
7 3 -9,5923E-14 27,0000005 6,4399E-10
8 3 0 27 1,1842E-15
67

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Calcular por el método de la secante la raíz
de 𝑓 𝑥 = 𝑒 − 𝑥 con r1=0,5 y r2=0,75
−𝑥

k r fr1 m error
0 0,5 0,10653066
1 0,75 -0,27763345 -1,53665643 0,33333333
2 0,56932627 -0,00341969 -1,51772898 0,31734655
3 0,56707311 0,00010999 -1,5665446 0,00397332
4 0,56714332 -4,3432E-08 -1,56716319 0,0001238
5 0,56714329 -5,5145E-13 -1,56714329 4,8866E-08
6 0,56714329 0 -1,56737141 6,2035E-13
68

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


function raices_secante
%% Método de la secante
clc;clear;
error=1e-3;
iter=0; while (abs(f(r2))>error && iter<40)
r1=0.49; r2=0.5; % dos aproximaciones iter=iter+1;
m=(f(r2)-f(r1))/(r2-r1); m=(f(r2)-f(r1))/(r2-r1);
r1=r2; r1=r2;
r2=r2-f(r2)/m; r2=r2-f(r2)/m;
A(1,:)=[0 r1 f(r1) m abs(f(r1))]; A(iter+2,:)=[iter+1 r2 f(r2) m
A(2,:)=[1 r2 f(r2) m abs(f(r2))]; error];
%% encabezado de la tabla end
disp(' iter raíz f(r) m disp(A)
error') end
%%
function funcion=f(x)
funcion=12*exp(-2.5*x)-9*exp(-4*x)-0.9;
end
69

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Newton - raphson

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝑓 𝑥 = 𝑥2 − 4 ; f’ (x) = 2 x N-R 𝑓 𝑟𝑘
𝑟𝑘+1 = 𝑟𝑘 −
k r fr df(x)/dx error
𝑑𝑓(𝑥)
0 1,3 -2,31 3,9 𝑑𝑥 𝑟𝑘
1 1,89230769 -0,4191716 5,67692308 0,31300813
2 1,96614551 -0,13427184 5,89843652 0,0375546
3 1,98890948 -0,04423908 5,96672844 0,01144545
4 1,99632377 -0,01469139 5,98897132 0,00371397
5 1,99877685 -0,00489111 5,99633054 0,00122729
6 1,99959253 -0,00162971 5,9987776 0,00040793
7 1,99986421 -0,00054316 5,99959262 0,00013585
8 1,99995474 -0,00018105 5,99986421 4,5268E-05
9 1,99998491 -6,0348E-05 5,99995474 1,5088E-05
10 1,99999497 -2,0116E-05 5,99998491 5,029E-06
11 1,99999832 -6,7052E-06 5,99999497 1,6763E-06
12 1,99999944 -2,2351E-06 5,99999832 5,5877E-07
13 1,99999981 -7,4503E-07 5,99999944 1,8626E-07
14 1,99999994 -2,4834E-07 5,99999981 6,2086E-08
15 1,99999998 -8,2781E-08 5,99999994 2,0695E-08
16 1,99999999 -2,7594E-08 5,99999998 6,8984E-09
71
17 2 -9,1979E-09 5,99999999 2,2995E-09
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
Calcular por el método de N-R la raíz de 𝑓 𝑥 =
−𝑥
𝑒 −𝑥 con r1=0,5
k r fr df(x)/dx error

0 0,5 0,10653066 -1,60653066

1 0,566311 0,00130451 -1,56761551 0,11709291

2 0,56714317 1,9648E-07 -1,56714336 0,00146729

3 0,56714329 4,4409E-15 -1,56714329 2,2106E-07

4 0,56714329 0 -1,56714329 5,0897E-15


72

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


function raices_NR
clc;clear; format
tol=1e-4; error=1;
iter=0;
r1=2.5;
r=r1-f(r1)/df(r1);
A(1,:)=[0 r1 f(r1) df(r1) 100];
A(2,:)=[1 r f(r) df(r) 100];
%% encabezado de la tabla function funcion=f(x)
disp(' iter raíz f(r) df(r) funcion=x^3-27;
error%') end
%%
function derivada=df(x)
while (error>tol && iter<10) derivada=3*x^2;
iter=iter+1; end
r1=r;
r=r-f(r)/df(r);
error=abs((r-r1)/r)*100;
A(iter+2,:)=[iter+1 r f(r) df(r) error ];
end
disp(A) 73
end
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
PUNTO FIJO

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Encontrar g(x) para calcular la 3

 3=𝑥
 𝑥2 =3
−1
 𝑥 2 = −1
3
−1
 𝑥 2 + 𝑥 = −1 + 𝑥
3
−1 2
𝑥 = 𝑥 +𝑥+1
3
−1 2
 𝑔 𝑥 = 𝑥 +𝑥+1
3
75

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


CONVERGENCIA

76
CONVERGENCIA
−1 2
𝑔 𝑥 = 𝑥 +𝑥+1
3

𝑑𝑔(𝑥) 2
=− 𝑥+1
𝑑𝑥 3

𝑑𝑔(𝑥) 2
= − 𝑥+1 <1
𝑑𝑥 3
𝑥=𝜉 𝑥=𝜉

77
−1 2
𝑔 𝑥 = 𝑥 +𝑥+1 ; x0 = 2
3
x g(x) error= abs(xk-xk-1)
2 1,66666667
1,66666667 1,74074074 0,07407407
1,74074074 1,7306813 0,01005944
1,7306813 1,73226205 0,00158075
1,73226205 1,73201811 0,00024393
1,73201811 1,73205586 3,7751E-05
1,73205586 1,73205003 5,8397E-06
1,73205003 1,73205093 9,0342E-07
1,73205093 1,73205079 1,3976E-07
1,73205079 1,73205081 2,1621E-08
1,73205081 1,73205081 3,3448E-09 78

1,73205081 1,73205081 5,1744E-10


Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
Calcular por el x g(x) error rel
-1 2,71828183
método del PF la 2,71828183 1,25526313 53,8214502
raíz de 1,25526313 1,73003462 37,8224678
𝑓 𝑥 = 𝑒 −𝑥 − 𝑥 1,73003462 1,73236136 0,13449074
1,73236136 1,73200273 0,02070148
1,73200273 1,73205824 0,00320501
con x0=-1 1,73205824 1,73204966 0,00049576
1,73204966 1,73205099 7,6695E-05
1,73205099 1,73205078 1,1865E-05
1,73205078 1,73205081 1,8355E-06
1,73205081 1,73205081 2,8395E-07
1,73205081 1,73205081 79 4,3927E-08

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


function raices_PF
% Cálculo de la raiz cuadrada de 3
clc;clear;
x0=2; tol=1e-8; error=1;
iter=0;
while (error>tol && iter<100)
iter=iter+1;
x=g(x0);
error=abs((x0-x));
x0=x; function g=g(x)
end g=(-1/3)*x^2+x+1 ;
n='x0='; end
str=[n,num2str(x0)];
disp(str)
n='iteraciones='; str=[n,num2str(iter)];
disp(str)
80

end
Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación
function raices_PF
% Cálculo de la raiz cuadrada de 3
clc;clear;
x0=2;
str=[n,num2str(x0)];
tol=1e-8; disp(str)
error=1; n='iteraciones='; str=[n,num2str(iter)];
iter=0; disp(str)
flag=true end
function g=g(x)
while flag==true g=(-1/3)*x^2+x+1 ;
iter=iter+1; %g=((-1/3)*(x^2+3))+x;
x=g(x0); end
error=abs((x0-x));
x0=x;
flag=(error>tol & iter<100);
end
n='x0=';

81
SISTEMAS DE Métodos de JACOBI y

ECUACIONES LINEALES GAUSS SEIDEL

DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN


A.x=b

83
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
−3 1 −2 −2 1
JACOBI 𝐴 = 4 −5 0
1 −3 6
𝑏= 5
6
𝒙𝟎 = 1
1

−3 𝑥1 + 𝑥2 − 2 𝑥3 = −2 1 2 2
𝑥1 = 𝑥2 − 𝑥3 +
3 3 3
4 𝑥1 − 5 𝑥2 + 0 𝑥3 = 5 0,333
4 𝒙𝟏 = −0,2
𝑥2 = 𝑥1 − 1
𝑥1 −3 𝑥2 + 6 𝑥3 = 6 5 1,333

1 3
𝑥3 = − 𝑥1 + 𝑥2 + 1
6 6

84
−3 1 −2 −2 1

JACOBI 𝐴= 4
1
−5
−3
0
6
𝑏= 5
6
𝒙𝟎 = 1
1

error=
x1 x2 x3 Max abs(xk+1-xk)
1 1 1

0,33333333 -0,2 1,33333333 1,2

-0,28888889 -0,73333333 0,84444444 0,62


85
clear;clc;
A=[-3 1 -2;4 -5 0;1 -3 6];
% SEL JACOBI despejando b=[-2;5;6];
x=[1;1;1];
B=[x(1) x(2) x(3)];
1 2 2 for i=1:60
𝑥1 = 𝑥2 − 𝑥3 +
3 3 3 x1=(1/3)*x(2)-(2/3)*x(3)+(2/3);

4 x2=(4/5)*x(1)-1;
𝑥2 = 𝑥1 − 1 x3=-(1/6)*x(1)+(3/6)*x(2)+1;
5
B(i+1,:)=[x1 x2 x3];
1 3
𝑥3 = − 𝑥1 + 𝑥2 + 1 x(1)=x1;
6 6
x(2)=x2;
x(3)=x3;
end
B 86
% SEL JACOBI despejando con uso de while
clear all;clc;
A=[-3 1 -2;4 -5 0;1 -3 6]; b=[-2;5;6]; x=[1;1;1]; B=[x(1) x(2) x(3)];
imax=5; e=100; iter=0;
while e>1e-5 && iter<imax
iter=iter+1;
x1=(1/3)*x(2)-(2/3)*x(3)+(2/3); x2=(4/5)*x(1)-1; x3=-(1/6)*x(1)+(3/6)*x(2)+1;
B(iter+1,:)=[x1 x2 x3];
x(1)=x1; x(2)=x2; x(3)=x3;
e=max(abs(B(iter+1,:)-B(iter,:)));
C(iter,:)=[iter B(iter+1,:) e];
end
disp('iter solución error')
D=[0 B(1,:) 0; C];
disp(D) 87
𝑘+1 𝑘
JACOBI 𝑥 = 𝑇 .𝑥 + 𝑐

88
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
JACOBI 𝑥 𝑘+1 = 𝑇. 𝑥 𝑘 + 𝑐
𝐴. 𝑥 = 𝑏
𝐴=𝐷+𝐵
error=1; tol=1e-4; x=[1;1;1;1];
iter=0;
𝐷 + 𝐵 .𝑥 = 𝑏
%% definir T y c
𝐷. 𝑥 + 𝐵. 𝑥 = 𝑏 while error>tol
iter=iter+1;
xk=T*x+c;
Si premultiplico por 𝐷−1 error=max(abs(xk-x))
I . 𝑥 +𝐷−1 . 𝐵 . 𝑥 = 𝐷−1 . b x=xk;
−𝐷−1 . 𝐵 = 𝑇 ; 𝐷−1 . b= c end

𝑥 = 𝑇. 𝑥 + 𝑐
89
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
JACOBI OBTENCIÓN DE LA MATRIZ T

90
-3 1 -2 -2
JACOBI A 4 -5 0 b 5
6
1 -3 6

-3 0 0 0 1 -2
D 0 -5 0 B 4 0 0
0 0 6 1 -3 0

T = - D-1 . B
𝐷−1 . b= c
0,333333
0 33 -0,66666667 0,66666667
T 0,8 0 0 c -1
1
-0,16666667 0,5 0

91
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑘+1 𝑘
𝑥 = 𝑇. 𝑥 + 𝑐
JACOBI
iter x error= Max abs(𝑥 𝑘 -x)
0 1 1 1

1 0,33333333 -0,2 1,33333333 0,66666667 1,2 0,33333333


- -
2 0,28888889 0,73333333 0,84444444 0,62222222 0,53333333 0,48888889
- -
3 0,14074074 1,23111111 0,68148148 0,14814815 0,49777778 0,16296296
- -
4 0,19802469 1,11259259 0,40790123 0,05728395 0,11851852 0,27358025
-
5 0,02386831 1,15841975 0,47670782 0,221893 0,04582716 0,06880658

…. … … … … … …
71 0 -1 0,5 8,7172E-07 8,3523E-07 6,7417E-07
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN 92
JACOBI

93
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
JACOBI
i=1 i=2 i=3

𝑏1 𝑎12 .𝑥20 +𝑎13 .𝑥30 𝑏2 𝑎21 .𝑥10 +𝑎23 .𝑥30 𝑏3 𝑎31 .𝑥10 +𝑎32 .𝑥20
it=1 𝑥11 = 𝑎11
−( 𝑎11
) 𝑥21 = 𝑎22
− 𝑎22
𝑥31 = 𝑎33
− ( 𝑎33
)

𝑏1 𝑎12 .𝑥21 +𝑎13 .𝑥31 𝑏2 𝑎21 .𝑥11 +𝑎23 .𝑥31 𝑏3 𝑎31 .𝑥11 +𝑎32 .𝑥21
i=2 𝑥12 = − ( ) 𝑥21 = − 𝑥31 = −( )
𝑎11 𝑎11 𝑎22 𝑎22 𝑎33 𝑎33

………………………….

94
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
JACOBI
while ((error>tol) && (iter<2000))
iter=iter+1;
for i=1:n
sum=0;
for j=1:n
if j~=i
sum=sum+A(i,j)*x(j);
end
end
xk(i)=(-sum+b(i))/A(i,i);
end
error=max(abs(xk-x)); %norma inf
x=xk; % actualización de var.
end

95
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
GAUSS −3 1 −2 −2 1

SEIDEL
𝐴 = 4 −5 0 𝑏= 5 𝒙𝟎 = 1
1 −3 6 6 1

1 2 2 1 2 2
𝑥 = 𝑥 − 𝑥 + 𝑥1 = 3 1 − 3 1 + 3=0,333
−3 𝑥1 + 𝑥2 − 2 𝑥3 = −2 1 3 2 3 3 3
4
4 𝑥1 − 5 𝑥2 + 0 𝑥3 = 5 4 𝑥2 = 0,333 − 1 = −0,733
𝑥2 = 𝑥1 − 1 5
5
𝑥1 −3 𝑥2 + 6 𝑥3 = 6 1 3
𝑥3 = − 0,333 + −0,7333 + 1 = 0,5777
1 3 6 6
𝑥3 = − 𝑥1 + 𝑥2 + 1
6 6

96
clear;clc;
% SEL GAUSS SEIDEL despejando A=[-3 1 -2;4 -5 0;1 -3 6];
b=[-2;5;6];
x=[1;1;1];
B=[x(1) x(2) x(3)];
for i=1:10
x1=(1/3)*x(2)-(2/3)*x(3)+(2/3);
x2=(4/5)*x1-1;
x3=-(1/6)*x1+(3/6)*x2+1;
B(i+1,:)=[x1 x2 x3];
x(1)=x1;
x(2)=x2;
x(3)=x3;
end
B 97
GAUSS SEIDEL

98
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
GAUSS SEIDEL 𝐴=

0 0 0 −𝑎12 −𝑎13
−𝑎21
0
𝑎11 𝑎11
0 0
Tl = 𝑎22 Ts=0 0
−𝑎23
−𝑎31 −𝑎32 𝑎22
0
𝑎33 𝑎33 0 0 0

99
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
GAUSS SEIDEL
x=[1;1,5;1,5;1];
Xk= =[0.72750; 0.92364;0.96914;0.99000];
tol=1e-6;
error=1;
iter=0;
while error>tol && iter<80
iter=iter+1;
aux=xk;
xk=Tl*xk+Ts*x+c;
error=max(abs(xk-x));
x=aux;
end
100
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
GAUSS SEIDEL
tol=1e-6;
error=1;
iter=0;
while ((error>tol) && (iter<2000))
iter=iter+1;
for i=1:n
sum=0;
for j=1:n
if j~=i
if j<i
sum=sum+A(i,j)*xk(j);
else
sum=sum+A(i,j)*x(j);
end
end
end
xk(i)=(-sum+b(i))/A(i,i);
end

101
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
AUTOVALORES Y Métodos de la Potencia
Y
AUTOVECTORES Potencia Inversa

DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN


MÉTODO DE LA POTENCIA
SIN ESCALAMIENTO

Dada una matriz A se buscan las direcciones invariantes


soluciones de:

𝐴 − λ 𝐼 .𝑥 = 0 𝑥𝑘+1 = 𝐴. 𝑥𝑘

103
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
−10 4
𝐴=
−4 0
MÉTODO DE LA POTENCIA
CON ESCALAMIENTO

2
𝑥0 = ; 𝑥𝑘 2 = 2,83 ;
2
2/2,83 0,707
𝑥𝑘+1 = 𝐴. 𝑦𝑘 𝑦0 = =
2/2,83 0,707
𝑥𝑘
𝑦𝑘 = 𝑥𝑘
𝑥𝑘+1
𝛼𝑘 = − 4.2426
𝑦𝑘 𝑥1 = 𝑦1 = − 0,83
−2.8284 −0,55
λ= 𝛼
𝛼1 = −5,99
−3,99
104
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%% Métodod de la Potencia con escalamiento

MÉTODO DE LA clc;clear;
A=[-10 4;-4 0];

POTENCIA
CON ESCALAMIENTO
N=size(A); N=N(1);
x0=[2;2]; alfa
y0=x0/norm(x0);
tol=1e-8;
maxit=100;
error=1; iter=0;
alfa0=zeros(N(1),1)
while ((error>tol) && (iter<maxit))
iter=iter+1;
𝑥𝑘+1 = 𝐴. 𝑦𝑘 xk=A*y0
𝑥
𝑘 alfa(:,iter)=xk./y0;
𝑦𝑘 = 𝑝𝑠𝑒𝑢𝑑𝑜𝑛𝑜𝑟𝑚𝑎 error=max(abs(alfa(:,iter)-alfa0));
alfa0=alfa(:,iter);
𝑥𝑘+1
𝛼𝑘 = x0=xk;
𝑦𝑘 y0=x0/norm(x0);
λ= 𝛼 end

alfa
iter

plot(alfa(1,:)) 105
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
MÉTODO DE LA POTENCIA
PROBLEMA GENERALIZADO DE VALORES PROPIOS
𝐾 − 𝜔2 . 𝑀 . 𝑥 = 0

𝐾 − 𝜔2 . 𝑀 . 𝑥 = 0
(𝑀−1 𝐾 − 𝜔2 . 𝐼). 𝑥 = 0

𝑨 = 𝑴−𝟏 𝑲
106
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
MÉTODO DE %% Métodod de la Potencia con escalamiento
clc;clear;
LAS A=[-10 4;-4 0]; A=A^-1;
N=size(A); N=N(1);
alfa
POTENCIAS x0=[2;2];
y0=x0/norm(x0);
INVERSAS tol=1e-8;
maxit=100;
error=1; iter=0;
alfa0=zeros(N(1),1)
while ((error>tol) && (iter<maxit))
iter=iter+1;
𝑥𝑘+1 = 𝐴−1 . 𝑦𝑘 xk=A*y0
alfa(:,iter)=xk./y0;
𝑥𝑘
𝑦𝑘 = error=max(abs(alfa(:,iter)-alfa0));
𝑥𝑘 alfa0=alfa(:,iter);
𝑥𝑘+1 x0=xk;
𝛼𝑘 = 𝑦𝑘 y0=x0/norm(x0);
end
1
λ= alfa
𝛼 iter
disp('el mínimo valor propio es =');
disp(1/alfa0(1))
plot(alfa(1,:)) 107
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
MÉTODO DE Mínimos Cuadrados
APROXIMACIÓN
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
MÍNIMOS CUADRADOS
Dados n puntos de coordenadas (xi, yi), se asume que pertenecen
x 0 1 2 3 a una función y(x) que no se conoce.
y 1 1 2 4
Se busca APROXIMAR dicha función mediante
una combinación lineal de m funciones bases
y 5 conocidas.
4
4

3
2
𝒇𝒎 𝒙 = 𝒂𝒋 . ∅𝒋 𝒙 ; j=1,m
2
1 1
1 ∅𝑗 𝑥 funciones bases conocidas y linealmente
0
independientes
0 1 2 3 4
𝑎𝑗 coeficientes a determinar.
x

109
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
MÍNIMOS CUADRADOS
x 0 1 2 3
y 1 1 2 4

y 5

3 Aproximación
lineal
2

0
x
0 0,5 1 1,5 2 2,5 3 3,5

110
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
MÍNIMOS CUADRADOS
x 0 1 2 3
y 1 1 2 4

y 5

3 Aproximación
exponencial
2

0
x
0 0,5 1 1,5 2 2,5 3 3,5

111
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
MÍNIMOS CUADRADOS
x 0 1 2 3
y 1 1 2 4

y 5

3 Aproximación
Polinómica
2

0
x
0 0,5 1 1,5 2 2,5 3 3,5

112
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
APROXIMACIÓN LINEAL

x 0 1 2 3
DATOS
y 1 1 2 4

BASE ∅1 𝑥 , ∅2 𝑥 } = 1, 𝑥

113
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑇 𝑇
MÍNIMOS CUADRADOS ∅ . ∅. 𝑎 = ∅ . 𝑦
x 0 1 2 3
y 1 1 2 4
1 0
1 1
∅= [∅1 𝑥 ∅2 𝑥 } =
1 2
1 3
114
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑇 𝑇
MÍNIMOS CUADRADOS ∅ . ∅. 𝑎 = ∅ . 𝑦
x 0 1 2 3
y 1 1 2 4
1 0
1 1 𝑇 1 1 1 1
∅= ∅ =
1 2 0 1 2 3
1 3
115
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑇 𝑇
∅ . ∅. 𝑎 = ∅ . 𝑦
x 0 1 2 3
y 1 1 2 4
1 0
𝑇 1 1 1 1 1 1 4 6
∅ . ∅= =
0 1 2 3 1 2 6 14
1 3
116
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑇 𝑇
∅ . ∅. 𝑎 = ∅ . 𝑦
x 0 1 2 3
y 1 1 2 4
1
𝑇 1 1 1 1 1 8
∅ .𝑦 = . =
0 1 2 3 2 17
4
117
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑇 𝑇
∅ . ∅. 𝑎 = ∅ . 𝑦

4 6 𝑎1 8
. 𝑎 =
6 14 2 17
𝑎1 0,5
𝑎2 =
1
118
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
APROXIMACIÓN LINEAL
𝑎1 0,5
𝑎2 = 𝑦 = 0,5 + 𝑥
1

y 5

0
x
0 0,5 1 1,5 2 2,5 3 3,5

119
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
LAGRANGE
INTERPOLACIÓN NEWTON

DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN


121
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
MÉTODO DIRECTO ∅ .𝑎 = 𝑦

DADOS n+1 datos:

𝐵𝐴𝑆𝐸 = ∅0 𝑥 , ∅1 𝑥 , ∅2 𝑥 , … , ∅𝑛 𝑥 = 1, 𝑥, 𝑥 2 , 𝑥 3 , … , 𝑥 𝑛

1 𝑥0 𝑥02 … 𝑥0𝑛 𝑎0 𝑦0
1 𝑥1 𝑥12 … 𝑥1𝑛 𝑎1 𝑦1
1 𝑥2 𝑥22 … 𝑥2𝑛 𝑎2 = 𝑦2
… … … … … … …
1 𝑥𝑛 𝑥𝑛2 … 𝑥𝑛𝑛 𝑎𝑛 𝑦𝑛
122
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
x 3 7 9 1 3 9 𝑎0 5
y 5 -1 2
1 7 49 𝑎1 = −1
1 9 81 𝑎2 2
𝑎0 20
𝑎1 = −6,5
𝑎2 0,5

𝑃 𝑥 = 20 − 6,5 𝑥 + 0,5 𝑥 2
123
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
function Interpolacion_MD
%% Interpolacion Método Directo iter=0;
clc; clear all; for i=3:0.5:9
datosx=[3;7;9]; iter=iter+1;
x(iter)=i
datosy=[5;-1;2];
v(iter)= f(a(1),a(2),a(3),i)
%dimensión de los datos end
N=size(datos); N=N(1); hold on
V=[ones(N,1) datosx datosx.^2] plot(x,v,'--r')
a=V\datosy xlabel('x');
plot(datosx,datosy,'rs',… ylabel('y');
'LineWidth',2,... title('Método Directo')
end
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',... function y=f(a1,a2,a3,x)
'MarkerSize',10) y=a1+a2*x+a3*(x^2);
end
124
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑛 (𝑥−𝑥𝑘 )
𝑙𝑖 𝑥 = 𝑘=0 (𝑥 −𝑥 ) 𝐵𝑎𝑠𝑒𝑠
𝑘≠𝑖 𝑖 𝑘

𝑛
𝑃𝑛 𝑥 = 𝑘=0 𝑦𝑘 𝑙𝑘 (𝑥)
125
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
POLINOMIOS DE LAGRANGE
𝑛 (𝑥−𝑥𝑘 ) i 0 1 2
𝑙𝑖 𝑥 = 𝑘=0
(𝑥 −𝑥 ) 𝑖 𝑘 xi 3 7 9
𝑘≠𝑖
yi 5 -1 2

𝑥−𝑥1 (𝑥−𝑥2 ) 𝑥−7 (𝑥−9) 𝑥−7 𝑥−9


𝑙0 𝑥 = 𝑥0 −𝑥1 (𝑥0 −𝑥2 )
= 3−7 (3−9)
= 24

𝑥−𝑥0 (𝑥−𝑥2 ) 𝑥−3 (𝑥−9) 𝑥−3 𝑥−9


𝑙1 𝑥 = = =
𝑥1 −𝑥0 (𝑥1 −𝑥2 ) 7−3 (7−9) −8

𝑥−𝑥0 (𝑥−𝑥1 ) 𝑥−3 (𝑥−7) 𝑥−3 𝑥−7


𝑙2 𝑥 = = =
𝑥2 −𝑥0 (𝑥2 −𝑥1 ) 9−3 (9−7) 12
126
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑛
i 0 1 2

xi 3 7 9
𝑃𝑛 𝑥 = 𝑦𝑘 𝑙𝑘 (𝑥)
yi 5 -1 2
𝑘=0

𝒙−𝟕 𝒙−𝟗 𝒙−𝟑 𝒙−𝟗 𝒙−𝟑 𝒙−𝟕


𝒍𝟎 𝒙 = 𝒍𝟏 𝒙 = 𝒍𝟐 𝒙 =
𝟐𝟒 −𝟖 𝟏𝟐

5 1 2
𝑃𝑛 𝑥 = 𝑥−7 𝑥−9 + 𝑥−3 𝑥−9 + 12 𝑥−3 𝑥−7
24 8

127
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
5 1 2
𝑃𝑛 𝑥 = 𝑥−7 𝑥−9 + 𝑥−3 𝑥−9 + 𝑥−3 𝑥−7
24 8 12

128
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
function Interpolacion_Mlag % Interpolación Polinomios de LAGRANGE
datosx=[3;7;9];
datosy=[5;-1;2];
N=size(datosx); N=N(1);%dimensión del vector de datos
Deltax=0.1; %incremento en x para graficar
%% sumatoria
% cálculo del polinomio resultante
ind=0; % inicializa subíndice del vector polinomio
for k=datosx(1):Deltax:datosx(N)
ind=ind+1;
polix(ind)=k;
suma=0; %inicializa la sumatoria
for i=1:N
suma=suma+(datosy(i)*l(i,N,k,datosx));
end 𝑛
poliy(ind)=suma;
end 𝑃𝑛 𝑥 = 𝑦𝑘 𝑙 𝑘 (𝑥)
𝑘=0

129
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%% Gréafico del polinomio y puntos dato
plot(polix,poliy,'r',datosx,datosy,'rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
title('Interpolación - Polinomios de LAGRANGE')
xlabel('x'); ylabel('y');grid('on');
end

130
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%% función que calcula los polinomios de Lagrange en x; ln(x)

function f=l(n,N,x,datosx) 𝑛 (𝑥 − 𝑥𝑘 )
% n subíndice de los PL 𝑙𝑖 𝑥 = 𝑘=0 (𝑥 − 𝑥 )
𝑖 𝑘
% N cantidad de datos 𝑘≠𝑖

% x variable
% datosx vector datos con las abscisas

multi=1; %inicializa la productoria


for k=1:N
if k~=n
multi=multi*((x-datosx(k))/(datosx(n)-datosx(k)));
end
end
f=multi;
end
131
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
POLINOMIOS DE NEWTON ∅ . 𝑎 = 𝑦

∅0 𝑥 = 𝑛0 𝑥 = 1
∅1 𝑥 = 𝑛1 𝑥 = 1 (𝑥 − 𝑥0 )
∅2 𝑥 = 𝑛2 𝑥 = 1 𝑥 − 𝑥0 𝑥 − 𝑥1
En general ∅𝒏 𝒙 = 𝒏𝒏 𝒙 = 𝟏 𝒙 − 𝒙𝟎 𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟐 … 𝒙 − 𝒙𝒏−𝟏

1 0 0 … 0
1 (𝑥1 − 𝑥0 ) 0 … 0
∅= 1 (𝑥2 − 𝑥0 ) 𝑥2 − 𝑥0 (𝑥2 − 𝑥1 ) … 0
….. …… ….. ….. …..
1 (𝑥𝑛 − 𝑥0 ) 𝑥𝑛 − 𝑥0 (𝑥𝑛 − 𝑥1 ) … 𝑥𝑛 − 𝑥0 𝑥𝑛 − 𝑥1 … (𝑥𝑛 − 𝑥𝑛−1
132
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
POLINOMIOS DE NEWTON ∅ . 𝑎 = 𝑦
i 0 1 2
1 𝑥0 − 𝑥0 (𝑥0 −𝑥0 ) ∗ (𝑥0 − 𝑥1 )
xi 3 7 9
∅=1 𝑥1 − 𝑥0 (𝑥1 −𝑥0 ) ∗ (𝑥1 − 𝑥1 )
yi 5 -1 2 1 𝑥2 − 𝑥0 (𝑥2 −𝑥0 ) ∗ (𝑥2 − 𝑥1 )
5
𝑎 = −1,5
1 0 0 1 0 0 0,5
∅=1 7−3 0 = 1 4 0
1 9 − 3 (9 − 3) ∗ (9 − 7) 1 6 12

P(x) =a0 . 1 + a1 . (𝑥 − 𝑥0 ) + a2 . (𝑥 − 𝑥0 ) . (𝑥 − 𝑥1 )

P(x) = 5 − 1,5(𝑥 − 3) + 0,5 (𝑥 − 3)(𝑥 − 7)

133
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
clear all;clc;
POLINOMIOS DE NEWTON
datosx=[3;7;9]; datosy=[5;-1;2]; %-------------------DATOS---------------
d=size(datosx);N=d(1) % dimensión de los datos
%-------------- matriz Fi------
c1=datosx-datosx(1); c2= c1.*(datosx-datosx(2));
Fi=[ones(N,1) c1 c2]
%----------------------------
a=Fi\datosy % vector de coeficientes para combinación lineal
%---------gráfico del polinomio--------------
x=datosx(1); incx=0.1;
for i=1:(datosx(N)-datosx(1))/incx
polix(i)=x;
poliy(i)=a(1)+ a(2)*(polix(i)-datosx(1))+ a(3)*(polix(i)-datosx(1))*(polix(i)-datosx(2));
x=x+incx;
end

plot(datosx,datosy,'db',polix,poliy,'g')
title('Datos e interpolación con polinomios de Newton')
xlabel('x'); ylabel('y')
legend('datos','polinomio'); 134
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Programa genérico

%% POLINOMIOS DE NEWTON

function Interpolacion_PN
clear;clc;
%-------------------DATOS---------------
datosx=[0;pi/2; pi/4; 3*pi/4];
datosy=sin(datosx);
%---------------------------------------
fc=size(datosx); N=fc(1); %calcula cantidad de datos
incx=0.01; %incremento en x para graficar
x=datosx(1); %inicializo x para graficar
Fi=n(N,datosx) % matriz Fi
a=Fi\datosy % vector de coeficientes para combinación lineal

135
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%---------gráfico del polinomio--------------
for i=1:(datosx(N)-datosx(1))/incx
polix(i)=x;
poliy(i)=a(1)+...
a(2)*(polix(i)-datosx(1))+...
a(3)*(polix(i)-datosx(1))*(polix(i)-datosx(2))+...
a(4)*(polix(i)-datosx(1))*(polix(i)-datosx(2))*(polix(i)-datosx(3));
x=x+incx;
end
figure(1)
plot(datosx,datosy,'db',polix,poliy,'g',polix,sin(polix),'b')
title('Datos e interpolación con polinomios de Newton')
xlabel('x'); ylabel('y')
legend('datos','polinomio','seno(x)');

%% entrega la matriz Fi
function f=n(N,datosx)
f=zeros(N,1);
f(:,1)=1;
for k=2:N
f(:,k)=f(:,k-1).* (datosx(:)-datosx(k-1));%polinomios de Newton
end
end
136
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
figure(2)
x=datosx(1);
for i=1:(datosx(N)-datosx(1))/incx
nx(i)=x;
n1(i)=1;
n2(i)=nx(i)-datosx(1);
n3(i)=(nx(i)-datosx(1))*(nx(i)-datosx(2));
n4(i)=(nx(i)-datosx(1))*(nx(i)-
datosx(2))*(nx(i)-datosx(3));
x=x+incx;
end
plot(nx,n1,'r',nx,n2,'b',nx,n3,'g',nx,n4,'k')
title('Polinomios de Newton')
xlabel('x'); ylabel('y');
legend('n0','n1','n2','n3')
end

137
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
x 0 𝝅 𝝅 𝟑𝝅
𝟒 𝟐 𝟒
y Seno(0) 𝝅
Seno(𝟒 )
𝝅
Seno(𝟐 ) 𝟑𝝅
Seno( 𝟒 )

𝑎0 = 𝑦0 𝑦1 − 𝑦0
x y 𝑎1 =
𝑥1 − 𝑥0 𝑦2 − 𝑦1
− 𝑎1
0 0 𝑥2 − 𝑥1
𝑎2 =
0,90031632 𝑥2 − 𝑥1
0,78539816 0,707106781 -0,33574887
0,37292323 -0,05902388
1,57079633 1 -0,4748206
𝑎3
-0,37292323
2,35619449 0,707106781
138
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
DIFERENCIAS DIVIDIDAS DE NEWTON
𝑎0 𝑎1 𝑎2 𝑎3
x y

0 0
𝟎,𝟕𝟎𝟕−𝟎
=0,900
𝟎,𝟕𝟖𝟓−𝟎

𝟎,𝟑𝟕𝟑−𝟎,𝟗
0,78539816 0,707106781 =-0,336
𝟏,𝟓𝟕𝟏−𝟎
1−0,707 −𝟎,𝟒𝟕𝟓+𝟎,𝟑𝟑𝟔
=0,373
1,571−0,785 𝟐,𝟑𝟓𝟔−𝟎 =0,059

−0,373−0,373
1,57079633 1 2,356−0,785 =-0,475
0,707−1
=-0,373
2,356−1,571

2,35619449 0,707106781

𝑷 𝒙 = 𝟎 . 𝟏 + 𝟎, 𝟗 𝒙 − 𝟎 + 𝟎, 𝟑𝟑𝟔 𝒙 − 𝟎 𝒙 − 𝟎, 𝟕𝟖𝟓 + 𝟎, 𝟎𝟓𝟗 (𝒙 − 𝟎) 𝒙 − 𝟎, 𝟕𝟖𝟓 𝒙 − 𝟏, 𝟓𝟕𝟏


DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑷 𝒙 = 𝟎 . 𝟏 + 𝟎, 𝟗 𝒙 − 𝟎 + 𝟎, 𝟑𝟑𝟔 𝒙 − 𝟎 𝒙 − 𝟎, 𝟕𝟖𝟓 + 𝟎, 𝟎𝟓𝟗 (𝒙 − 𝟎) 𝒙 − 𝟎, 𝟕𝟖𝟓 𝒙 − 𝟏, 𝟓𝟕𝟏

140
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Trapecios Simple
Trapecios Compuesto

INTEGRACIÓN NUMÉRICA Simpson Simple


Simpson Compuesto
Richardson – Romberg
Gauss Legendre
D r a . I n g . S E LV A S . R I V E R A – P R O F. A D J U N TA – C Á L C U L O N U M É R I C O Y C O M P U TA C I Ó N
𝑏
𝑎
𝑓 𝑥 𝑑𝑥 = I
TRAPECIO ℎ 𝑇𝑆
𝐼𝑇𝑆 = 𝑦0 + 𝑦1 + 𝑂(ℎ3 )
SIMPLE 2
xi 0 0,1 0,2 0,3 0,4 8

f(xi) 1 7 4 3 5 7
6
5
4

y
3
2

ℎ𝑇𝑆 = ∆𝑥 = (𝑏 − 𝑎) = 0,4 − 0 1
0
0 0,2 x 0,4 0,6

0,4
𝐼𝑇𝑆 = 1 + 5 = 1,2
2
142
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
ℎ 𝑇𝑆
TRAPECIO 𝐼𝑇𝑆 = 𝑦0 + 𝑦𝑛 + 𝑂(ℎ3 )
2
SIMPLE
xi 0 0,1 0,2 0,3 0,4
f(xi) 1 7 4 3 5

𝑃𝑟𝑜𝑑𝑢𝑐𝑡𝑜 𝑒𝑠𝑐𝑎𝑙𝑎𝑟
ℎ𝑇𝑆 = 0,4 − 0

0,4 𝐼𝑇𝑆 = 𝑦 𝑐 ; 𝑦= 1 5 ;𝑐=


2

𝐼𝑇𝑆 = 1 + 5 = 1,2
2 2
143
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%% Trapecios Simple

clear;clc;
datosx=[0;0.1;0.2;0.3;0.4];
datosy=[1;7;4;3;5];
y=[1 5];
h=0,4; %paso
c=[h/2;h/2];
ITS=y*c
144
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%% Trapecios Simple
%-----DATOS---------
clear;clc;
datosx=[0;0.1;0.2;0.3;0.4];
datosy=[1;7;4;3;5];
N=size(datosy);
y(1)=datosy(1);
y(2)=datosy(N(1));
h=datosx(N(1))-datosx(1); %paso
% I=(h/2)*(y(1)+y(2)) = y*c
c=[h/2;h/2]; %vector de coeficientes
ITS=y*c %resultado
145
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
propuesto
ℎ 𝑇𝑆
CALCULAR POR 𝐼𝑇𝑆 =
2
𝑦0 + 𝑦1 + 𝑂(ℎ3 )
TS
3
𝜋
2
𝑓 𝑥 𝑑𝑥
0
xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0


146
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
ℎ 𝑇𝑆
Ejercicio 𝐼𝑇𝑆 = 𝑦0 + 𝑦1 + 𝑂(ℎ3 )
resuelto 2

xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0

𝟑 𝟑
ℎ𝑇𝑆 = 𝝅 𝑰𝑻𝑺 = 𝝅 𝟎+𝟎 =𝟎
𝟐 𝟒
147
DRA. ING. SELVA S. RIVERA – PROF. ADJUNTA – CÁLCULO NUMÉRICO Y COMPUTACIÓN DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑛−1
ℎ 𝑇𝐶
TRAPECIOS 𝐼𝑇𝐶 =
2
𝑦0 + 2 𝑦𝑖 + 𝑦𝑛 + 𝑂(ℎ2 )
COMPUESTO 𝑖=1

𝑏
𝑎
𝑓 𝑥 𝑑𝑥 = I 𝑃𝑟𝑜𝑑𝑢𝑐𝑡𝑜 𝑒𝑠𝑐𝑎𝑙𝑎𝑟
xi 0 0,1 0,2 0,3 0,4 𝐼𝑇𝑆 =𝑦 𝑐 ;
f(xi) 1 7 4 3 5 N=5 puntos
𝑦= 1 7 4 3 5 ;
𝑏 − 𝑎 0,4 − 0
i=0…n; n=N-1=4 ∆𝑥 =
𝑛
=
4
= 0,1 ℎ/2

ℎ𝑇𝐶 = ∆𝑥 = 0,1
𝑐= ℎ
4−1

𝑦0 𝑦𝑖 𝑦𝑛
0,1 𝑖=1 ℎ
𝐼𝑇𝐶 = 1 + 2 ∗ (7 + 4 + 3) + 5 = 1,7 ℎ/2
2 148
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%% Trapecios Compuesto
%-----DATOS---------
clear;clc;
datosx=[0;0.1;0.2;0.3;0.4];
datosy=[1;7;4;3;5];
N=size(datosy);N=N(1);
y0=datosy(1);
yn=datosy(N);
h=(datosx(N)-datosx(1))/(N-1);
%c=[h/2; h; h; h; h/2];
c(1,1)=h/2; c(N,1)=h/2; %primer y último elemento de c
for i=2:N-1 % elemento intermedios de c
c(i,1)=h;
end
ITC=datosy'*c

149
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
propuesto 𝑛−1
ℎ 𝑇𝐶
CALCULAR 𝐼𝑇𝐶 =
2
𝑦0 + 2 𝑦𝑖 + 𝑦𝑛 + 𝑂(ℎ2 )

POR TC
𝑖=1

3
𝜋
2
𝑓 𝑥 𝑑𝑥
0
xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0


150
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑛−1
ℎ 𝑇𝐶
Ejercicio 𝐼𝑇𝐶 = 𝑦0 + 2 𝑦𝑖 + 𝑦𝑛 + 𝑂(ℎ2 )
resuelto 2
𝑖=1

xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0

𝟑
hTC = 𝝅
𝟖 5−1

𝑦𝑖
𝑦0 𝑖=1 𝑦𝑛
𝟑
𝐼𝑇𝐶 = 𝟏𝟔 𝝅 0 + 2 ∗ (0,707 − 1 + 0,707) + 0 = 0,4877
151
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
SIMPSON 𝐼𝑆𝑆 =
ℎ𝑆𝑆
𝑦0 + 4𝑦𝑛/2+ 𝑦𝑛 + 𝑂(ℎ5 )
SIMPLE 3

xi 0 0,1 0,2 0,3 0,4


f(xi) 1 7 4 3 5
𝑃𝑟𝑜𝑑𝑢𝑐𝑡𝑜 𝑒𝑠𝑐𝑎𝑙𝑎𝑟

𝐼𝑇𝑆 = 𝑦 𝑐 ; 𝑦= 1 4 5 ;
𝑏 − 𝑎 0,4
ℎ𝑇𝑆 = = = 0,2 ℎ/3
2 2
0,2 𝑦0 𝑦1 𝑦2 𝑐 = 4 ℎ/3
𝐼𝑇𝑆 = 1 + 4 ∗ 4 + 5 = 1,466 … ℎ/3
3
152
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
% MÉTODO DE SIMPSON SIMPLE
% Claculo de la Integral dentre a=0 y 0.4
clear;clc;
%-----DATOS----------------
datosx=[0;0.1;0.2;0.3;0.4];
datosy=[1;7;4;3;5];
%---------------------------
N=size(datosx);N=N(1); %size da como resultado filas y columnas de datosx
y0=datosy(1); %imagen del extremo inferior
y2=datosy(N); %imagen del extremo superior
pm=(N+1)/2; %punto medio del intervalo
y1=datosy(pm); %imagen del punto medio
h=datosx(pm)-datosx(1); %cálculo del intervalo de integració
%fórmula utilizada (producto escalar): I= y * c
y=[y0 y1 y2]; %vector de imágenes
c=[h/3; 4*h/3; h/3]; %vector de coeficientes
Integral=y*c 153
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
propuesto ℎ𝑆𝑆
𝐼𝑆𝑆 = 𝑦0 + 4𝑦1+ 𝑦2 + 𝑂(ℎ5 )
3
3
CALCULAR 2
𝜋

POR SS 𝑓 𝑥 𝑑𝑥
0
xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0


154
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
CALCULAR 𝐼𝑆𝑆 =
ℎ𝑆𝑆
𝑦0 + 4𝑦1+ 𝑦2 + 𝑂(ℎ5 )
POR SS 3
xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0

𝟑
ℎ𝑆𝑆 = 𝝅
𝟒

𝟏
𝐼𝑆𝑆 = 𝝅 𝟎 − 𝟒 ∗ 𝟏 + 𝟎 = −𝝅
𝟒 155
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
SIMPSON COMPUESTO
ℎ𝑆𝐶 4
𝐼𝑆𝐶 = 𝑦0 + 4 𝑦𝑖 + 2 𝑦𝑖 + 𝑦𝑛 + 𝑂(ℎ )
3
𝑖𝑚𝑝 𝑝𝑎𝑟𝑒𝑠

i 0 1 2 3 4
xi 0 0,1 0,2 0,3 0,4
f(xi) 1 7 4 3 5
𝑏 − 𝑎 0,4 − 0
ℎ𝑆𝐶 = = = 0,1
5−1 4

0,1
𝐼𝑆𝐶 = 1 + 4 ∗ 7 + 3 + 2 ∗ (4) + 5 =1,8
3
156
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%% SIMPSON COMPUESTO
clear;clc;
datosx=[0;0.1;0.2;0.3;0.4];
datosy=[1 7 4 3 5];
%----------------------------
ℎ𝑆𝐶
h=datosx(2)-datosx(1); %paso
𝐼𝑆𝐶 = 𝑦0 + 4 𝑦𝑖 + 2 𝑦𝑖 + 𝑦𝑛
3
𝑖𝑚𝑝 𝑝𝑎𝑟𝑒𝑠 c=[h/3;4*h/3;2*h/3;4*h/3;h/3];
%% resultado
ISC=datosy*c
ℎ𝑆𝐶
𝐼𝑆𝐶 = 𝑦1 + 2 𝑦𝑖 + 4 𝑦𝑖 + 𝑦𝑛+1
3
𝑖𝑚𝑝 𝑝𝑎𝑟𝑒𝑠

157
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%% SIMPSON COMPUESTO
clear;clc;
datosx=[0;0.1;0.2;0.3;0.4]; % datos
datosy=[1;7;4;3;5]; %datos
N=size(datosx); %dimension de datosx[5 1]
h=datosx(2)-datosx(1); %paso
%% sumatoria de los i=impares (o pares de la fórmula)
for i=3:2:N(1)-1
cimpares(i,1)=2*h/3;
yimpares(i,1)=datosy(i,1);
end

ℎ𝑆𝐶 sumaimpares=yimpares'*cimpares;
𝐼𝑆𝐶 = 𝑦0 + 4 𝑦𝑖 + 2 𝑦𝑖 + 𝑦𝑛 %% sumatoria de los i=pares (o impares de la fórmula)
3
𝑖𝑚𝑝 𝑝𝑎𝑟𝑒𝑠
for i=2:2:N(1)-1
cpares(i,1)=4*h/3;
ypares(i,1)=datosy(i,1);
ℎ𝑆𝐶
𝐼𝑆𝐶 = 𝑦1 + 2 𝑦𝑖 + 4 𝑦𝑖 + 𝑦𝑛+1 end
3
𝑖𝑚𝑝 𝑝𝑎𝑟𝑒𝑠
sumapares=ypares'*cpares;
%% resultado
ISC=((h/3)*datosy(1,1))+sumapares+sumaimpares+((h/3)*datosy(N(1),1)) 158
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
propuesto

CALCULAR POR SIMPSON COMPUESTO


ℎ𝑆𝐶
𝐼𝑆𝐶 = 𝑦0 + 4 𝑦𝑖 + 2 𝑦𝑖 + 𝑦𝑛 + 𝑂(ℎ4 )
3
𝑖𝑚𝑝 𝑝𝑎𝑟𝑒𝑠

xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0

159
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
resuelto

ℎ𝑆𝐶
𝐼𝑆𝐶 = 𝑦0 + 4 𝑦𝑖 + 2 𝑦𝑖 + 𝑦𝑛 + 𝑂(ℎ4 )
3
𝑖𝑚𝑝 𝑝𝑎𝑟𝑒𝑠

xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0


𝟑
ℎ𝑆𝐶 = 𝝅
𝟖
𝟏
𝐼𝑆𝐶 = 𝝅 0 + 4 ∗ 0,707 + 0,707 + 2 ∗ (−1) + 0 = 1,4357
𝟖 160
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
COTA DEL ERROR EN EL EJEMPLO
Trapecios 𝑶(𝒉𝟑 ) 𝑶(𝟎, 𝟒𝟑 )=𝑶(𝟎, 𝟎𝟔𝟒)
Simple
Trapecios 𝑶(𝒉𝟐 ) 𝑶(𝟎, 𝟏𝟐 )=𝑶(0,01)
Compuesto
Simpson Simple 𝑶(𝒉𝟓 ) 𝑶 𝟎, 𝟐𝟓 = 𝟎, 𝟎𝟎𝟎𝟑𝟐
Simpson 𝑶(𝒉𝟒 ) 𝑶 𝟎, 𝟏𝟒 =0,0001
Compuesto

161
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
xi 0 𝟏 𝟏 𝟑 𝟏
EXTRAPOLACIÓN DE 𝟒 𝟐 𝟒
RICHRADSON
fi 1 3 3 1,5 0

0,5
h1=0,5 𝐼ℎ1=0,5 = 1 + 2 ∗ 3 + 0 = 1,75
2

0,25
h2=0,25 𝐼ℎ2=0,25 =
2
1 + 2 ∗ (3 + 3 + 1,5) + 0 = 2

𝑛 2
𝛽 𝐼 ℎ2 − 𝐼(ℎ1 ) 4 ∗ 2 − 1,75 ℎ1 0,5
I𝑅 = = = 2,083 𝛽= = =4
𝛽−1 4−1 ℎ2 0,25

162
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
propuesto Dada la función f(x) en forma discreta, aplicando SC
𝟑
halle una aproximación de la integral de f(x) en [0; 𝝅]
𝟐

xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0

ℎ1 𝑛 𝛽 𝐼ℎ2 − 𝐼ℎ1
𝛽= 𝐼𝑅 =
ℎ2 𝛽−1

163
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
xi 0 𝟑 𝟑 𝟗 𝟑
Ejercicio 𝝅 𝝅 𝝅 𝝅
resuelto 𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0


𝟑 𝜋
ℎ1 = 𝝅; 𝐼ℎ1 = 0 + 4 ∗ −1 + 0 = −𝜋
𝟒 4
𝟑 𝜋
ℎ2 = 𝝅 ; 𝐼ℎ2 = 0 + 4 ∗ 0,707 + 0,707 + 2 ∗ −1 + 0 =1,4357
𝟖 8

ℎ1 𝑛 𝛽 𝐼ℎ2 − 𝐼ℎ1
𝛽= = 2 4
= 16 𝐼𝑅 = = 1,74
ℎ2 𝛽−1

164
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝛽 = 4𝑘−1
MÉTODO DE ROMBERG

h K=1 K=2 ; 𝛽=4 K=3; 𝛽=16

h1=1 ITS(h1)=(1/2)*(1+0)=1/2 4∗1,75−0,5 16∗2,083−2,16


𝐼= =2,16 𝐼= =2,0778
4−1 16−1

h2=0,5 ITC(h2)=(0,5/2) * (1+2*3+0)=1,75 4∗2−1,75


𝐼= =2,083
4−1

h3=0,25 ITC(h3)=(0,25/2)*(1+2*(3+3+1,5)+0)=2

165
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
propuesto

CALCULAR POR ROMBERG

xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

f(xi) 0 0,707 -1 0,707 0

𝛽 = 4𝑘−1

166
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
resuelto xi 0 𝟑 𝟑 𝟗 𝟑
𝝅 𝝅 𝝅 𝝅
𝟖 𝟒 𝟖 𝟐

𝛽 = 4𝑘−1 f(xi) 0 0,707 -1 0,707 0

h K=1 K=2 ; 𝛽=4 K=3; 𝛽=16

𝟑 𝟑
ITS=(𝟒 𝝅)*(0+0)=0 16∗1,425+𝜋
4∗−4𝜋 −0
3
𝟐
𝝅 =1,7
16−1
=-𝜋
4−1
𝟑 𝟑 3
ITC=(𝟖 𝝅) * (0+2*(-1)+0)=-4 𝜋 3
𝟒
𝝅 4∗0,487+4𝜋
=1,425
4−1
𝟑 𝟑
ITC=(𝟏𝟔 𝝅)*(0+2*(0,707-
𝝅
𝟖 1+0,707)+0)=0,487

167
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
GAUSS - LEGENDRE
3
𝜋
𝐼= 2
0
𝑠𝑒𝑛𝑜 2 𝑥 𝑑𝑥
𝑥 =ℎ𝑡+𝑐 3
𝑏−𝑎 2 𝜋 −0 3
h= = = 𝜋
2 2 4
a h c b
x

t 3
-1 0 1 𝑐 =𝑎+ℎ =0+ 𝜋
4
3 3
𝑥= 𝜋𝑡+ 𝜋
4 4
168
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
GAUSS - LEGENDRE 3
𝜋
𝐼= 0
2 𝑠𝑒𝑛𝑜 2 𝑥 𝑑𝑥

3 3
𝑥 =ℎ𝑡+𝑐 = 𝜋𝑡+ 𝜋
4 4
𝑓 𝑥 = 𝑠𝑒𝑛𝑜 (2𝑥)

𝐺 𝑡 = 𝑓 ℎ𝑡 + 𝑐 = 𝑠𝑒𝑛𝑜(2 ℎ𝑡 + 𝑐 )

3 3
𝐺 𝑡 = 𝑠𝑒𝑛𝑜 2 𝜋𝑡+ 𝜋
4 4

169
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑛
𝐼𝐺𝐿 = ℎ 𝑖=1 𝜔𝑖 𝐺(𝑡𝑖 )

170
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑛
𝐼𝐺𝐿 = ℎ 𝑖=1 𝜔𝑖 𝐺(𝑡𝑖 )

3 3 3
𝐺 𝑡 = 𝑠𝑒𝑛𝑜 2 𝜋𝑡+ 𝜋 = 𝑠𝑒𝑛𝑜 𝜋(𝑡 + 1)
4 4 2

3
𝐼𝐺𝐿 = 𝜋 𝜔1∗ 𝐺(𝑡1 + 𝜔2 ∗ 𝐺(𝑡2 ))
4

3 3 3 3 3
= 𝜋 1 ∗ 𝑠𝑒𝑛𝑜 𝜋 +1 + 1 ∗ 𝑠𝑒𝑛𝑜 𝜋 − +1 = 4,301
4 2 3 2 3

171
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑛
𝐼𝐺𝐿 = ℎ 𝑖=1 𝜔𝑖 𝐺(𝑡𝑖 )

3 3
𝐺 𝑡 = 𝑠𝑒𝑛𝑜 2 𝜋𝑡+ 𝜋
4 4

3
𝐼𝐺𝐿 = 𝜋 𝜔1 ∗ 𝐺(𝑡1 + 𝜔2 ∗ 𝐺 𝑡2 + 𝜔3 ∗ 𝐺(𝑡3 ))
4

3 3
0,5555556 ∗ 𝑠𝑒𝑛𝑜 𝜋 0,774596669 + 1 + 0,5555556 ∗ 𝑠𝑒𝑛𝑜 𝜋 − 0,774596669 + 1 +
3 2 2
= 𝜋 =0,192
4 3
+ 0,8888889 ∗ 𝑠𝑒𝑛𝑜 𝜋 0+1
2
172
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
propuesto

𝑛
𝐼𝐺𝐿 = ℎ 𝑖=1 𝜔𝑖 𝐺(𝑡𝑖 )

3
𝜋
Resolver con 4 puntos de Gauss 𝐼= 2 𝑠𝑒𝑛𝑜 2 𝑥 𝑑𝑥
0

173
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
Ejercicio
𝑛
resuelto 𝐼𝐺𝐿 = ℎ 𝑖=1 𝜔𝑖 𝐺(𝑡𝑖 )
3 3
𝐺 𝑡 = 𝑠𝑒𝑛𝑜 2 𝜋𝑡+ 𝜋
4 4

3
𝐼𝐺𝐿 = 𝜋 𝜔1 ∗ 𝐺(𝑡1 + 𝜔2 ∗ 𝐺 𝑡2 + 𝜔3 ∗ 𝐺 𝑡3 + 𝜔4 ∗ 𝐺 𝑡4 ) =
4

3 3
0,3478548 𝑠𝑒𝑛𝑜 2 𝜋 0,861136312 + 𝜋 +
4 4
3 3
0,3478548 𝑠𝑒𝑛𝑜 2 𝜋 (−0,861136312) + 𝜋 +
3 4 4
𝜋 = 1,094
4 3 3
0,6521452 𝑠𝑒𝑛𝑜 2 𝜋 0,339981044 + 𝜋 +
4 4
3 3
0,6521452 𝑠𝑒𝑛𝑜 2 𝜋 (−0,339981044) + 𝜋
4 4
174
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
DERIVACIÓN
NUMÉRICA

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


DERIVADAS
PRIMERAS
Hacia adelante - Hacia atrás
Central - Asimétrica

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Hacia adelante ◦𝑓′𝑠 = 1

𝑓𝑠+1 − 𝑓𝑠 -O(h)

𝑓𝑠+1 − 𝑓𝑠 Forma
aproximada
𝑓′𝑠 ≅
𝑥𝑠+1 − 𝑥𝑠
Paso h

177

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


x 0,8 0,9 1 1,1 1,2
F(x) 2,5537129 2,78927897 3 3,19062036 3,36464311

Calcular una aprox. de la derivada primera hacia adelante de la f(x) en x=1.

1
𝑓′𝑠 = 𝑓𝑠+1 − 𝑓𝑠

1
= 3,19062036 − 3
0,1
=1,906
178

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Hacia atrás ◦𝑓′𝑠 =
1

𝑓𝑠 − 𝑓𝑠−1 +O(h)

𝑓𝑠 − 𝑓𝑠−1
𝑓′𝑠 ≅
𝑥𝑠 − 𝑥𝑠−1

179

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


x 0,8 0,9 1 1,1 1,2
F(x) 2,5537129 2,78927897 3 3,19062036 3,36464311

Calcular una aprox. de la derivada primera hacia atrás de la f(x) en x=1.

1
𝑓′𝑠 = 𝑓𝑠 − 𝑓𝑠−1

1
= 3−2,78927897
0,1

=2,107 180

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


1
central ◦𝑓′𝑠 = 𝑓𝑠+1 − 𝑓𝑠−1 + O ℎ2
2ℎ

𝑓𝑠+1 − 𝑓𝑠−1
𝑓′𝑠 ≅
𝑥𝑠+1 − 𝑥𝑠−1

181

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


x 0,8 0,9 1 1,1 1,2
F(x) 2,5537129 2,78927897 3 3,19062036 3,36464311

Calcular una aprox. de la derivada primera central de la f(x) en x=1.

1
𝑓′𝑠 = 𝑓𝑠+1 − 𝑓𝑠−1
2∗ℎ
1
= 3,19062036−2,78927897
0,2

=2,006 182

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


3 2 1
ASIMÉTRICA 𝑓′𝑠 = −
2ℎ
𝑓𝑠 + 𝑓𝑠+1 −
ℎ 2ℎ
𝑓𝑠+2 + O ℎ2
Hacia adelante

Calcular una aprox. de la derivada primera asimétrica hacia adelante de la f(x) en x=1.

x 0,8 0,9 1 1,1 1,2


F(x) 2,5537129 2,78927897 3 3,19062036 3,36464311

3 2 1
𝑓′𝑠 = − 3+ 3,19062036 − 3,36464311
2 ∗ 0,1 0,1 2 ∗ 0,1

= 1,989 183

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


3 2 1
ASIMÉTRICA 𝑓′𝑠 =
2ℎ
𝑓𝑠 − 𝑓𝑠−1 +
ℎ 2ℎ
𝑓𝑠−2 + O ℎ2
Hacia atrás

Calcular una aprox. de la derivada primera asimétrica hacia atrás de la f(x) en x=1.

x 0,8 0,9 1 1,1 1,2


F(x) 2,5537129 2,78927897 3 3,19062036 3,36464311

3 2 1
𝑓′𝑠 = 3− 2,78927897 + 2,5537129
2 ∗ 0,1 0,1 2 ∗ 0,1

= 1,9829851 184

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


x 0,8 0,9 1 1,1 1,2
F(x) 2,5537129 2,78927897 3 3,19062036 3,36464311

◦Calcular dos aproximaciones de la derivada


primera de f(x) en x=0,8.
◦Usar h1=0,1 y h2=2 h1

Calcular la extrapolación de Richardson

185

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


x 0,8 0,9 1 1,1 1,2
F(x) 2,5537129 2,78927897 3 3,19062036 3,36464311

1
◦ 𝑓′𝑠 = 0,1
2,78927897 − 2,5537129 = 2,3556607

1
◦𝑓′𝑠 = 3 − 2,5537129 = 2,2314355
0,2

0,5∗2,2314355 −2,3556607
𝑓′𝑠 𝑅 = = 𝟐, 𝟒𝟕𝟗𝟖𝟖𝟓𝟗;
0,5−1
1
0,1
𝛽= = 0,5
0,2 186

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


DERIVACIÓN
NUMÉRICA
Segundas – Terceras - Cuartas

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝟏
DERIVADAS SEGUNDAS
𝒇′′𝒔 ≅ 𝟐 𝒇𝒔+𝟏 − 𝟐𝒇𝒔 + 𝒇𝒔−𝟏
𝒉

𝟏
DERIVADAS TERCERAS
𝒇′′′𝒔 ≅ 𝟑
−𝒇𝒔−𝟐 + 𝟐𝒇𝒔−𝟏 − 𝟐𝒇𝒔+𝟏 + 𝒇𝒔+𝟐
𝟐𝒉

𝟏
DERIVADAS CUARTAS
𝒇𝒊𝒗
𝒔 = 𝟒 𝒇𝒔−𝟐 − 𝟒𝒇𝒔−𝟏 + 𝟔𝒇𝒔 − 𝟒𝒇𝒔+𝟏 + 𝒇𝒔+𝟐
𝒉

𝑂(ℎ2 )

188

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Calcular las derivadas en x=1 con h=0,1

x 0,8 0,9 1 1,1 1,2


F(x) 2,5537129 2,78927897 3 3,19062036 3,36464311

𝟏
DERIVADAS 𝒇′′𝒔 ≅ 𝒇𝒔+𝟏 − 𝟐𝒇𝒔 + 𝒇𝒔−𝟏 =-2,010067
𝒉𝟐
SEGUNDAS

𝟏
DERIVADAS 𝒇′′′𝒔 ≅ −𝒇𝒔−𝟐 + 𝟐𝒇𝒔−𝟏 − 𝟐𝒇𝒔+𝟏 + 𝒇𝒔+𝟐 =4,123715
𝟐 𝒉𝟑
TERCERAS

𝟏
DERIVADAS 𝒇𝒊𝒗
𝒔 = 𝒉𝟒
𝒇𝒔−𝟐 − 𝟒𝒇𝒔−𝟏 + 𝟔𝒇𝒔 − 𝟒𝒇𝒔+𝟏 + 𝒇𝒔+𝟐 =-12,4131
CUARTAS

189

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


DERIVACIÓN
NUMÉRICA
Ecuaciones Diferenciales Ordinarias

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Edo DERIVADAS
SEGUNDAS
𝟏
𝒇′′𝒔 ≅ 𝟐 𝒇𝒔−𝟏 − 𝟐𝒇𝒔 + 𝒇𝒔+𝟏
con valores de contorno 𝒉

x 0 0,25 0,5 0,75 1


𝑑2 𝑢 𝑥
◦ 10 𝑑𝑥 2
+3 𝑥−1 =0 u(x) 0 U(0,25) U(0,5) U(0,75) 5

𝑽. 𝑪. 𝒖 𝟎 = 𝟎
𝒖 𝟏 =𝟓
10
𝑥1 = 0,25 𝑢 0 − 2 𝑢 0,25 + 𝑢(0,5) +3 (0,25-1)=0
0,252

𝑥0 = 0 𝑢 0 =0
10
𝑥2 = 0,50 𝑢 0,25 − 2 𝑢 0,50 + 𝑢 0,75 + 3 (0,50−1)=0
𝑥4 = 1 𝑢 1 =5 0,252

10
𝑥3 = 0,75 𝑢 0,50 − 2 𝑢 0,75 + 𝑢 1 + 3 (0,75−1)=0
0,252
191

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Edo con valores de contorno

◦ 10
𝑑2 𝑢 𝑥
+3 𝑥−1 =𝟎 𝑽. 𝑪. 𝒖 𝟎 = 𝟎 x 0 0,25 0,5 0,75 1
𝑑𝑥 2
u(x) 0 U(0,25) U(0,5) U(0,75) 5
◦ 𝒖 𝟏 =𝟓

𝒙𝟎 = 𝟎 ; 𝒖 𝟎 =𝟎

10
𝒙𝟏 = 𝟎, 𝟐𝟓 ; 𝑢 0 − 2 𝑢 0,25 + 𝑢(0,5) +3 (0,25-1)=0
0,252

10
𝒙𝟐 = 𝟎, 𝟓𝟎 ; 𝑢 0,25 − 2 𝑢 0,50 + 𝑢 0,75 + 3 (0,50−1)=0
0,252

10
𝒙𝟑 = 𝟎, 𝟕𝟓 ; 𝑢 0,50 − 2 𝑢 0,75 + 𝑢 1 + 3 (0,75−1)=0
0,252

𝒙𝟒 = 𝟏 ; 𝒖 𝟏 =𝟓 192

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Edo con valores de contorno
x 0 0,25 0,5 0,75 1
𝑑2 𝑢 𝑥 u(x) 0 U1 U2 U3 5
◦ 10 + 3 (𝑥 − 1) = 0 𝑉. 𝐶. 𝑢 0 =0
𝑑𝑥 2

◦ 𝑢 1 =5

𝑥0 = 0 𝑢0 = 0
10
𝑥1 = 0,25 0,252
𝑢0 − 2𝑢1 + 𝑢2 +3 ( 0,25-1)=0

10
𝑥2 = 0,50 𝑢 − 2𝑢2 + 𝑢3 +3 (0,50−1) =0
0,252 1
10
𝑥3 = 0,75 𝑢 − 2𝑢3 + 𝑢4 +3 (0,75−1)=0
0,252 2
𝑥4 = 1 𝑢4 = 5
193

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


5

4.5

Edo
3.5

con valores 3

2.5

de contorno
2

1.5

0.5

𝑑2 𝑢 𝑥
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

◦ 10 +3 𝑥−1 =0 𝑉. 𝐶. 𝑢 0 =0
𝑑𝑥 2
◦ 𝑢 1 =5
10
𝑥1 = 0,25 ; 0 − 2𝑢1 + 𝑢2 =2,25 160 −2𝑢1 + 𝑢2 + 0𝑢3 =2,25
0,252

10 −2 1 0 𝑢1 2,25
𝑥2 = 0,50 ; 𝑢 − 2𝑢2 + 𝑢3 =1,5 160 𝑢1 −2𝑢2 + 𝑢3 =1,5 160 1 −2 1 𝑢2 = 1,50
0,252 1
0 1 −2 𝑢3 −799,25
10 160 𝑢2 − 2𝑢3 =−799,25
𝑥3 = 0,75 ; 𝑢 − 2𝑢3 =−799,25
0,252 2 𝑢1 1,2336
𝑢2 = 2,48125
𝑢3 3,7383
194

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝟏
𝒇′′𝒔 ≅ 𝒇 − 𝟐𝒇𝒔 + 𝒇𝒔−𝟏
𝒉𝟐 𝒔+𝟏

◦ Usando una aproximación central de la derivada segunda, hallar u(x) en forma discreta con 3
puntos interiores en [0;L]

𝑑2 𝑢(𝑥)
𝐸𝐽 2
+𝑃 𝑥−𝐿 = 0 𝑢 0 =0 𝐸𝐽 = 10000
𝑑𝑥
𝑑𝑢(𝐿) 𝑃 = 100
=0 L = 10
𝑑𝑥

x 0L 0,25 L 0,5 L 0,75 L 1L


u(x) U0 U1 U2 U3 U4

195

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝟏
𝒇′′𝒔 ≅ 𝒇 − 𝟐𝒇𝒔 + 𝒇𝒔−𝟏 𝑑 2 𝑢(𝑥)
𝒉𝟐 𝒔+𝟏 𝐸𝐽 +𝑃 𝑥−𝐿 =0 𝑢 0 =0
𝑑𝑥 2 𝐸𝐽 = 10000
𝑃 = 100
𝑑𝑢(𝐿) L = 10
x 0L 0,25 L 0,5 L 0,75 L 1L 𝑑𝑥
=0
u(x) 0 U1 U2 U3 U4

◦ 𝑥0 = 0 ; 𝑢0 = 0
102
◦ 𝑥1 = 2,5; 0 − 2𝑢1 + 𝑢2 + 100 2,5 − 10 = 0
0,252
102
◦ 𝑥2 = 5,0; 𝑢1 − 2𝑢2 + 𝑢3 + 100 5,0 − 10 = 0
0,252
102
◦ 𝑥3 = 7,5; 𝑢2 − 2𝑢3 + 𝑢4 + 100 7,50 − 10 = 0
0,252
3 2 1
◦ 𝑥4 = 10; 𝑢4 − 0,25 𝑢3 + 2 𝑢2 =0
2 0,25 10 10 0,25 10

196

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝟏
𝒇′′𝒔 ≅ 𝒇 − 𝟐𝒇𝒔 + 𝒇𝒔−𝟏 𝑑 2 𝑢(𝑥)
𝒉𝟐 𝒔+𝟏 𝐸𝐽 +𝑃 𝑥−𝐿 =0 𝑢 0 =0
𝑑𝑥 2 𝐸𝐽 = 10000
𝑃 = 100
𝑑𝑢(𝐿) L = 10
x 0L 0,25 L 0,5 L 0,75 L 1L 𝑑𝑥
=0
u(x) 0 U1 U2 U3 u4

ℎ = 0,25 ∗ 𝐿 = 2,5
◦ 𝑥0 = 0 ; 𝑢0 = 0
◦ 𝑥1 = 2,5; 16 102 0 − 2𝑢1 + 𝑢2 = 750
◦ 𝑥2 = 5,0; 16 102 𝑢1 − 2𝑢2 + 𝑢3 = 500
◦ 𝑥3 = 7,5; 16 102 𝑢2 − 2𝑢3 + 𝑢4 = 250
16 102
◦ 𝑥4 = 10; (0,6 𝑢4 − 0,8 𝑢3 + 0,2 𝑢2 ) = 0
16 102

−2 1 0 0 𝑢1 750
1 −2 1 0 𝑢2 500
16 102 0 1 −2 1 𝑢3 =
0,2 −0,8 0,6 250
0 𝑢4 0
16 102 16 102 16 102 197

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


−3200 1600 0 0 𝑢1 750
1600 −3200 1600 0 𝑢2 500
𝑢3 =
0 1600 −3200 1600 250
0 1/5 −0,8 0,6 𝑢4 0

−3200 1600 0 𝑢1 750


◦ 1600 −3200
2
1600
1
𝑢2 = 500
0 1600 − 3 3200 𝑢3 250
3

1 4
𝑢4 = − 𝑢2 + 𝑢3
3 3

𝑢0 = 0 ; 𝑢1 = −1,0156; 𝑢2 = −1,5625 ; 𝑢3 = −1,7969; 𝑢4 = −1,8750

198

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝑑2 𝑣(𝑥)
𝑇 𝑑𝑥 2 + 𝜔 2 𝜌 𝑥 𝑣(𝑥) =0 con 𝑣 0 = 𝑣 𝐿 = 0

◦ L= 12 T=500

x 0 2,0 4,0 6,0 8,0 10 12


𝜌 𝑥 10 20 40 80 40 20 10

199

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


x 0 2,0 4,0 6,0 8,0 10 12
◦ L= 12 T=500
𝜌 𝑥 10 20 40 80 40 20 10
𝑑2 𝑣(𝑥)
𝑇 𝑑𝑥 2 + 𝜔 2 𝜌 𝑥 𝑣(𝑥) =0 con 𝑣 0 = 𝑣 𝐿 = 0

𝑥0 = 0; 𝑣0 = 0

𝑥1 = 2; 150 0 − 2 𝑣1 + 𝑣2 + 𝜔 2 20 𝑣1 = 0
𝑥2 = 4; 150 𝑣1 − 2 𝑣2 + 𝑣3 + 𝜔 2 40 𝑣2 = 0
𝑥3 = 6; 150 𝑣2 − 2 𝑣3 + 𝑣4 + 𝜔 2 80 𝑣3 = 0
𝑥4 = 8; 150 𝑣3 − 2 𝑣4 + 𝑣5 + 𝜔 2 40 𝑣4 = 0
𝑥5 = 10; 150 𝑣4 − 2 𝑣5 + 𝑣0 + 𝜔 2 20 𝑣5 = 0

𝑥6 = 12; 𝑣6 = 𝑣 𝐿 = 0

200

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝑥0 = 0; 𝑣0 = 0

𝑥1 = 2; 125 0 − 2 𝑣1 + 𝑣2 + 𝜔 2 20 𝑣1 = 0
𝑥2 = 4; 125 𝑣1 − 2 𝑣2 + 𝑣3 + 𝜔 2 40 𝑣2 = 0
𝑥3 = 6; 125 𝑣2 − 2 𝑣3 + 𝑣4 + 𝜔 2 80 𝑣3 = 0
𝑥4 = 8; 125 𝑣3 − 2 𝑣4 + 𝑣5 + 𝜔 2 40 𝑣4 = 0
𝑥5 = 10; 125 𝑣4 − 2 𝑣5 + 0 + 𝜔 2 20 𝑣5 = 0

𝑥6 = 12; 𝑣6 = 𝑣 𝐿 = 0

−2 1 0 0 0 20 0 0 0 0 𝑣1 0
1 −2 1 0 0 0 40 0 0 0 𝑣2 0
2 𝑣3 = 0
125 0 1 −2 1 0 + 𝜔 0 0 80 0 0
0 0 1 −2 1 0 0 0 40 0 𝑣4 0
0 0 0 1 −2 0 0 0 0 20 𝑣5 0

201

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


−2 1 0 0 0 20 0 0 0 0 𝑣1 0
1 −2 1 0 0 0 40 0 0 0 𝑣2 0
2 𝑣3 = 0
125 0 1 −2 1 0 + 𝜔 0 0 80 0 0
0 0 1 −2 1 0 0 0 40 0 𝑣4 0
0 0 0 1 −2 0 0 0 0 20 𝑣5 0

𝑀+𝜔2K . 𝑣=0 λ =-14.9728

−14,9728

𝐴−λ𝐼 . 𝑣 =0 5,9239
𝑣𝑝 = −1,5625
5,9239
−14,9728

𝐾 −1 𝑀 − (−𝜔 2 ) 𝐾 −1 K . 𝑣 = 0
202

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


ECUACIONES DIFERENCIALES ORDINARIAS
CON VALORES INICIALES EULER

DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN



𝑑𝑦
𝑓 𝑥, 𝑦 = 𝑦 = ; 𝑉. 𝐼. 𝑦 𝑥0 = 𝑦0
𝑑𝑥

𝑑𝑦
𝑑𝑥
=2 𝑦 −2 𝑥 −1 𝑐𝑜𝑛 𝑦 0 = 2

𝑦𝑚+1 = 𝑦𝑚 + ℎ 𝑦′𝑚 Método de Euler

204
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑑𝑦
𝑑𝑥
=2 𝑦 −2 𝑥 −1 𝑐𝑜𝑛 𝑦 0 = 2

𝑦𝑚+1 = 𝑦𝑚 + ℎ 𝑦′𝑚 Método de Euler


h=0,1
Solución exacta
𝑦𝑒𝑥 = 𝑒 2𝑥 + 𝑥 + 1
X Y Y’ Error=
Abs(yex.- y)
0 2 3 Abs(2-2)=0
0+h=0+0,1=0,1 2+0,1 * 3=2,3 2 * 2,3 – 2 * 0,1-1=3,4
0,2 2,3+0,1*3,4=2,64 2*2,64-2*0,2-1=3,88 Abs(2,69-2,64)=0,05

205
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑦𝑚+1 = 𝑦𝑚 + ℎ 𝑦′𝑚 Método de Euler

𝑑𝑦
=2 𝑦 −2 𝑥 −1 𝑐𝑜𝑛 𝑦 0 = 2
𝑑𝑥

h=0,025
error
10 0.35
yaprox
9 yex
0.3

8
0.25

7
0.2
6
0.15
5

0.1
4

3 0.05

2 0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
206
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
RUNGE-KUTTA
𝑑𝑦 DE SEGUNDO ORDEN

=2 𝑦 −2 𝑥 −1 𝑐𝑜𝑛 𝑦 0 = 2
𝑑𝑥

Conocidos (𝒙𝒎 ; 𝒚𝒎 ) 𝒚 𝒂𝒔𝒖𝒎𝒊𝒅𝒐𝒔 𝒉 𝒚 𝝎 𝒔𝒆 𝒄𝒂𝒍𝒄𝒖𝒍𝒂:

𝑘1 = ℎ 𝑓 𝑥𝑚 ; 𝑦𝑚 = ℎ 𝑦′𝑚
ℎ 𝑘1
𝑘2 = ℎ 𝑓 𝑥𝐺 ; 𝑦𝐺 = ℎ 𝑦′𝐺 𝑥𝐺 = 𝑥𝑚 + 𝑦𝐺 = 𝑦𝑚 +
2𝜔 2𝜔

𝑦𝑚+1 = 𝑦𝑚 + 1 − 𝜔 𝑘1 + 𝜔 𝑘2
𝑥𝑚+1 = 𝑥𝑚 + ℎ 207
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑑𝑦
=2 𝑦 −2 𝑥 −1 𝑐𝑜𝑛 𝑦 0 = 2
𝑑𝑥
xm ym k1 xG yG k2
h=0,1 ; 𝜔=1
0 2 0,3 0,05 2,15 0,32
0,1 2,32 0,344 0,15 2,492 0,3684
0,2 2,6884 0,39768 0,25 2,88724 0,427448

0,3 3,115848 0,4631696 0,35 3,3474328 0,49948656


𝑘1 = ℎ 𝑓 𝑥𝑚 ; 𝑦𝑚 = ℎ 𝑦′𝑚
𝑘2 = ℎ 𝑓 𝑥𝐺 ; 𝑦𝐺 = ℎ 𝑦′𝐺
0,4 3,61533456 0,54306691 0,45 3,88686802 0,5873736

0,5 4,20270816 0,64054163 0,55 4,52297898 0,6945958 ℎ 1 𝑘


𝑥𝐺 = 𝑥𝑚 + 2 𝜔 𝑦𝐺 = 𝑦𝑚 + 2 𝜔
0,6 4,89730396 0,75946079 0,65 5,27703436 0,82540687

0,7 5,72271083 0,90454217 0,75 6,17498191 0,98499638


𝒚𝒎+𝟏 = 𝒚𝒎 + 𝟏 − 𝝎 𝒌𝟏 + 𝝎 𝒌𝟐
0,8 6,70770721 1,08154144 0,85 7,24847793 1,17969559

0,9 7,8874028 1,29748056 0,95 8,53614308 1,41722862 𝑥𝑚+1 = 𝑥𝑚 + ℎ


1 9,30463142 1,56092628 1,05 10,0850946 1,70701891
208
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
%%% RUNGE- KUTTA 𝑘1 = ℎ 𝑓 𝑥𝑚 ; 𝑦𝑚 = ℎ 𝑦′𝑚
𝑘2 = ℎ 𝑓 𝑥𝐺 ; 𝑦𝐺 = ℎ 𝑦′𝐺
% y'=2y-2x-1
clear;clc;
ℎ 1 𝑘
𝑥𝐺 = 𝑥𝑚 + 2 𝜔 𝑦𝐺 = 𝑦𝑚 + 2 𝜔

a=0; b=10; %intervalo de cálculo


x(1)=0; y(1)=4; V.I. 𝒚𝒎+𝟏 = 𝒚𝒎 + 𝟏 − 𝝎 𝒌𝟏 + 𝝎 𝒌𝟐

h=0.1; w=1; 𝑥𝑚+1 = 𝑥𝑚 + ℎ

for i=1:(((b-a)/h))
k1=h*(2*y(i)-2*x(i)-1);
xG=x(i)+(h/2*w);
yG=y(i)+(k1/(2*w));
k2=h*(2*yG-2*xG-1);
y(i+1)=y(i)+(1-w)*k1+w*k2;
x(i+1)=x(i)+h;
yex(i+1)= exp(2*x(i+1))+x(i+1)+1;
end
yex(1)=exp(2*x(1))+x(1)+1;
plot(x,y,'k',x,yex,'sg')
legend('y','yex')
209
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑑𝑦 1 1
+ 𝑦= 𝑡; 𝑦 0 = 4
𝑑𝑡 2 2
a) Identificar la función f(x,y)
b) Elaborar un programa MATLAB que resuelva el ejercicio con el
método de Euler, para valores de 𝑡0 ; 𝑦0 𝑦 𝐷𝑡 elegidos.
𝑡
c) La solución exacta es 𝑦𝑒𝑥 = 6 𝑒
−2
− 2 + 𝑡.
d) Graficar la solución exacta, la aproximación obtenida por el
método de Euler y por el método de R-K
e) Obtener la función error como la diferencia de ambas soluciones y
graficarla

210
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑑𝑦 1 1
+ 𝑦= 𝑡; 𝑦 0 = 4
𝑑𝑡 2 2

Yex= 6 e^(-t/2)-2+t
211
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝒅
𝒖 𝒕 = 𝒗(𝒕) 𝒖 𝟎 =𝟎
𝒅𝒕 𝒄𝒐𝒏 𝒕 𝝐 [𝟎; +∞)
𝒗 𝟎 =𝟎
𝒅 𝒑 𝒌
𝒗 𝒕 = 𝒔𝒆𝒏𝒐 𝜴 𝒕 − 𝒖(𝒕)
𝒅𝒕 𝒎 𝒎

𝑑 𝑢(𝑡) 𝑣(𝑡) 𝑢 0 =0
= 𝑝 𝑘 𝑐𝑜𝑛 𝑡 𝜖 [0; +∞)
𝑑𝑡 𝑣(𝑡) 𝑠𝑒𝑛𝑜 Ω 𝑡 − 𝑢(𝑡) 𝑣 0 =0
𝑚 𝑚

en forma matricial

𝑢′(𝑡) 0 1 𝑢(𝑡) 0
= + 𝑝
𝑣′(𝑡) −𝑘/𝑚 0 𝑣(𝑡) 𝑠𝑒𝑛𝑜(Ω 𝑡)
𝑚
212
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝑘1 = ℎ 𝑓 𝑥𝑚 ; 𝑦𝑚 = ℎ 𝑦′𝑚
𝑘2 = ℎ 𝑓 𝑥𝐺 ; 𝑦𝐺 = ℎ 𝑦′𝐺

ℎ 1 𝑘
𝑥𝐺 = 𝑥𝑚 + 2 𝜔 𝑦𝐺 = 𝑦𝑚 + 2 𝜔

MÉTODO DE EULER 𝒚𝒎+𝟏 = 𝒚𝒎 + 𝟏 − 𝝎 𝒌𝟏 + 𝝎 𝒌𝟐 ; 𝜔 =0


𝒚 𝒎+𝟏 = 𝒚 𝒎 + 𝒌 𝟏 = h . 𝒚′ 𝒎
𝑥𝑚+1 = 𝑥𝑚 + ℎ

𝑢′(𝑡) 0 1 𝑢(𝑡) 0
= + 𝑝
𝑣′(𝑡) −𝑘/𝑚 0 𝑣(𝑡) 𝑠𝑒𝑛𝑜(Ω 𝑡)
𝑚

𝑢𝑚 0 1 𝑢𝑚 0
𝑦𝑚+1 = 𝑣 +ℎ 𝑣𝑚 + 𝑝
𝑚 −𝑘/𝑚 0 𝑠𝑒𝑛𝑜(Ω 𝑡)
𝑚

213
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
0
𝑢𝑚 0 1 𝑢𝑚 1
𝑦𝑚+1 = 𝑣 + 0,01 𝑣𝑚 +
𝑚 −0,2/0,9 0 𝑠𝑒𝑛𝑜(0,65 𝑡)
0,9

%%Euler matrices
clear all;clc;
p=1; k=0.2;
O=0.65; m=0.9;
y(:,1)=[0;0];
h=0.01;
t=0:h:20; t
for z=2:((20/h)+1)
y(:,z)=y(:,z-1)+h*[y(2,z-1); (p/m)*sin(O*t(z-1))-(k/m)*y(1,z-1)];
end
plot(t,y(1,:),'r',t,y(2,:),'b')
title('Método de Euler con matrices')
legend('u(t)','v(t)')
214
%% Runge Kutta para w=0, 0,5 y 1
clear all;clc;
p=1; k=0.2;
O=0.65; m=0.9;
y(:,1)=[0;0];
h=0.01;
w=1;
t=0:h:20;
for z=2:((20/h)+1)
k1=h*[y(2,z-1); (p/m)*sin(O*t(z-1))-(k/m)*y(1,z-1)];
if w=~0
tG=t(z-1)+(h/(2*w)); yG=y(:,z-1)+(k1/(2*w));
k2=h*[yG(2,1); (p/m)*sin(O*tG)-(k/m)*yG(1,1)];
end
y(:,z)=y(:,z-1)+(1-w)*k1+w*k2;
end 215
%%Runge Kutta con matrices
clear all;clc;
p=1; k=0.2; O=0.65; m=0.9;
y(:,1)=[0;0];
h=0.01; w=1; t=0:h:20;
A=[0 1; -k/m 0];
for z=2:((20/h)+1)
k1=h*((A*y(:,z-1))+[0; (1/m)*sin(O*t(z-1))]);
if w=~0
tG=t(z-1)+(h/(2*w)); yG=y(:,z-1)+(k1/(2*w));
k2=h*((A*yG(:,1))+[0; (1/m)*sin(O*tG)]);
end
y(:,z)=y(:,z-1)+(1-w)*k1+w*k2;
end
plot(t,y(1,:),'r',t,y(2,:),'b') 216
Ecuaciones Diferenciales de Segundo Orden reducidas a un Sistema de primer orden

𝑑2𝜃 𝑔 Π
+ 𝜃 =0 𝜃 𝑡 0 = 𝜃0 = ; 𝑡0 =0
𝑑𝑡 2 𝐿 4
𝑑𝜃
𝑡0 = 𝜃′ 0 = 0; 𝜃′ 0 = 𝛼
𝑑𝑡

𝑑𝜃
=𝛼 𝑦0 =
𝜋/4
𝑑𝑡 0

𝜋/4 0 1 𝜋/4
𝑦1 = 𝑦0 + ℎ 𝑦0′ = + 0,1
0 −𝑔/𝐿 0 0
𝑑𝛼 𝑑 2 𝜃 𝑔
= 2 =− 𝜃 𝑦=
𝜃
𝑑𝑡 𝑑𝑡 𝐿 𝛼
0 1 𝜃
𝑦′ = 𝜃 = =Ay
𝛼 −𝑔/𝐿 0 𝛼

217
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
𝜃′ = 0 1 𝜃 Π
𝜃 𝑡0 = 𝑡0 =0
𝛼′ −0,981 0 𝛼 4
𝑑𝜃
𝑡0 = 0
𝑑𝑡

218
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
EULER
1,5

1
Alfa
0,5 1,5

0 1
0 2 4 6 8 10 12
-0,5 0,5

-1 0 Tita
-1,5 -1 -0,5 0 0,5 1 1,5
-1,5 -0,5

Tita Alfa
-1

-1,5

219
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
R-K

220
DRA. ING. SELVA S. RIVERA - PROF. ADJUNTA - CÁLCULO NUMÉRICO Y COMPUTACIÓN
DIFERENCIA
CENTRAL

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝒙𝟏 (𝒕)+4 𝒙𝟏 (𝒕)+4 𝒙𝟐 (𝒕) +𝒙𝟑 𝒕 = 𝟓𝒆𝒕 + 𝟖𝒆𝟐𝒕 + 𝒄𝒐𝒔(𝒕)
−𝒙𝟐 (𝒕)- 𝒙𝟐 (𝒕)+4 𝒙𝟏 (𝒕) +𝟐𝒙𝟐 𝒕 = −𝟖𝒆𝟐𝒕 + 𝟒𝒆𝒕
𝟐𝒙𝟑 𝒕 + 𝟑 𝒙𝟑 (𝒕)+ 𝒙𝟏 (𝒕) + 𝒙𝟑 𝒕 = − 𝒄𝒐𝒔 𝒕 − 𝟑𝒔𝒆𝒏 𝒕 + 𝒆𝒕

𝒙𝟏 (𝟎) 𝟏 𝒙𝟏 (𝟎) 𝟏
◦ 𝒄𝒐𝒏 𝒗𝒂𝒍𝒐𝒓𝒆𝒔 𝒊𝒏𝒊𝒄𝒊𝒂𝒍𝒆𝒔 𝒙𝟐 (𝟎) = 𝟐 𝒙𝟐 (𝟎) = 𝟒
𝒙𝟑 (𝟎) 𝟏 𝒙𝟑 (𝟎) 𝟎
1 0 0 𝑥1 (𝑡) 4 0 0 𝑥1 0 4 1 𝑥1 5𝑒 𝑡 + 8𝑒 2𝑡 + cos(𝑡)
◦ 0 −1 0 𝑥2 (𝑡) + 0 −1 0 𝑥2 + 4 2 0 𝑥2 = −8𝑒 2𝑡 + 4𝑒 𝑡
0 0 2 𝑥3 (𝑡) 0 0 3 𝑥3 1 0 1 𝑥3 − cos 𝑡 − 3𝑠𝑒𝑛 𝑡 + 𝑒 𝑡

𝑴 𝒖 𝒕 + 𝑪 𝒖 𝒕 +𝑲 𝒖 𝒕 = 𝑹(𝒕)
222

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


𝑴 𝒖 𝒕 + 𝑪 𝒖 𝒕 +𝑲 𝒖 𝒕 = 𝑹(𝒕)
Se aproxima la 𝒖 𝒕 y la 𝒖 𝒕 con derivadas numéricas centrales :

𝟏
𝑴 𝟐 𝒖 𝒕 − 𝜟𝒕 − 𝟐 𝒖 𝒕 + 𝒖(𝒕 + 𝜟𝒕) +
𝜟𝒕
𝟏
+𝑪 𝟐 𝜟𝒕
−𝒖 𝒕 − 𝜟𝒕 + 𝒖(𝒕 + 𝜟𝒕) +

+𝑲 𝒖 𝒕 = 𝑹(𝒕)
223

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Despejamos u(t+ Δ t) :

𝟏 𝟏
𝑴 𝒖 𝒕 − 𝜟𝒕 − 𝟐 𝒖 𝒕 + 𝒖(𝒕 + 𝜟𝒕) + 𝑪 −𝒖 𝒕 − 𝜟𝒕 + 𝒖(𝒕 + 𝜟𝒕) + 𝑲 𝒖 𝒕 = 𝑹(𝒕)
𝜟𝒕𝟐 𝟐 𝜟𝒕

𝟏 𝟏 𝟏 𝟏 𝟏
𝑴 +𝑪 𝒖 𝒕 + 𝜟𝒕 = −𝑴 +𝑪 𝒖(𝒕 − 𝜟𝒕) + 2 𝑴 − 𝑲 𝑢 𝑡 + 𝑅(𝑡)
𝜟𝒕𝟐 𝟐 𝜟𝒕 𝜟𝒕𝟐 𝟐 𝜟𝒕 𝜟𝒕𝟐

𝟏 𝟏 −1 𝟏 𝟏 𝟏
𝒖 𝒕 + 𝜟𝒕 = 𝑴 +𝑪 −𝑴 +𝑪 𝒖(𝒕 − 𝜟𝒕) + 2 𝑴 − 𝑲 𝑢 𝑡 + 𝑅(𝑡)
𝜟𝒕𝟐 𝟐 𝜟𝒕 𝜟𝒕𝟐 𝟐 𝜟𝒕 𝜟𝒕𝟐

224

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Despejamos u(t+ Δ t) :

𝟏 𝟏 −1 𝟏 𝟏 𝟏
𝒖 𝒕 + 𝜟𝒕 = 𝑴 𝜟𝒕𝟐
+𝑪 𝟐 𝜟𝒕
−𝑴 𝜟𝒕𝟐
+𝑪 𝟐 𝜟𝒕
𝒖(𝒕 − 𝜟𝒕) + 2 𝑴 𝜟𝒕𝟐
− 𝑲 𝑢 𝑡 + 𝑅(𝑡)

Y Z
X

Son matrices que se


calculan una sola vez
al inicio del método
225

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Despejamos u(t+ Δ t) :

𝟏 𝟏 −1 𝟏 𝟏 𝟏
𝒖 𝒕 + 𝜟𝒕 = 𝑴 +𝑪 −𝑴 +𝑪 𝒖(𝒕 − 𝜟𝒕) + 2 𝑴 − 𝑲 𝑢 𝑡 + 𝑅(𝑡)
𝜟𝒕𝟐 𝟐 𝜟𝒕 𝜟𝒕𝟐 𝟐 𝜟𝒕 𝜟𝒕𝟐

𝒖 𝒕 + 𝜟𝒕 = X 𝑌 𝒖(𝒕 − 𝜟𝒕) +𝑍 𝒖 𝒕 + 𝑅(𝑡)

Para e𝒏𝒄𝒐𝒏𝒕𝒓𝒂𝒓 𝒆𝒍 𝒗𝒂𝒍𝒐𝒓 𝒖(𝒕 − 𝜟𝒕)𝒔𝒆 𝒃𝒖𝒔𝒄𝒂 𝒖𝒏𝒂 𝒂𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒄𝒊ó𝒏


mediante Serie de Tylor:
𝟏 𝟐
𝒖(𝒕0 − 𝜟𝒕)= 𝑢 𝑡0 − 𝜟𝒕 𝒖 𝒕𝟎 + 𝜟𝒕 𝒖(𝒕𝟎 )
𝟐
226

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación


Resumiendo
◦ Partimos de 𝑴 𝒖 𝒕 + 𝑪 𝒖 𝒕 +𝑲 𝒖 𝒕 = 𝑹(𝒕)
◦ Con V.I. como datos 𝒖 𝒕𝟎 y 𝒖 𝒕𝟎
◦ Reemplazamos por derivadas centrales 𝒖 𝒕 y 𝒖 𝒕 en
◦ despejamos
𝒖 𝒕 + 𝜟𝒕 = X 𝑌 𝒖(𝒕 − 𝜟𝒕) +𝑍 𝒖 𝒕 + 𝑅(𝑡)
◦ Para iterar

◦ Calculamos con Serie de Tylor 𝟏 𝟐


𝒖(𝒕0 − 𝜟𝒕)= 𝑢 𝑡0 − 𝜟𝒕 𝒖 𝒕𝟎 + 𝜟𝒕 𝒖(𝒕𝟎 )
(por única vez) 𝟐

dato
V.I.
dato

227
%% DIFERENCIA CENTRAL
clear all;clc; %%Serie de Tylor
M=[1 0 0;0 -1 0;0 0 2]; d2x=(M^-1)*(R0-K*x(:,1)-(C*dx(:,1)))
C=[4 0 0;0 -1 0;0 0 3]; xant=x(:,1)-Dt*dx(:,1)+0.5*(Dt^2)*d2x
K=[0 4 1;4 2 0;1 0 1]; %%%-----------------------------------------
%% Condiciones iniciales %%% ITERACIONES
x(:,1)=[1;2;1]; for k=2:((8/Dt)+1)
dx(:,1)=[1;4;0]; Rt=[5*exp(t(k))+8*exp(2*t(k))+cos(t(k));...
Dt=0.0032; -8*exp(2*t(k))+4*exp(t(k));...
t=0:Dt:8; -cos(t(k))-3*sin(t(k))+exp(t(k))];
R0=[5*exp(t(1))+8*exp(2*t(1))+cos(t(1));... x(:,k)=X*(Y*xant+Z*x(:,k-1)+Rt);
-8*exp(2*t(1))+4*exp(t(1));... xant=x(:,k-1);
-cos(t(1))-3*sin(t(1))+exp(t(1))]; end
X=((M*(1/(Dt^2)))+(C*(1/(2*Dt))) )^-1 yex=[exp(t);2*exp(2*t);cos(t)]; ## solución exacta
Y= (-M*(1/(Dt^2)))+(C*(1/(2*Dt))) plot(t,x(3,:),t,yex(3,:),'pr') ##gráfico de la tercer componente
Z=(2*M*(1/(Dt^2))-K); grid on
legend('Solución Numérica','Solución exacta')

228
𝑥1 (𝑡) 𝑒𝑡
◦ 𝑥2 (𝑡) = 2 𝑒 2𝑡 solución exacta
𝑥3 (𝑡) cos(t)

229

Dra. Ing. Selva S. Rivera - Prof. Adjunta - Cálculo Numérico y Computación

También podría gustarte