Trabajo Final de Metodos
Trabajo Final de Metodos
Trabajo Final de Metodos
UNIVERSIDAD AUTONOMA DE
COAHUILA
FACULTAD DE CIENCIAS QUIMICAS
“TRABAJO FINAL
LAB1-LAB11”
METODOS NUMERICOS
ALUMNO: ROBERTO GUADALUPE TREVIÑO RODRIGUEZ
MAESTRO: M.C EFRAIN VIESCA VILLANUEV
2 JUNIO 2016
1
ROBERTO TREVIÑO
2
ROBERTO TREVIÑO
3
ROBERTO TREVIÑO
Nonlinear equations
General Settings
4
ROBERTO TREVIÑO
if Fa*Fb<=0
ALGORITMO
c=b;
%Metodo de Biseccion - Metodos Numericos Matlab
Fc=Fb;
clc;
else
5
ROBERTO TREVIÑO
a=b;
end
end
fprintf('\nEl resultado sera %.8f\n',b); 10.2500 10.2813 10.3125 -61.0747 -11.9666 37.7432 0.0625
ezplot(Fx);%graficamos la funcion
Ingrese la funcion: x^ 3 * 15 - x ^ 2 * 154.5439 + x* 2.196 - 10.2813 10.2891 10.2969 -11.9666 0.4043 12.8129 0.0156
.174582
Ingrese a : 10
10.2813 10.2852 10.2891 -11.9666 -5.7859 0.4043 0.0078
Ingrese c : 11
6
ROBERTO TREVIÑO
10.2886 10.2887 10.2888 -0.3700 -0.1764 0.0171 0.0002 Metodo punto fijo
f(x)=x^3-x- 3
𝑥 = √𝑥 + 1
1=0
10.2887 10.2888 10.2888 -0.1764 -0.0797 0.0171 0.0001
i Xo g(Xo) /Xo-g(Xo)/
1 2 1.44224957 0.55775043
2 1.44224957 1.3466767 0.09557287
El volumen es 10.28875732 Litros
3 1.3466767 1.32887589 0.01780081
LABORATORIO 2 4 1.32887589 1.32550727 0.00336862
5 1.32550727 1.32486787 0.0006394
Metodo punto fijo 6 1.32486787 1.32474643 0.00012144
f(x)=x^3-x- 3 7 1.32474643 1.32472337 2.3064E-05
1=0 𝑥 = √𝑥 + 1
8 1.32472337 1.32471899 4.3846E-06
i Xo g(Xo) /Xo-g(Xo)/ 9 1.32471899 1.32471815 8.3659E-07
1 1 1.2599210 0.25992105 La solucion es 1.32472337 con un error 4.3846E-
5 06
2 1.25992105 1.3122938 0.052372787
4
3 1.31229384 1.3223538 0.01005998 Newton Raphson
2 f(x)=x^3-x-1=0 f´(x)=3x^2-1=0
4 1.32235382 1.3242687 0.001914925 i xo f(xo) f'(xo) x /x-xo/
4 1 1 -1 2 1.5 0.5
5 1.32426874 1.3246326 0.000363884
2 1.5 0.875 5.75 1.347826 0.152173
2
09 91
6 1.32463262 1.3247017 6.91275E-05
3 1.347826 0.1006821 4.449905 1.325200 0.022625
5
09 87 51 4 69
7 1.32470175 1.3247148 1.31287E-05
4 1.325200 0.0020583 4.268468 1.324718 0.000482
8
4 66 3 17 23
8 1.32471488 1.3247173 2.49273E-06
5 1.324718 9.07323E- 4.264634 1.324717 2.1276E-
7
17 07 69 96 07
La solucion es 1.32471488 con un error de
la solucion es 1.32471817 con error de
2.49273E-06
2.1276E-07
7
ROBERTO TREVIÑO
Bisectriz
x=(7x-3)/(x-.45)^2
Metodo secante
i X1 X2 Xm /X1-Xm/ f(X1 f(Xm) f(X1)*f(Xm)
f(x)=x^3-x-1=0
)
i x1 f(x1) error D 1 0. 0. 0.4 0.05 -80 #¡DIV/0!
0 1 -1 4 5 5
1 2 5 1 0.83333333
2 1.16666667 -0.5787037 0.83333333 -0.08644537
Bisectriz
3 1.25311203 -0.28536303 0.08644537 -0.08409441
x=(7x-3)/(x-.45)^2
4 1.33720645 0.05388059 0.08409441 0.01335635
i X1 X2 Xm /X1-Xm/ f(X1) f(Xm)
5 1.3238501 -0.00369812 0.01335635 -0.00085784
1 0.39 0.53 0.46 0.07 -75 2200
6 1.32470794 -4.2734E-05 0.00085784 -1.0029E-05
2 0.39 0.46 0.425 0.035 -75 -40
7 1.32471797 3.4582E-08 1.0029E-05 8.1091E-09
3 0.425 0.46 0.4425 0.0175 -40 1733.3
la solucion es 1.32471797 con un error de 8.1091E-09
4 0.425 0.4425 0.43375 0.00875 -40 137.27
5 0.425 0.43375 0.429375 0.004375 -40 13.223
Newton Raphson 6 0.425 0.429375 0.4271875 0.0021875 -40 -18.61
f(x)=x^3-x-1=0 f´(x)=3x^2-1=0 7 0.4271875 0.429375 0.42828125 0.00109375 -18.6151248 -4.306
i xo f(xo) f'(xo) x /x-xo/ 8 0.42828125 0.429375 0.42882813 0.00054688 -4.30619533 4.0086
1 2 5 11 1.545454 0.454545 9 0.42828125 0.42882813 0.42855469 0.00027344 -4.30619533 -0.254
55 45 10 0.42855469 0.42882813 0.42869141 0.00013672 -0.25481004 1.8496
2 1.545454 1.145755 6.165289 1.359614 0.185839 11 0.42855469 0.42869141 0.42862305 6.8359E-05 -0.25481004 0.7906
55 1 3 92 63
12 0.42855469 0.42862305 0.42858887 3.418E-05 -0.25481004 0.2662
3 1.359614 0.153704 4.545658 1.325801 0.033813
92 95 19 35 57 13 0.42855469 0.42858887 0.42857178 1.709E-05 -0.25481004 0.0053
4 1.325801 0.004624 4.273247 1.324719 0.001082 14 0.42855469 0.42857178 0.42856323 8.5449E-06 -0.25481004 -0.124
35 94 66 05 3 La solucion es .42856323 con error de 8.5449E-06
5 1.324719 4.6578E- 4.264641 1.324717 1.0922E-
05 06 68 96 06
la solucion es 1.32471905 con error de Algoritmo Matlab Newton Raphson
1.0922E-06 x0=input('Ingrese el valor inicial: ');
tol=input('Ingrese el porcentaje de error: ');
f=input('Ingrese la función: ');
8
ROBERTO TREVIÑO
9
ROBERTO TREVIÑO
x^3-x-1
Ingrese la función despejada:
(x+1)^(1/3)
Ingrese el punto inicial:
10
ROBERTO TREVIÑO
11
ROBERTO TREVIÑO
Tolerance F 0.0000001
Tolerance X 0.0000001
Tolerance min 0.0000001
1 1 0 3 4 La solucion es
x1=1 x2=0
x3=2 x4=1
0 -1 -1 -5 -7
0 0 3 13 19
0 0 0 -13 -13
Nonlinear equations
1 f(x) = x ^ 3 - x - 1 = 0
General Settings
Total number of equations 1
Number of implicit equations 1
Number of explicit equations 0
Elapsed time 0.0000 sec
Solution method SAFENEWT
Max iterations 150
12
ROBERTO TREVIÑO
[n n]=size(A); x=A(:,n+1)./diag(A)
for p=1:n A=
for k=[1:p-1,p+1:n]; 1 1 0 3
m=-A(k,p)/A(p,p); 2 1 -1 1
A(k,:)=A(k,:)+m*A(p,:) 3 -1 -1 2
end -1 2 3 -1
13
ROBERTO TREVIÑO
>> B=[4;1;3;4] 0 3 3 2 8
B= A=
4 1 0 -1 -2 -3
1 0 -1 -1 -5 -7
3 0 -4 -1 -7 -9
4 0 3 3 2 8
>> eliminacion(A,B) A=
A= 1 0 -1 -2 -3
1 1 0 3 4 0 -1 -1 -5 -7
0 -1 -1 -5 -7 0 0 3 13 19
3 -1 -1 2 3 0 3 3 2 8
-1 2 3 -1 4 A=
A= 1 0 -1 -2 -3
1 1 0 3 4 0 -1 -1 -5 -7
0 -1 -1 -5 -7 0 0 3 13 19
0 -4 -1 -7 -9 0 0 0 -13 -13
-1 2 3 -1 4 A=
0 -4 -1 -7 -9 0 0 0 -13.0000 -13.0000
14
ROBERTO TREVIÑO
A= 1 0 0 0 1
0 0 0 -13.0000 -13.0000
A=
0 0 0 -13.0000 -13.0000
A=
1.0000 0 0 0 1.0000
0 0 0 -13.0000 -13.0000
A=
1 0 0 0 1
0 -1 0 0 0
0 0 3 13 19
0 0 0 -13 -13
A=
15
ROBERTO TREVIÑO
0 0 0 -13 -13
x=
Metodo Gauss-Jordan
3 -0.1 -0.2 7.85 1 -0.03333333 -0.066666667
0.1 7 -0.3 -19.3 0.1 7 -0.3
0.3 -0.2 10 71.4 0.3 -0.2 10
Metodo Gauss-Jordan
3 -0.1 -0.2 7.85 1 - - 2.6166 1 0 0 2.999
0.0333 0.06666 6667 9999
3333 6667 9
0. 7 -0.3 -19.3 0. 7 -0.3 -19.3 0 1 0 -
1 1 2.500
0001
3
0. -0.2 10 71.4 0. -0.2 10 71.4 0 0 0.999 6.999
3 3 99999 9999
8 9
16
ROBERTO TREVIÑO
1 0 - 2.523 1 0 - 2.5235
0.068 5602 0.06806 602
06283 2827
0 1 - - 0 1 - -
0.041 2.793 0.04188 2.7931
88482 19385 4817 9385
0 0 10.01 70.08 0 0 0.99999 6.9999
20419 42932 9998 9999
clc;
%Metodo de Gauss-Jordan
[MA,NA]=size(A);
[MB,NB]=size(B);
17
ROBERTO TREVIÑO
A=[A,B'];
[M,N]=size(A);
for j=2:M+1
piv=j-1;
pivm=max(A(:,piv));
for k=piv:M
if A(k,piv)==pivm
temp=A(piv,:);
A(piv,:)=A(k,:);
A(k,:)=temp;
end
end
for i=j:M
A(i,:)=A(i,:)-A(i,piv)*A(piv,:)/A(piv,piv);
end
for l=1:piv-1
A(l,:)=A(l,:)-A(l,piv)*A(piv,:)/A(piv,piv);
end
end
%Resultado
for h=1:M
x(h)=A(h,N)/A(h,h);
end
18
ROBERTO TREVIÑO
A=
0 4.5000 0 -7.2458
0 0 3.2778 9.5000
x=
Metodo de la Inversa
1 2 4 11
4 1 -1 6
2 5 2 3
clc;
19
ROBERTO TREVIÑO
for k=1:c
for j=1:f
fprintf('Fila: %x\n',j)
fprintf('Columna: %x',k);
A(j,k)=r;
j=j+1;
end
k=k+1;
end
B=A;
pause
for k=k:c*2
for j=1:f
fprintf('Fila: %x\n',j)
fprintf('Columna: %x',k)
A(j,k)=r;
j=j+1;
end
k=k+1;
end
pause
for k=1:c
A(k,:)=A(k,:)/A(k,k);
20
ROBERTO TREVIÑO
for j=k+1:f
A(j,:)=A(j,:)-A(k,:)*A(j,k);
j=j+1;
pause
end
k=k+1;
pause
end
for k=f:-1:2
for j=k-1:-1:1
A(j,:)=A(j,:)-A(k,:)*A(j,k);
j=j-1;
pause
end
k=k-1;
pause
end
c=inv(B);
Fila: 1
21
ROBERTO TREVIÑO
Fila: 2
Fila: 3
Fila: 1
Fila: 2
Fila: 3
Fila: 1
Fila: 2
Fila: 3
A=
1 4 2
2 1 5
4 -1 2
Fila: 1
Fila: 2
Fila: 3
Fila: 1
22
ROBERTO TREVIÑO
Fila: 2
Fila: 3
Fila: 1
Fila: 2
Fila: 3
A=
1 4 2 1 0 0
2 1 5 0 1 0
4 -1 2 0 0 1
A=
1 4 2 1 0 0
0 -7 1 -2 1 0
4 -1 2 0 0 1
A=
1 4 2 1 0 0
0 -7 1 -2 1 0
0 -17 -6 -4 0 1
A=
1 4 2 1 0 0
0 -7 1 -2 1 0
0 -17 -6 -4 0 1
A=
23
ROBERTO TREVIÑO
A=
A=
A=
A=
A=
A=
A=
24
ROBERTO TREVIÑO
c=
METODO DE D.G.O
5 6 -2 2 1
6 -5 -2 2 0
-2 -2 3 -1 0
-2 2 -1 -3 0
-61 2 -2 -6
2 11 -1 2
22 -9 -11 2
-135 13 -22
101 143 2
338 -32
-0.09467456 x4
0.15384615 x3
0.10650888 x2
0.17159763 x1
2.61666667 1 2.616666667
-2.75714286 2 3.000761905
7.14 3 3.003365306
4 3.002702244
5 3.002681306
6 3.002682177
25
ROBERTO TREVIÑO
7 3.002682235
clc;
%Metodo de Gauss-Seidel
n=length(A);
X=x;
for k=1:m
h=A*x';
if abs(h-B')<E
break
end
for i=1:n
sum=0;
26
ROBERTO TREVIÑO
for j=1:n
if i~=j
sum=sum+A(i,j)*x(j);
end
end
x(i)=(B(i)-sum)/A(i,i);
end
if abs(X-x)<E
break
end
X=x;
fprintf('%d\t%d\n',k,x)
end
disp(x)
1 2.616667e+00
-2.794524e+00 7.005610e+00
2 2.990557e+00
-2.499625e+00 7.000291e+00
3 3.000032e+00
-2.499988e+00 6.999999e+00
27
ROBERTO TREVIÑO
Jacobi
10 1 2 3
4 6 -1 9
-2 3 8 51
clc;
%Metodo de Jacobi
28
ROBERTO TREVIÑO
n=length(A);
X=x;
for k=1:m
H=A*x';
if abs(H-B')<E
break
end
for i=1:n
sum=0;
for j=1:n
if i~=j
sum=sum+A(i,j)*x(j);
end
end
U(i)=(B(i)-sum)/A(i,i);
end
for i=1:n
x(i)=U(i);
end
if abs(X-x)<E
break
end
X=x;
fprintf('%d\t%d\n',k,x)
end
29
ROBERTO TREVIÑO
disp(x);
Para verificar el funcionamiento del programa se presentan dos ejemplos vistos en clase:
1 2.616667e+00
-2.757143e+00 7.140000e+00
2 3.000762e+00
-2.488524e+00 7.006357e+00
3 3.000806e+00
-2.499738e+00 7.000207e+00
4 3.000022e+00
-2.500003e+00 6.999981e+00
La respuesta final es
30
ROBERTO TREVIÑO
1 1.122449e-03
1.894068e-03 3.294118e-03
2.112676e-03 7.446809e-04
2 8.559198e-04
1.461017e-03 2.119568e-03
1.539284e-03 3.787474e-04
3 9.273781e-04
1.597613e-03 2.404364e-03
1.755350e-03 4.863792e-04
La respuesta final es
31
ROBERTO TREVIÑO
32
ROBERTO TREVIÑO
%Newton-Raphson multivariable
clear all; close all; clc;
%funciones x^2-10x+y^2+8=0
% xy^2+x-10y+8=0
f=inline('[x(1)^2-10*x(2)+x(2)^2+8; x(1)*x(2)^2+x(1)-10*x(2)+8]');
df=inline('[ 2*x(1)-10 2*x(2); x(2)^2+1 2*x(1)*x(2)-10 ]');
%Punto de partida para x e y
x0=[0;0];
%iteraciones maximas
maxi=2000;
%tolreancia
tol=1.e-6;
corr=tol+1;
k=0;
while k<=maxi & norm(corr,inf)>tol
fx0=feval(f,x0);
dfx0=feval(df,x0);
corr=dfx0\fx0;
x=x0-corr;
x0=x;
k=k+1;
end
disp('La solucion es ')
disp(x)
if norm(corr,inf)>tol
error ('Se alcanzo el numero maximo de iteraciones ')
end
disp(['Se calculo en ' num2str(k) 'iteraciones'])
La solucion es
0.9930
0.9983
Se alcanzo el numero maximo de iteraciones
33
ROBERTO TREVIÑO
34
ROBERTO TREVIÑO
%Newton-Raphson multivariable
clear all; close all; clc;
%funciones x^2-10x+y^2+8=0
% xy^2+x-10y+8=0
f=inline('[x(1)^2-10*x(2)+x(2)^2+8; x(1)*x(2)^2+x(1)-10*x(2)+8]');
df=inline('[ 2*x(1)-10 2*x(2); x(2)^2+1 2*x(1)*x(2)-10 ]');
%Punto de partida para x e y
x0=[0;0];
%iteraciones maximas
maxi=2000;
%tolreancia
tol=1.e-6;
corr=tol+1;
k=0;
while k<=maxi & norm(corr,inf)>tol
fx0=feval(f,x0);
dfx0=feval(df,x0);
corr=dfx0\fx0;
x=x0-corr;
x0=x;
k=k+1;
end
disp('La solucion es ')
disp(x)
if norm(corr,inf)>tol
error ('Se alcanzo el numero maximo de iteraciones ')
end
disp(['Se calculo en ' num2str(k) 'iteraciones'])
LABORATORIO 5
Interpolación y aproximación
Interpolación lineal
35
ROBERTO TREVIÑO
T(°C) R(Ω)
10 98
15 99.5
20 103
25 107
30 112
35 116
40 122
a) b)
110 31.8125
Matlab cuenta con un comando para la interpolación lineal. El comando interp1 determina el
valor funcional de una abscisa especificada denotada por xi interpolando linealmente a partir de
la tabla de la función.
La sintaxis es: yi=interp1(x, y, xi)
T(°C) R
10 98
15 99.5
20 103
25 107
30 112
35 116
40 122
36
ROBERTO TREVIÑO
Ti=[17,28,32]';
Propdad=interp1(Temp,R,Ti,'linear');
[Ti,Propdad]
ans =
17.0000 100.9000
28.0000 110.0000
32.0000 113.6000
37
ROBERTO TREVIÑO
Polinomio de Lagrange
38
ROBERTO TREVIÑO
ans =
109.9834
39
ROBERTO TREVIÑO
x y
i V(ft^3) P(psia) x*y x^2 yc ABS %D
1 26.43 14.7 388.521 698.5449 9.5049501 5.1950499 35.3404755
2 22.4 17.53 392.672 501.76 17.0759613 0.45403871 2.59006678
40
ROBERTO TREVIÑO
βi βo ȳ ӿ
41
ROBERTO TREVIÑO
MINIMOS CUADRADOS
i T (°C)[X] R(Ω)[Y] XiYi Xi^2 Yc %Dif.
1 10 98 980 100 96 2.04081633
2 15 99.5 1492.5 225 100.071429 0.57430007
3 20 103 2060 400 104.142857 1.10957004
4 25 107 2675 625 108.214286 1.13484646
5 30 112 3360 900 112.285714 0.25510204
6 35 116 4060 1225 116.357143 0.30788177
7 40 122 4880 1600 120.428571 1.28805621
Σ 175 757.5 19507.5 5075 6.71057292
β1= nΣXiYi-ΣXiΣYi/nΣXi^2-(Σxi)^2
β1= 0.81428571
42
ROBERTO TREVIÑO
y media=Σyi/n
y media= 108.214286
x media=Σxi/n
x media= 25
Yc=β0+β1Xi
El objetivo es encontrar una ecuación que nos permita calcular los valores de la variable
dependiente para diferentes valores de la variable independiente.
El método de ajuste que se presenta es el método de mínimos cuadrados, cuyo método hace que
el cuadrado de la suma de los errores tienda a cero.
El ejercicio siguiente se hizo en clase:
Encontrar una ecuación que nos permita calcular la resistencia eléctrica para una determinada
temperatura.
T(ºC) R(Ω)
10 98
15 99.5
20 103
25 107
30 112
35 116
40 122
function [A,B]=lsline(X,Y)
%Datos
% - X es el vector de las abscisas 1 x n
% - Y es el vector de ordenadas 1 x n
%Resultados
% - A es el coeficiente de x en Ax + B
% - B es el termino independiente en Ax + B
xmean=mean(X);
ymean=mean(Y);
sumx2=(X-xmean)*(X-xmean)';
sumxy=(Y-ymean)*(X-xmean)';
A=sumxy/sumx2
43
ROBERTO TREVIÑO
B=ymean-A*xmean
A=
0.8143
B=
87.8571
ans =
0.8143
LABORATORIO N° 6
Primer problema
Punto Fijo
n X1 X2 f(X1) f(X2) Xm f(Xm) /XI-Xm/ f(Xi)*f(Xm)
1 0.5 1 -1.7171875 5.35 0.62149016 0.77450114 0.12149016 -1
2 0.5 0.62149016 -1.7171875 0.77450114 0.58372691 0.08493779 0.08372691 -1
3 0.5 0.58372691 -1.7171875 0.08493779 0.57978069 0.00881157 0.07978069 -1
4 0.5 0.57978069 -1.7171875 0.00881157 0.57937339 0.00090865 0.07937339 -1
5 0.5 0.57937339 -1.7171875 0.00090865 0.57933142 9.3642E-05 0.07933142 -1
6 0.5 0.57933142 -1.7171875 9.3642E-05 0.57932709 9.6498E-06 0.07932709 -1
7 0.5 0.57932709 -1.7171875 9.6498E-06 0.57932664 9.944E-07 0.07932664 -1
8 0.5 0.57932664 -1.7171875 9.944E-07 0.5793266 1.0247E-07 0.0793266 -1
9 0.5 0.5793266 -1.7171875 1.0247E-07 0.57932659 1.056E-08 0.07932659 -1
10 0.5 0.57932659 -1.7171875 1.056E-08 0.57932659 1.0882E-09 0.07932659 -1
11 0.5 0.57932659 -1.7171875 1.0882E-09 0.57932659 1.1214E-10 0.07932659 -1
12 0.5 0.57932659 -1.7171875 1.1214E-10 0.57932659 1.1553E-11 0.07932659 -1
13 0.5 0.57932659 -1.7171875 1.1553E-11 0.57932659 1.1866E-12 0.07932659 -1
14 0.5 0.57932659 -1.7171875 1.1866E-12 0.57932659 1.279E-13 0.07932659 -1
15 0.5 0.57932659 -1.7171875 1.279E-13 0.57932659 0 0.07932659 0
Bisectriz
44
ROBERTO TREVIÑO
resultado es .579345
45
ROBERTO TREVIÑO
>> biseccion('0.65*x.^5-9*x.^4+45.4*x.^3-88*x.^2+82.3*x-26',0.001)
46
ROBERTO TREVIÑO
ans =
0.5793
function y=falsap(fun,an,bn,tol)
u=subs(fun,an);
v=subs(fun,bn);
a=an;
b=bn;
while abs(u)>tol
p=a-u*(b-a)/(v-u);
w=subs(fun,p);
if u*v<0
a=an;
b=p;
else
a=p;
b=bn;
end
u=subs(fun,a);
v=subs(fun,b);
end
p
falsap('.65*x^5-9*x^4+45.4*x^3-88*x^2+82.3*x-26',0.5,1,0.001)
p=
0.57932659286195026184645437063161
GUASS
47
ROBERTO TREVIÑO
A x b
4 1 -1 x1 -2
5 1 2 x2 4
6 1 1 x3 6
4 1 -1 -2
5 1 2 4 1.25
6 1 1 6 1.5
4 1 -1 -2 -4
0 -0.25 3.25 6.5 (7)-(f7)(6)
0 -0.5 2.5 9 (8)-(f8)(6) 2
4 0 12 24 (10)-(f10)(11)
0 -0.25 3.25 6.5
0 0 -4 -4 (12)-(f12)(11)
x3 1
x2 -13
x1 3
4 1 -1 3 -2
5 1 2 -13 4
6 1 1 1 6
function y=eliminacion(A,B)
[n n]=size(A);
A=[A';B']';
x=zeros(n,1);
for p=1:n
for k=[1:p-1,p+1:n];
48
ROBERTO TREVIÑO
m=-A(k,p)/A(p,p);
A(k,:)=A(k,:)+m*A(p,:)
end
end
x=A(:,n+1)./diag(A)
0 -0.2500 3.2500
Column 4
-2.0000
6.5000
6.0000
A=
Columns 1 through 3
0 -0.2500 3.2500
0 -0.5000 2.5000
Column 4
-2.0000
6.5000
9.0000
A=
Columns 1 through 3
4.0000 0 12.0000
0 -0.2500 3.2500
0 -0.5000 2.5000
Column 4
24.0000
49
ROBERTO TREVIÑO
6.5000
9.0000
A=
Columns 1 through 3
4.0000 0 12.0000
0 -0.2500 3.2500
0 0 -4.0000
Column 4
24.0000
6.5000
-4.0000
A=
Columns 1 through 3
4.0000 0 0
0 -0.2500 3.2500
0 0 -4.0000
Column 4
12.0000
6.5000
-4.0000
A=
Columns 1 through 3
4.0000 0 0
0 -0.2500 0
0 0 -4.0000
Column 4
12.0000
3.2500
-4.0000
x=
-13
50
ROBERTO TREVIÑO
Ultimo problema
METODO DE D.G.O
1 1 -1 -3
6 2 2 2
-3 4 1 1
-4 8 20
7 -2 -8
12 27
2.25 z
-0.5 y
-0.25 x
function y=eliminacion(A,B)
[n n]=size(A);
A=[A';B']';
x=zeros(n,1);
for p=1:n
for k=[1:p-1,p+1:n];
m=-A(k,p)/A(p,p);
A(k,:)=A(k,:)+m*A(p,:)
end
end
x=A(:,n+1)./diag(A)
A=
51
ROBERTO TREVIÑO
1 1 -1 -3
0 -4 8 20
-3 4 1 1
A=
1 1 -1 -3
0 -4 8 20
0 7 -2 -8
A=
1 0 1 2
0 -4 8 20
0 7 -2 -8
A=
1 0 1 2
0 -4 8 20
0 0 12 27
A=
Columns 1 through 3
1.0000 0 0
0 -4.0000 8.0000
0 0 12.0000
Column 4
-0.2500
20.0000
27.0000
A=
Columns 1 through 3
1.0000 0 0
0 -4.0000 0
52
ROBERTO TREVIÑO
0 0 12.0000
Column 4
-0.2500
2.0000
27.0000
x=
-0.2500
-0.5000
2.2500
Newton raphson
2 2
f(x)=sen(x) + cos(1+xdy/dx=cos(x)-2xsen(1+x
) -1 ) x=radianes
x=2 127.32395
el resultado es 2.5322158
53
ROBERTO TREVIÑO
54
ROBERTO TREVIÑO
else
raiz=v1;
end
>> newtonraphson('sin(x)+cos(1+x^2)-1',2.5,3,0.0001)
ans =
2.5322
Problema 2
LABORATORIO N° 7
55
ROBERTO TREVIÑO
log V log P
n V(ft^3) P(psia) Xi Yi XiYi Xi^2 Yc Po %D
1 26.43 14.7 1.42209716 1.16731733 1.66003867 2.02236034 1.16370931 14.5783815 0.827336
2 22.4 17.53 1.35024802 1.24378192 1.67941407 1.82316971 1.23872038 17.3268806 1.158696
3 19.08 20.8 1.28057837 1.31806333 1.6878834 1.63988096 1.31145604 20.4859469 1.509870
4 16.32 24.54 1.21272015 1.38987456 1.68552889 1.47069017 1.38230055 24.1157378 1.728859
5 12.04 28.83 1.08062649 1.45984464 1.57754679 1.1677536 1.52020738 33.1289279 14.91130
6 12.12 32.71 1.08350262 1.51468054 1.64116034 1.17397793 1.51720468 32.900665 0.582895
7 10.51 39.25 1.02160272 1.59383966 1.62827093 1.04367211 1.58182866 38.1793617 2.727740
8 9.15 45.49 0.96142109 1.65791594 1.59395535 0.92433052 1.64465875 44.1223616 3.006459
9 8 52.52 0.90308999 1.72032472 1.55360803 0.81557152 1.70555688 50.7641226 3.343254
Sumatoria 136.05 276.37 10.3158866 13.0656426 14.7074065 12.0814069 13.0656426 275.602386 29.7964
β1 β0 ȳ ӿ a
-1.04400787 2.64838994 1.45173807 1.14620962 445.030663
1 0 0 158.936458 Bo B1 B2
0 1 0 32.96875 158.936458 32.96875 -0.08283333
0 0 1 -0.08283333
56
ROBERTO TREVIÑO
57
ROBERTO TREVIÑO
Yi X2
Xi Yi X1^2 X1^2 X2^2 X1*X2 Yi*X2 Yi*X1 Calculado %D
1 2 9 81 81 6561 729 162 18 5.41340624 1.706703
2 3 6 36 36 1296 216 108 18 3.30149901 0.100499
3 4 5 25 25 625 125 100 20 3.32629396 0.168426
4 7 10 100 100 10000 1000 700 70 6.84613934 0.021980
5 8 9 81 81 6561 729 648 72 5.41340624 0.323324
6 9 11 121 121 14641 1331 1089 99 8.64325445 0.039638
7 5 2 4 4 16 8 20 10 5.58697087 0.117394
8 5 3 9 9 81 27 45 15 4.46902989 0.106194
Suma 43 55 457 457 39781 4165 2872 322 43 2.584160
58
ROBERTO TREVIÑO
59
ROBERTO TREVIÑO
60
ROBERTO TREVIÑO
E
n nu Re Pr m/mw yi xi x2 x3 x1^2 x2^2 x3^2
1 97.45 10500 18.2 0.85 1.988781843 4.021189299 1.260071388 -0.070581074 16.16996338 1.587779903 0.0049816
2 109.5 12345 17.1 0.9 2.039414119 4.091491094 1.23299611 -0.045757491 16.74029937 1.520279408 0.0020937
3 129.9 15220 16.8 0.96 2.113609151 4.182414652 1.225309282 -0.017728767 17.49259232 1.501382836 0.0003143
4 147.76 18300 15.3 1.05 2.169556882 4.26245109 1.184691431 0.021189299 18.16848929 1.403493786 0.0004489
5 153.44 21050 12.1 1.08 2.18593859 4.3232521 1.08278537 0.033423755 18.69050872 1.172424158 0.0011171
6 168.9 25310 10.1 1.15 2.22762965 4.403292145 1.004321374 0.06069784 19.38898172 1.008661422 0.0036842
7 177.65 28560 8.7 1.18 2.249565212 4.455758203 0.939519253 0.071882007 19.85378116 0.882696426 0.0051670
8 175.16 31300 6.5 1.22 2.243434937 4.495544338 0.812913357 0.086359831 20.20991889 0.660828125 0.007458
SUMA 1159.76 162585 104.8 8.39 17.21793038 34.23539292 8.742607564 0.139485401 146.7145349 9.737546065 0.025265
Gauss-Jordan
61
ROBERTO TREVIÑO
1 0 0 -1.64152 -1.835255512
0 1 0 0.375039 0.847147311
0 0 1 0.04942 0.33142897
0 0 0 1 0.186543537
1 0 0 0 -1.529039732
0 1 0 0 0.777186138
0 0 1 0 0.32220997
0 0 0 1 0.186543537
B0 -1.529039732
B1 0.777186138
B2 0.32220997
B3 0.186543537
Log(s)=a+bt+ct^2
62
ROBERTO TREVIÑO
Yi X1 X2
n t s X1^2 X1^2 X2^2 X1X2 YiX1 YiX2 t calc %D
1 0 61.5 3782.25 3782.25 14305415.06 232608.4 0 0 2.81528
2 10 62.1 3856.41 3856.41 14871898.09 239483.1 621 38564.1 6.547113 0.3452
3 27.4 66.3 4395.69 4395.69 19322090.58 291434.2 1816.62 120441.9 28.2848 0.0322
4 42.1 70.3 4942.09 4942.09 24424253.57 347428.9 2959.63 208062 41.8528 0.0058
Suma 79.5 260.2 16976.44 16976.44 72923657.29 1110955 5397.25 367068 79.5 0.3834
Bo -1210.43
B1 33.10483
B2 -0.21752
5.36 Yi X1 X2
n I t(s) X1^2 X1^2 X2^2 X1X2 YiX1 YiX2 Yc %D
1 0.073 0.1 0.01 0.01 0.0001 0.001 0.0073 0.00073 0.08892857 0.2181996
2 0.22 0.2 0.04 0.04 0.0016 0.008 0.044 0.0088 0.19921429 0.0944805
3 0.301 0.3 0.09 0.09 0.0081 0.027 0.0903 0.02709 0.29314286 0.0261034
4 0.37 0.4 0.16 0.16 0.0256 0.064 0.148 0.0592 0.37071429 0.001930
5 0.418 0.5 0.25 0.25 0.0625 0.125 0.209 0.1045 0.43192857 0.0333219
6 0.467 0.6 0.36 0.36 0.1296 0.216 0.2802 0.16812 0.47678571 0.0209544
7 0.517 0.7 0.49 0.49 0.2401 0.343 0.3619 0.25333 0.50528571 0.0226581
SUMA 2.366 2.8 1.4 1.4 0.4676 0.784 1.1407 0.62177 2.366 0.4176486
63
ROBERTO TREVIÑO
5.32 Yi X1 X2
n T(K) k X1^2 X1^2 X2^2 X1X2 YiX1 YiX2 Yc %D
1 293 0.0000853 7.2761E-09 7.2761E-09 5.2941E-17 6.2065E-13 0.0249929 2.1319E-06 316.232807 0.07929286
2 300 0.000191 3.6481E-08 3.6481E-08 1.3309E-15 6.9679E-12 0.0573 1.0944E-05 316.274454 0.05424818
3 320 0.00156 2.4336E-06 2.4336E-06 5.9224E-12 3.7964E-09 0.4992 0.00077875 316.813155 0.00995889
4 340 0.01 0.0001 0.0001 0.00000001 0.000001 3.4 0.034 320.105753 0.05851249
5 360 0.0522 0.00272484 0.00272484 7.4248E-06 0.00014224 18.792 0.9809424 335.831958 0.06713345
6 380 0.2284 0.05216656 0.05216656 0.00272135 0.01191484 86.792 19.8232928 388.226903 0.02164975
7 400 0.8631 0.74494161 0.74494161 0.554938 0.6429591 345.24 297.976644 399.51497 0.00121257
SUMA 2393 1.1555363 0.79993549 0.79993549 0.55766679 0.65501719 454.805493 318.815671 2393 0.29200819
5.31 Yi X1 X2
n X Y X1^2 X1^2 X2^2 X1X2 YiX1 YiX2 Yc %D
1 2 1.07 1.1449 1.1449 1.31079601 1.225043 2.14 2.2898 2.44716156 0.22358078
2 4 1.88 3.5344 3.5344 12.4919834 6.644672 7.52 14.1376 2.45917104 0.38520724
3 6 2.26 5.1076 5.1076 26.0875778 11.543176 13.56 30.6456 6.20347466 0.03391244
4 12 2.78 7.7284 7.7284 59.7281666 21.484952 33.36 92.7408 15.1965583 0.26637986
5 18 2.97 8.8209 8.8209 77.8082768 26.198073 53.46 158.7762 19.5978101 0.08876723
6 24 2.99 8.9401 8.9401 79.925388 26.730899 71.76 214.5624 20.0958243 0.16267399
SUMA 66 13.95 35.2763 35.2763 257.352189 93.826815 181.8 513.1524 66 1.16052154
3lna=8.2677 2.75591151 a
15.7353773
5.35 Yi X1 X2
n P(atm) t(min) t^2 x1^2 X2^2 X1X2 YiX1 YiX2 calc %D
1 1 0 0 0 0 0 0 0 1.00888344 0
2 1.0631 0.1 0.01 0.01 0.0001 0.001 0.10631 0.010631 1.06202209 9.62022094
3 1.2097 0.3 0.09 0.09 0.0081 0.027 0.36291 0.108873 1.19970504 2.9990168
4 1.3875 0.5 0.25 0.25 0.0625 0.125 0.69375 0.346875 1.37926218 1.75852435
5 1.7232 0.8 0.64 0.64 0.4096 0.512 1.37856 1.102848 1.72711198 1.15888998
6 2 1 1 1 1 1 2 2 2.01135459 1.01135459
7 2.91 1.5 2.25 2.25 5.0625 3.375 4.365 6.5475 2.90516068 0.93677379
SUMA 11.2935 4.2 4.24 4.24 6.5428 5.04 8.90653 10.116727 11.2935 17.4847804
64
ROBERTO TREVIÑO
β1 β0 ȳ ӿ a
-1.04400787 2.64838994 1.45173807 1.14620962 445.030663
clc;
%Metodo de minimos cuadrados
n=input('inserte el numero de datos: ');
sx=0;
sy=0;
sz=0;
sw=0;
for i=1:1:n
x(i)=input('Valor de X: ')
y(i)=input('Valor de Y: ')
sx=sx+x(i);
sy=sy+y(i);
z(i)=x(i)*y(i)
sz=z(i)+sz;
w(i)=(x(i))^2
sw=w(i)+sw;
end
my=sy/n
mx=sx/n
B1=((n*sz)-(sx*sy))/((n*sw)-(sx^2))
B0=my-(B1*mx)
sf=0;
sd=0;
for i=1:1:n
f(i)=B0*(B1*x(i))
d(i)=((abs(y(i)-f(i)))/y(i))*100
sf=sf+f(i);
sd=sd+d(i);
65
ROBERTO TREVIÑO
end
md=sd/n
inserte el numero de datos: 9
Valor de X: log(26.43)
x=
3.2745
Valor de Y: log(14.7)
y=
2.6878
z=
8.8014
w=
10.7223
Valor de X: log(22.4)
x=
3.2745 3.1091
Valor de Y: log(17.53)
y=
2.6878 2.8639
z=
8.8014 8.9041
w=
10.7223 9.6663
Valor de X: log(19.08)
x=
3.2745 3.1091 2.9486
Valor de Y: log(20.8)
y=
Valor de X: log(16.32)
x=
3.2745 3.1091 2.9486 2.7924
Valor de Y: log(24.59)
y=
2.6878 2.8639 3.0350 3.2023
z=
8.8014 8.9041 8.9490 8.9422
w=
10.7223 9.6663 8.6945 7.7974
66
ROBERTO TREVIÑO
Valor de X: log(14.04)
x=
3.2745 3.1091 2.9486 2.7924 2.6419
Valor de Y: log(28.83)
y=
2.6878 2.8639 3.0350 3.2023 3.3614
z=
8.8014 8.9041 8.9490 8.9422 8.8806
w=
10.7223 9.6663 8.6945 7.7974 6.9797
Valor de X: log(12.12)
x=
3.2745 3.1091 2.9486 2.7924 2.6419 2.4949
Valor de Y: log(33.71)
y=
2.6878 2.8639 3.0350 3.2023 3.3614 3.5178
z=
8.8014 8.9041 8.9490 8.9422 8.8806 8.7764
w=
10.7223 9.6663 8.6945 7.7974 6.9797 6.2243
Valor de X: log(10.51)
x=
3.2745 3.1091 2.9486 2.7924 2.6419 2.4949 2.3523
Valor de Y: log(39.25)
y=
2.6878 2.8639 3.0350 3.2023 3.3614 3.5178 3.6700
z=
8.8014 8.9041 8.9490 8.9422 8.8806 8.7764 8.6329
w=
10.7223 9.6663 8.6945 7.7974 6.9797 6.2243 5.5334
Valor de X: log(9.15)
x=
Columns 1 through 7
3.2745 3.1091 2.9486 2.7924 2.6419 2.4949 2.3523
Column 8
2.2138
Valor de Y: log(45.49)
y=
Columns 1 through 7
2.6878 2.8639 3.0350 3.2023 3.3614 3.5178 3.6700
Column 8
3.8175
z=
Columns 1 through 7
67
ROBERTO TREVIÑO
901.3448
f=
-21.5389 -20.4507
68
ROBERTO TREVIÑO
d=
901.3448 814.0825
f=
-21.5389 -20.4507 -19.3955
d=
901.3448 814.0825 739.0708
f = -21.5389 -20.4507 -19.3955 -18.3677
d = 901.3448 814.0825 739.0708 673.5720
f = -21.5389 -20.4507 -19.3955 -18.3677 -17.3779
d = 901.3448 814.0825 739.0708 673.5720 616.9813
f = -21.5389 -20.4507 -19.3955 -18.3677 -17.3779 -16.4106
d=
901.3448 814.0825 739.0708 673.5720 616.9813 566.5028
f = -21.5389 -20.4507 -19.3955 -18.3677 -17.3779 -16.4106 -15.4731
d = 901.3448 814.0825 739.0708 673.5720 616.9813 566.5028 521.6154
f=
Columns 1 through 7
-21.5389 -20.4507 -19.3955 -18.3677 -17.3779 -16.4106 -15.4731
Column 8
-14.5616
d=
Columns 1 through 7
901.3448 814.0825 739.0708 673.5720 616.9813 566.5028 521.6154
Column 8
481.4435
f=
Columns 1 through 7
-21.5389 -20.4507 -19.3955 -18.3677 -17.3779 -16.4106 -15.4731
Columns 8 through 9
-14.5616 -13.6781
d=
Columns 1 through 7
901.3448 814.0825 739.0708 673.5720 616.9813 566.5028 521.6154
Columns 8 through 9
481.4435 445.3025
md = 639.9906
69
ROBERTO TREVIÑO
1.0688 0 0.2
0.4 2.456
0.8 0.232
n=8 h 0.1
A %D x f(x)
1.6008 2.4199939 0 0.2
0.1 1.289
0.2 1.288
0.3 1.607
0.4 2.456
0.5 3.325
0.6 3.464
0.7 2.363
0.8 0.232
LABORATORIO N° 8
f(x)=.2+25x-200x^2+675x^3-
900x^4+400x^5 a=0 b=.8
trapezoid
al n=1 n=2 n=8
N=1 A %D
89.46662
0.1728 6
N=2 h 0.4
A x f(x)
1.0688 0 0.2
0.4 2.456
0.8 0.232
n=8 h 0.1
A %D x f(x)
2.419993
1.6008 9 0 0.2
0.1 1.289
0.2 1.288
0.3 1.607
0.4 2.456
0.5 3.325
0.6 3.464
0.7 2.363
0.8 0.232
f(x)=.2+25x-200x^2+675x^3-
900x^4+400x^5
70
ROBERTO TREVIÑO
Evaluación en la ventana de
comando de Matlab
>> trapeciocom('400*x^5-
900*x^4+675*x^3-
200*x^2+25*x+0.2',0,0.8,20)
fs =
40.637504
71
ROBERTO TREVIÑO
integral =
1.63414016
function
y=simpsoncom(fun,a,b,n)
fa=subs(fun,a);
fb=subs(fun,b);
h=(b-a)/n;
s1=0;
s2=0;
for i=1:n-1
x(i)=a+i*h;
end
for i=1:2:n-1
s1=s1+subs(fun,x(i));
end
for i=2:2:n-2
s2=s2+subs(fun,x(i));
end
integral=h*(fa+4*s1+2*s2+
fb)/3
Evaluación en la ventana de
comando de Matlab
>> simpsoncom('400*x^5-
900*x^4+675*x^3-
200*x^2+25*x+0.2',0,0.8,20)
72
ROBERTO TREVIÑO
integral =
1.64050602666666666666666666
66667
function
y=simpsonc(fun,a,b,n)
fa=subs(fun,a);
fb=subs(fun,b);
h=(b-a)/n;
s1=0;
s2=0;
for i=1:n-1
x(i)=a+i*h;
end
for i=1:2:n-1
s1=s1+subs(fun,x(i));
end
for i=2:2:n-2
s2=s2+subs(fun,x(i));
end
integral=3*h*(fa+3*s1+3*s
2+fb)/8
73
ROBERTO TREVIÑO
Evaluación en la ventana de
comando de Matlab
>> simpsonc('400*x^5-
900*x^4+675*x^3-
200*x^2+25*x+0.2',0,0.8,21)
integral =
1.78852908147262483749265050
70691
LABORATORIO° 9
74
ROBERTO TREVIÑO
METODO DE RALSTON
t a K1 K2 0.75hK1 yi+0.75hK1 K1/3 2K2/3 RALSTON
0 3 -0.02044595 -0.01881311 -0.46003393 2.53996607 -0.00681532 -0.01254208 2.41927821
30 2.41927821 -0.01836072 -0.01671975 -0.41311612 2.00616209 -0.00612024 -0.0111465 1.90127609
60 1.90127609 -0.01627681 -0.0146254 -0.36622824 1.53504785 -0.0054256 -0.00975026 1.44600004
90 1.44600004 -0.01419485 -0.01252953 -0.31938417 1.12661587 -0.00473162 -0.00835302 1.05346099
120 1.05346099 -0.01211591 -0.01043113 -0.27260792 0.78085308 -0.00403864 -0.00695409 0.72367931
150 0.72367931 -0.01004199 -0.00832809 -0.22594478 0.49773453 -0.00334733 -0.00555206 0.45669754
180 0.45669754 -0.00797739 -0.0062151 -0.17949137 0.27720617 -0.00265913 -0.0041434 0.25262158
75
ROBERTO TREVIÑO
LABORATORIO 10°
f(y) = x ^ 2 + y ^ 2 - 16
y(0) = 1
f(x) = (x - 4) ^ 2 + (y - 4) ^ 2 - 5
x(0) = 4
Calculated values of NLE variables
Variable Value f(x) Initial Guess
1 y 1.805829 5.105E-09 1.
2 x 3.569171 5.105E-09 4.
Nonlinear equations
1 f(y) = x ^ 2 + y ^ 2 - 16 = 0
2 f(x) = (x - 4) ^ 2 + (y - 4) ^ 2 - 5 = 0
General Settings
Total number of equations 2
Number of implicit equations 2
Number of explicit equations 0
Elapsed time 0.0000 sec
Solution method SAFENEWT
Max iterations 150
Tolerance F 0.0000001
Tolerance X 0.0000001
Tolerance min 0.0000001
f(y) = y + 5 * x * y - x ^ 2
76
ROBERTO TREVIÑO
y(0) = 1.2
f(x) = x ^ 2 - x + .75 - y
x(0) = 1.2
POLYMATH Report
Nonlinear Equations 11-abr-2016
Nonlinear equations
1 f(y) = y + 5 * x * y - x ^ 2 = 0
2 f(x) = x ^ 2 - x + .75 - y = 0
General Settings
Total number of equations 2
Number of implicit equations 2
Number of explicit equations 0
Elapsed time 0.0000 sec
Solution method SAFENEWT
Max iterations 150
Tolerance F 0.0000001
Tolerance X 0.0000001
Tolerance min 0.0000001
f(z) = y + 3 * x * z + x ^ 3
z(0) = 1
f(y) = (2.7182818284590452354 ^ (x + y)) - x ^ 2 * cos(x) - (3.1416 / 1.15)
y(0) = 1
f(x) = y * sin(x) + cos(x) - z
x(0) = 1
POLYMATH Report
Nonlinear Equations 11-abr-2016
Nonlinear equations
1 f(z) = y + 3 * x * z + x ^ 3 = 0
2 f(y) = (2.7182818284590452354 ^ (x + y)) - x ^ 2 * cos(x) - (3.1416 / 1.15) = 0
3 f(x) = y * sin(x) + cos(x) - z = 0
General Settings
Total number of equations 3
77
ROBERTO TREVIÑO
10 0
4.97 2.5
2.47 5 5.94
1.22 7.5
0.61 10 5.84224
0.3 12.5 3.39366565
0.14 15
LABORATORIO 11
METODO DE EULER
METODO DE EULER
METODO DE EULER MEJORADO
X Y H=.5 REAL X Y
0 1 8.5 1.25 1 0 1
0.5 5.25 1.25 -1.5 3.21875 0.5 3.4375
1 5.875 -1.5 -1.25 3 1 3.375
1.5 5.125 -1.25 0.5 2.21875 1.5 2.6875
2 4.5 0.5 2.25 2 2 2.5
2.5 4.75 2.25 2.5 2.71875 2.5 3.1875
78
ROBERTO TREVIÑO
metodo de renge-kulta 4
orden metodo de heum con un corrector
x y k1 k2 k3 k4 x y
0 1 8.5 4.21875 4.21875 8.5 0 1
0.5 3.82291667 1.25 -0.59375 -0.59375 1.25 0.5 3.4375
1 3.83333333 -1.5 -1.65625 -1.65625 -1.5 1 3.375
1.5 3.03125 -1.25 -0.46875 -0.46875 -1.25 1.5 2.6875
2 2.66666667 0.5 1.46875 1.46875 0.5 2 2.5
2.5 3.23958333 2.25 2.65625 2.65625 2.25 2.5 3.1875
3 4.5 2.5 1.59375 1.59375 2.5 3 4.375
3.5 5.44791667 -0.25 -3.21875 -3.21875 -0.25 3.5 4.9375
- -
4 4.33333333 -7.5 13.28125 13.28125 -7.5 4 3
S 31.875 28.5
79
ROBERTO TREVIÑO
80
ROBERTO TREVIÑO
81
ROBERTO TREVIÑO
x(0) = 0
x(f) = 4
d(y)/d(x) = -2 * x ^ 3 + 12 * x ^ 2 - 20 * x + 8.5
y(0) = 1
82
ROBERTO TREVIÑO
x(0) = 1
x(f) = 2
d(y)/d(x) = 2 * x - 2 * y + 1
y(0) = 5
x(0) = 0
x(f) = 3
d(y)/d(x) = -0.002665 - (19.62 * x) ^ 1 / 2
y(0) = 3
83
ROBERTO TREVIÑO
Método de Euler
function [t,w]=euler(f,a,b,ya,n)
h=(b-a)/n;
t=zeros(1,n+1);
w=zeros(1,n+1);
t(1)=a;
w(1)=ya;
for i=1:n
w(i+1)=w(i)+h*feval(f,t(i),w(i));
t(i+1)=a+h*i;
end
w
f=
Inline function:
f(t,y) = y-t^2+1
84
ROBERTO TREVIÑO
>> euler(f,0,2,0.5,10)
w=
Columns 1 through 7
Columns 8 through 11
ans =
Columns 1 through 7
Columns 8 through 11
85
ROBERTO TREVIÑO
Método de Heun
function [t,w]=Heun(f,a,b,ya,n)
%Datos
% - f es la funcion, almacenada como una cadena de
caracteres 'f'
% - a y b son los extremos derecho e izquierdo del
intervalo
% - ya es la condicion inicial y(a)
% - n es el numero de pasos
%Resultado
% - [t,w] siendo t el vector de las abscisas y w el
vector de las
% ordenas
% - Y el vector de las ordenadas
h=(b-a)/n;
t=zeros(1,n+1);
w=zeros(1,n+1);
t=a:h:b;
w(1)=ya;
for j=1:n
k1=feval(f,t(j),w(j));
k2=feval(f,t(j+1),w(j)+h*k1);
86
ROBERTO TREVIÑO
w(j+1)=w(j)+(h/2)*(k1+k2);
end
w
f=
Inline function:
f(t,y) = y-t^2+1
>> Heun(f,0,2,0.5,10)
w=
Columns 1 through 7
Columns 8 through 11
ans =
87
ROBERTO TREVIÑO
Columns 1 through 7
Columns 8 through 11
function [t,w]=rk4(f,a,b,ya,n)
%Datos
% - f es la funcion, alamcenada como una cadena de
caracteres 'f'
% - a y b son los extremos derecho e izquierdo del
intervalo
% - ya es la condicion inicial y(a)
% - n es el numero de pasos
h=(b-a)/n;
t=zeros(1,n+1);
w=zeros(1,n+1);
t=a:h:b;
w(1)=ya;
for j=1:n
k1=h*feval(f,t(j),w(j));
88
ROBERTO TREVIÑO
k2=h*feval(f,t(j)+h/2,w(j)+k1/2);
k3=h*feval(f,t(j)+h/2,w(j)+k2/2);
k4=h*feval(f,t(j)+h,w(j)+k3);
w(j+1)=w(j)+(k1+2*k2+2*k3+k4)/6;
end
w
f=
Inline function:
f(t,y) = t^2-y
>> rk4(f,0,0.4,1,4)
w=
ans =
89
ROBERTO TREVIÑO
División Sintética
90
ROBERTO TREVIÑO
91