Sei sulla pagina 1di 91

ROBERTO TREVIÑO

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

4.2 Newton rapshon multivariable


INDICE LABORATORIO 5
LABORATORIO 1 ………………………..3 5.1 Interpolación lineal
1.1 Ejercicio 1 5.2 Interpolación de LaGrange
1.1.1 Método de la bisección
5.3 Mínimos cuadrados
LABORATORIO 2 ………………………..9
LABORATORIO 6 …………….
2.1 Ejercicio 1
6.1 Corrección del Examen
2.1.1 Punto fijo
LABORATORIO 7……………..
2.1.2 Secante
7.1 Regresión multiple
2.1.3 Newton-Raphson
LABORATORIO 8………………
2.2 Ejercicio 2
8.1 Metodo de Integracion trapecio y simpsons 1/3 y 3/8
2.2.1 Secante
LABORATORIO 9
LABORATORIO 3………………………
9.1 Corrección del examen
3.1 Eliminación Gaussiana
LABORATORIO 10
3.2 Método de DGO
10.1 Método para solución de ecuaciones diferenciales
3.3 Método de Gauss-Seidal
10.1.1 Euler
3.4 Método de la inversa
10.1.2 Euler mejorado
3.5 Método Gauss Jordan
10.1.3 Runge Kutta 2° Orgen
3.6 Metodo de Jacobi
10.1.4 Runge Kutta 4° Orden
LABORATORIO 4……………..
10.1.5 Heum
4.1 Punto fijo multivariable
10.1.6 Poligono mejorado

2
ROBERTO TREVIÑO

3
ROBERTO TREVIÑO

LABORATORIO 1 METODO DE LA BISECCION Tolerance min 0.0000001


POLYMATH Report

Nonlinear Equation 25-ene-2016

Calculated values of NLE variables

Variable Value f(x) Initial Guess

1 V 10.28881 2.335E-10 10.5 ( 10. < V < 11. )

Nonlinear equations

1 f(V) = V ^ 3 * 15 - V ^ 2 * 154.5439 + V * 2.196 - .174582 = 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


Metodo de bisección
Tolerance F 0.0000001
iteracion V1 V2 Vm /V1-Vm/ f(v1) f(Vm
Tolerance X 0.0000001

4
ROBERTO TREVIÑO

1 10 11 10.5 0.5 -432.604582


Fx=input('Ingrese
348.793443la funcion:
(-) ','s');

2 10 10.5 10.25 0.25 -432.604582


a=input('Ingrese
-61.0747008a : ');(+)

3 10.25 10.5 10.375 0.125 -61.0747008


c=input('Ingrese
138.979198 c : ');(-)

4 10.25 10.375 10.3125 0.0625 -61.0747008


e=input('Ingrese
37.7431914 el error
(-) : ');

5 10.25 10.3125 10.28125 0.03125 -61.0747008 -11.9666456 (+)

6 10.28125 10.3125 10.296875 0.015625 -11.9666456


x=a; 12.8128785 (-)

7 10.28125 10.296875 10.2890625 0.0078125 -11.9666456


Fa=eval(Fx);
0.4042893 (-)

8 10.28125 10.2890625 10.2851563 0.00390625 -11.9666456


x=c; -5.78588227 (+)

9 10.2851563 10.2890625 10.2871094 0.00195313 -5.78588227


Fc=eval(Fx);
-2.69197285 (+)

10 10.2871094 10.2890625 10.2880859 0.00097656 -2.69197285


fprintf('\n
-1.14413591
%6s %7s %8s (+)%10s %8s %8s %8s \n
','A','B','C','F(a)','F(b)','F(c)','|c-a|');
11 10.2880859 10.2890625 10.2885742 0.00048828 -1.14413591 -0.36999684 (+)
while abs(c-a)>e
12 10.2885742 10.2890625 10.2888184 0.00024414 -0.36999684 0.01712784 (-)
b=(a+c)/2;
13 10.2885742 10.2888184 10.2886963 0.00012207 -0.36999684 -0.1764391 (+)
x=b;
14 10.2886963 10.2888184 10.2887573 6.1035E-05 -0.1764391 -0.07965678 (+)
Fb=eval(Fx);

La solución del volumen es = 10.28886963 litros


fprintf('\n %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f
\n',a,b,c,Fa,Fb,Fc,abs(c-a));

if Fa*Fb<=0
ALGORITMO
c=b;
%Metodo de Biseccion - Metodos Numericos Matlab
Fc=Fb;
clc;
else

5
ROBERTO TREVIÑO

a=b;

Fa=Fb; 10.2500 10.3750 10.5000 -61.0747 138.9792 348.7934 0.2500

end

10.2500 10.3125 10.3750 -61.0747 37.7432 138.9792 0.1250

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

grid on; 10.2813 10.2969 10.3125 -11.9666 12.8129 37.7432 0.0313

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

Ingrese el error : .0001


10.2852 10.2871 10.2891 -5.7859 -2.6920 0.4043 0.0039

A B C F(a) F(b) F(c) |c-a|


10.2871 10.2881 10.2891 -2.6920 -1.1441 0.4043 0.0020

10.0000 10.5000 11.0000 -432.6046 348.7934 1289.1695


10.2881 10.2886 10.2891 -1.1441 -0.3700 0.4043 0.0010
1.0000

10.2886 10.2888 10.2891 -0.3700 0.0171 0.4043 0.0005


10.0000 10.2500 10.5000 -432.6046 -61.0747 348.7934
0.5000

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

i=1; 6 1.3247180 0.000


fx(i)=x0;
Algoritmo Matlab Secante
syms x;
f1=subs(f,x,fx(i)); clear all;
z=diff(f); clc;
d=subs(z,x,fx(i)); fprintf('\nCalculo de la raiz de una ecuacion
por el metodo de la Secante\n\n');
ea(1)=100; f=input('Dame la funcion f(x) : ','s');
x0=input('Dame el valor del intervalo
inferior de x : ');
while abs(ea(i))>=tol; x1=input('Dame el valor del intervalo
fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); superior de x : ');
d=subs(z,x,fx(i+1)); e=input('Dame el porciento del error : ');
ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100); ea=1000;
i=i+1; c=1;
end while ea>e
fprintf('i fx(i) Error aprox (i) x=x0;
\n'); g=eval(f);
for j=1:i; x=x1;
fprintf('%2d \t %11.7f \t %7.3f \n',j- gg=eval(f);
1,fx(j),ea(j)); xi=x1-((gg*(x0-x1))/(g-gg));
end ea=abs((xi-x1)/xi)*100;
Ingrese el valor inicial: 2 x0=x1;
Ingrese el porcentaje de error: .00001 x1=xi;
Ingrese la función: x^3-x-1 c=c+1;
end
i fx(i) Error aprox (i) fprintf('\n\n\n\nLa raiz exacta es: %.6f',xi)
fprintf('\n\nNumero de iteraciones: %.7f\n',c);
0 2.0000000 100.000

1 1.5454545 29.412 Calculo de la raiz de una ecuacion por el metodo de la Secante

2 1.3596149 13.669 Dame la funcion f(x) : x^3-x-1

3 1.3258013 2.550 Dame el valor del intervalo inferior de x : 1

4 1.3247190 0.082 Dame el valor del intervalo superior de x : 2

5 1.3247180 0.000 Dame el porciento del error : .00001

9
ROBERTO TREVIÑO

La raiz exacta es: 1.324718 1


Ingrese el numero de iteraciones:
Numero de iteraciones: 8.0000000
9
Algoritmo Matlab Punto Fijo
it x0 x1 x0-x1
clc;
fprintf('Método del punto fijo:\n'); 1 1.0000000000 1.2599210499 0.2599210499
fx = input('Ingrese la función
original:\n','s'); 2 1.2599210499 1.3122938367 0.0523727868
fun=input('Ingrese la función
desp^3ejada:\n','s'); 3 1.3122938367 1.3223538191 0.0100599825
x0=input('Ingrese el punto inicial:\n');
n=input('Ingrese el numero de iteraciones:\n'); 4 1.3223538191 1.3242687446 0.0019149254
it=0;
fprintf(' it x0 x1 5 1.3242687446 1.3246326253 0.0003638807
x0-x1');
while(it<n) 6 1.3246326253 1.3247017485 0.0000691233
it = it+1;
x=x0; 7 1.3247017485 1.3247148784 0.0000131299
x1=eval(fun);
8 1.3247148784 1.3247173724 0.0000024940
fprintf('\n%3.0f%15.10f%15.10f%15.10f\n',it,x0,x
1,abs(x1-x0)); 9 1.3247173724 1.3247178462 0.0000004737
x0=x1;
end el punto fijo aproximado es= 1.324718
fprintf('\n el punto fijo aproximado
f(X) = (7 * X - 3) / (X - .45) ^ 2 evaluado de .39 a .53
es=%10.6f\n',x1);

Método del punto fijo:


Ingrese la función original:

x^3-x-1
Ingrese la función despejada:

(x+1)^(1/3)
Ingrese el punto inicial:

10
ROBERTO TREVIÑO

Calculated values of NLE variables


Variable Value f(x) Initial Guess
1 x 0.4285714 1.451E-11 0.45 ( 0.4 < x < 0.5 )

Calculated values of NLE variables Nonlinear equations


Variable Value f(x) Initial Guess 1 f(x) = (7 * x - 3) / (x - .45) ^ 2 = 0

1 X 0.4285714 2.068E-09 0.46 ( 0.39 < X < 0.53 )


General Settings
Total number of equations 1
Nonlinear equations Number of implicit equations 1
1 f(X) = (7 * X - 3) / (X - .45) ^ 2 = 0 Number of explicit equations 0
Elapsed time 0.0000 sec

General Settings Solution method SAFENEWT


Total number of equations 1 Max iterations 150
Number of implicit equations 1 Tolerance F 0.0000001
Number of explicit equations 0 Tolerance X 0.0000001
Elapsed time 0.0000 sec Tolerance min 0.0000001
Solution method SAFENEWT
Max iterations 150
f(x) = x ^ 3 - x – 1 evaluado de 1 a 2
Tolerance F 0.0000001
Tolerance X 0.0000001
Tolerance min 0.0000001

f(X) = (7 * X - 3) / (X - .45) ^ 2 evaluado de .4 a .5

11
ROBERTO TREVIÑO

Tolerance F 0.0000001
Tolerance X 0.0000001
Tolerance min 0.0000001

Sistema de eliminacion Gaussiana


1 1 0 3 4 1 1 0 3 4
2 1 -1 1 1 0 -1 -1 -5 -7
3 -1 -1 2 3 0 -4 -1 -7 -9
-1 2 3 -1 4 0 3 3 2 8

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

Calculated values of NLE variables


Variable Value f(x) Initial Guess
1 x 1.324718 2.551E-11 1.5 ( 1. < x < 2. )

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

function y=eliminacion(A,B) end

[n n]=size(A); x=A(:,n+1)./diag(A)

A=[A';B']'; Evaluación en la ventana de comando de Matlab

x=zeros(n,1); >> A=[1 1 0 3;2 1 -1 1;3 -1 -1 2;-1 2 3 -1]

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=

A= 1.0000 0 0 2.3333 3.3333

1 1 0 3 4 0 -1.0000 -1.0000 -5.0000 -7.0000

0 -1 -1 -5 -7 0 0 3.0000 13.0000 19.0000

0 -4 -1 -7 -9 0 0 0 -13.0000 -13.0000

14
ROBERTO TREVIÑO

A= 1 0 0 0 1

1.0000 0 0 2.3333 3.3333 0 -1 0 0 0

0 -1.0000 0 -0.6667 -0.6667 0 0 3 0 6

0 0 3.0000 13.0000 19.0000

0 0 0 -13.0000 -13.0000

A=

1.0000 0 0 2.3333 3.3333

0 -1.0000 0 -0.6667 -0.6667

0 0 3.0000 13.0000 19.0000

0 0 0 -13.0000 -13.0000

A=

1.0000 0 0 0 1.0000

0 -1.0000 0 -0.6667 -0.6667

0 0 3.0000 13.0000 19.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

1 -0.033333333 -0.06666667 2.61666667 1 -0.03333333 -0.066666667

0 7.003333333 -0.29333333 -19.5616667 0 1 -0.041884817


0 -0.19 10.02 70.615 0 -0.19 10.02

1 0 -0.06806283 2.5235602 1 0 -0.068062827


0 1 -0.04188482 -2.79319385 0 1 -0.041884817
0 0 10.0120419 70.0842932 0 0 0.999999998

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

1 - - 2.616 1 - - 2.6166 La solución es


0.033 0.066 66667 0.0333 0.06666 6667 X1= 3 X2=-2.5
33333 66667 3333 6667 X3=7
3
0 7.003 - - 0 1 - -
33333 0.293 19.56 0.04188 2.7931
3 33333 16667 4817 9385

16
ROBERTO TREVIÑO

0 -0.19 10.02 70.61 0 -0.19 10.02 70.615


5

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

A=input('Introduzca la matriz A: ');

B=input('Introduzca la matriz transpuesta de terminos independientes B: ');

[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

Evaluación en la ventana de comando de Matlab

Introduzca la matriz A: [1,2,4;4,1,-1;2,5,2]

Introduzca la matriz transpuesta de terminos independientes B: [11,6,3]

18
ROBERTO TREVIÑO

A=

4.0000 0 -0.0000 10.5085

0 4.5000 0 -7.2458

0 0 3.2778 9.5000

x=

2.6271 -1.6102 2.8983

Metodo de la Inversa
1 2 4 11
4 1 -1 6
2 5 2 3

0.11864407 0.271186441 -0.10169492


-0.16949153 -0.101694915 0.28813559
0.30508475 -0.016949153 -0.11864407

clc;

fprintf('Dame la matriz a la que quiere calcular la inversa: \n')

f=input('Dame el numero de filas: ');

19
ROBERTO TREVIÑO

c=input('Dame el numero de columnas: ');

for k=1:c

for j=1:f

fprintf('Fila: %x\n',j)

fprintf('Columna: %x',k);

r=input('Numero de esta fila y columna: ');

A(j,k)=r;

j=j+1;

end

k=k+1;

end

B=A;

pause

fprintf('Dame la matriz identidad del mismo grado que la matriz anterior\n\n')

for k=k:c*2

for j=1:f

fprintf('Fila: %x\n',j)

fprintf('Columna: %x',k)

r=input('Numero de esta fila y columna: ');

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

fprintf('Calculo la inversa para comprobar directo con Matlab\n')

c=inv(B);

Evaluación en la ventana de comando de Matlab

Dame la matriz a la que quiere calcular la inversa:

Dame el numero de filas: 3

Dame el numero de columnas: 3

Fila: 1

21
ROBERTO TREVIÑO

Columna: 1Numero de esta fila y columna: 1

Fila: 2

Columna: 1Numero de esta fila y columna: 2

Fila: 3

Columna: 1Numero de esta fila y columna: 4

Fila: 1

Columna: 2Numero de esta fila y columna: 4

Fila: 2

Columna: 2Numero de esta fila y columna: 1

Fila: 3

Columna: 2Numero de esta fila y columna: -1

Fila: 1

Columna: 3Numero de esta fila y columna: 2

Fila: 2

Columna: 3Numero de esta fila y columna: 5

Fila: 3

Columna: 3Numero de esta fila y columna: 2

A=

1 4 2

2 1 5

4 -1 2

Dame la matriz identidad del mismo grado que la matriz anterior

Fila: 1

Columna: 4Numero de esta fila y columna: 1

Fila: 2

Columna: 4Numero de esta fila y columna: 0

Fila: 3

Columna: 4Numero de esta fila y columna: 0

Fila: 1

22
ROBERTO TREVIÑO

Columna: 5Numero de esta fila y columna: 0

Fila: 2

Columna: 5Numero de esta fila y columna: 1

Fila: 3

Columna: 5Numero de esta fila y columna: 0

Fila: 1

Columna: 6Numero de esta fila y columna: 0

Fila: 2

Columna: 6Numero de esta fila y columna: 0

Fila: 3

Columna: 6Numero de esta fila y columna: 1

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

1.0000 4.0000 2.0000 1.0000 0 0

0 1.0000 -0.1429 0.2857 -0.1429 0

0 0 -8.4286 0.8571 -2.4286 1.0000

A=

1.0000 4.0000 2.0000 1.0000 0 0

0 1.0000 -0.1429 0.2857 -0.1429 0

0 0 -8.4286 0.8571 -2.4286 1.0000

A=

1.0000 4.0000 2.0000 1.0000 0 0

0 1.0000 -0.1429 0.2857 -0.1429 0

0 0 1.0000 -0.1017 0.2881 -0.1186

A=

1.0000 4.0000 2.0000 1.0000 0 0

0 1.0000 0 0.2712 -0.1017 -0.0169

0 0 1.0000 -0.1017 0.2881 -0.1186

A=

1.0000 4.0000 0 1.2034 -0.5763 0.2373

0 1.0000 0 0.2712 -0.1017 -0.0169

0 0 1.0000 -0.1017 0.2881 -0.1186

A=

1.0000 4.0000 0 1.2034 -0.5763 0.2373

0 1.0000 0 0.2712 -0.1017 -0.0169

0 0 1.0000 -0.1017 0.2881 -0.1186

A=

1.0000 0 0 0.1186 -0.1695 0.3051

0 1.0000 0 0.2712 -0.1017 -0.0169

0 0 1.0000 -0.1017 0.2881 -0.1186

A=

1.0000 0 0 0.1186 -0.1695 0.3051

24
ROBERTO TREVIÑO

0 1.0000 0 0.2712 -0.1017 -0.0169

0 0 1.0000 -0.1017 0.2881 -0.1186

Calculo la inversa para comprobar directo con Matlab

c=

0.1186 -0.1695 0.3051

0.2712 -0.1017 -0.0169

-0.1017 0.2881 -0.1186

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

Metodo de gauss saidel


- -
3 0.1 0.2 7.85
- -
0.1 7 0.3 19.3
-
0.3 0.2 10 71.4 I x(1)
0 0

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

A=input('Ingrese la matriz de coeficientes A: ');

B=input('Ingrese la matriz transpuesta de terminos independientes B: ');

x=input('Ingrese un vector de aproximacion x: ');

m=input('Ingrese el numero de iteraciones m: ');

E=input('Ingrese la precision buscada E: ');

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('La respuesta final es: ');

disp(x)

Evaluación en la ventana de comando de Matlab

Ingrese la matriz de coeficientes A: [3,-0.1,-0.2;0.1,7,-0.3;0.3,-0.2,10]

Ingrese la matriz transpuesta de terminos independientes B: [7.85,-19.3,71.4]

Ingrese un vector de aproximacion x: [0,0,0]

Ingrese el numero de iteraciones m: 50

Ingrese la precision buscada E: 0.0001

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

La respuesta final es:

3.0000 -2.5000 7.0000

27
ROBERTO TREVIÑO

Jacobi

10 1 2 3

4 6 -1 9

-2 3 8 51

x(0) x(1) X(2) X(39 x(4) x(5) x(6)

iteracion iteracion1 iteracion2 iteracion3 iteracion4 iteracion5


iteracion6 iteracion7

x1 0 0.3 1.425 1.4975 2.01875 1.773930556 #¡DIV/0! #¡DIV/0!

x2 0 1.5 1.3 -3.3 0.334444444 #¡DIV/0! #¡DIV/0! #¡DIV/0!

x3 0 6.375 6.6375 6.94375 7.536875 7.212881944 #¡DIV/0!


#¡DIV/0!

Error 6.555961028 1.172404047 4.610753226 3.719231809 #¡DIV/0!


#¡DIV/0! #¡DIV/0!

clc;

%Metodo de Jacobi

A=input('Ingrese la matriz de coeficientes A: ');

28
ROBERTO TREVIÑO

B=input('Ingrese la matriz transpuesta de tèrminos independientes B: ');

x=input('Ingrese un vector de aproximacion x: ');

m=input('Ingrese el numero de iteraciones m: ');

E=input('Ingrese la presicion buscada E: ');

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('La respuesta final es ');

disp(x);

Evaluación en la ventana de comando de Matlab

Para verificar el funcionamiento del programa se presentan dos ejemplos vistos en clase:

Ingrese la matriz de coeficientes A: [3,-0.1,-0.2;0.1,7,-0.3;0.3,-0.2,10]

Ingrese la matriz transpuesta de tèrminos independientes B: [7.85,-19.3,71.4]

Ingrese un vector de aproximacion x: [0,0,0]

Ingrese el numero de iteraciones m: 50

Ingrese la presicion buscada E: 0.0001

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

3.0000 -2.5000 7.0000

Otro ejemplo hecho en clase:

Ingrese la matriz de coeficientes A:


[98,9,2,1,0.5;11,118,9,4,0.88;27,27,85,8,2;1,3,17,142,25;2,4,7,17,188]

Ingrese la matriz transpuesta de tèrminos independientes B: [0.11,0.2235,0.28,0.3,0.14]

Ingrese un vector de aproximacion x: [0,0,0,0,0]

Ingrese el numero de iteraciones m: 100

Ingrese la presicion buscada E: 0.0001

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

0.0009 0.0016 0.0023 0.0017 0.0005

Metodo de Newton Rapshon

u(x,y)=x2- ¶u/¶ 2x-10 ¶u/¶y 2y


10x+y2+8=0 x= =
v(x,y)=xy2+x- ¶v/¶x y2+1 ¶v/¶y 2xy-
10y+8=0 = = 10

iter xi yi ui vi ¶u/¶x ¶u/¶y ¶v/¶ ¶v/¶ Jacob


ació x y iano
n

31
ROBERTO TREVIÑO

0 0 0 8 8 -10 0 1 -10 100


1 0.8 0.88 1.414 0.495616 -8.4 1.76 1.774 - 69.04
4 4 8.592 9856
2 0.98862 0.97663866 0.044 0.154497 - 1.953 1.953 - 60.91
905 9199 09 8.0227 27732 8230 8.068 8610
5 4189 6 8 9332 8
9
3 0.99953 0.99842603 0.000 0.011195 - 1.996 1.996 - 60.05
265 5935 37 8.0009 85205 8545 8.004 2707
8 3471 2 3 0811 9
8
4 0.99998 0.99993734 2.487 0.000453 - 1.999 1.999 - 60.00
403 8E-06 34 8.0000 87468 8746 8.000 2014
3195 6 9 1572 9
6
5 0.99999 0.99999787 3.901 1.5445E- - 1.999 1.999 - 60.00
947 9E-09 05 8.0000 99573 9957 8.000 0068
0107 9 4 0053 2
3
6 0.99999 0.99999993 4.508 5.1535E- - 1.999 1.999 - 60.00
998 4E-12 07 8.0000 99985 9998 8.000 0002
0004 8 6 0001 3
8
7 1 1 0 1.7179E- -8 1.999 2 - 60.00
08 99999 8.000 0000
5 0000 1
1
8 1 1 0 5.7263E- -8 2 2 -8 60
10
9 1 1 0 1.9087E- -8 2 2 -8 60
11
Metodo
Punto
Fijo
f1(x,y)=x x=g(x,y)=(x^ dg1/dx=2 df1/dy
^2- 2+y^2+8)/1 x/10 =2y/10
10x+y^2 0
+8=0
f2(x,y)=x y=g(x,y)=(xy df2/dx=( df2/dy
y^2+x- ^2+x+8)/10 y^2+1)/1 =2xy/1
10y+8=0 0 0

Iteracion Iteracion1 Iterac Iteracion Iteraci Iteraci Iterac Iterac Iterac


0 ion2 3 on4 on5 ion6 ion7 ion8
x 0 0.8 1.005 0.906279 0.8831 0.878 0.877 0.876 0.876
44 879 17699 04555 0993 9304 9007
3

32
ROBERTO TREVIÑO

y 0 0.88 0.978 0.977384 0.9726 0.970 0.970 0.970 0.970


4052 065 74203 87602 3853 2689 2434
7 3 9 2
Erro 1.1892855 0.227 0.099165 0.0236 0.005 0.001 0.000 3.921
r 7919 38 36187 38146 0659 2050 2E-05
9 2 6

%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

f1=x^3+ x=g1=(z^3 dg1/dx=0 dg1/dy=(- dg1/dz=(3z^2)/(3*((z^3+129


y^3-z^3- +129- 3y^2)/(3*((z^3+ -y^3)^2)^1/3)
129=0 y^3)^(1/3 129-
) y^3)^2)^1/3)
f2=x^2+ y=g2=(z^2
y^2-z^2- +9.75-
9.75=0 x^2)^(1/2
)
f3=x+y- z=g3=x+y- dg2/dx=(- dg2/dy=0 dg2/dz=(2z)/(2*(z^2+
z-9.49=0 9.49 2x)/(2*(z^2+9. 9.75-x^2)^1/2)
75-x^2)^1/2)

dg3/dx=1 dg3/dy=1 dg3/dz=0


ITERACI ITERACIO ITERACION 2 ITERACION 3 ITERACION 4 ITER
ON 0 N1 ACI
ON
5

34
ROBERTO TREVIÑO

x 1 43 27289420.64 3.78365E+36 0 #¡N


UM
!
y 1 -919.125 -3.72356E+14 -7.15802E+72 2.5619E+145 #¡N
UM
!
z 1 -885.615 -3.72356E+14 -7.15802E+72 2.5619E+145 #¡N
UM
!
erro 1278.467 5.26591E+14 1.0123E+73 3.623E+145 #¡N
r 901 UM
!

%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

Resitencia electrica a diferentes


temperaturas
b)Temperatura
a) Determine el valor de R a con R 113.45
28°C

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)

El siguiente ejercicio fue hecho en clase


Una resistencia eléctrica (R) se sometió a diferentes temperaturas y se observa los siguientes
medidas de su resistencia:

T(°C) R
10 98
15 99.5
20 103
25 107
30 112
35 116
40 122

a) Determine el valor probable de una resistencia a una:


T= 17°C, 28°C, 32°C
Temp=[10,15,20,25,30,35,40]';
R=[98,99.5,103,107,112,116,122]';
Ti=[17,28,32]';
Propdad=interp1(Temp,R,Ti,'linear');
[Ti,Propdad]

Evaluación en la ventana de comando de Matlab


>> Temp=[10,15,20,25,30,35,40]';
R=[98,99.5,103,107,112,116,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

Resitencia electrica a diferentes temperaturas


a) Determine el valor de R a
28°C b)Temperatura con R 113.45
T(°C) R(Ω) 28 113.45
10 98 #2
15 99.5 a) b)
20 103 110 31.8125
25 107 #3
30 112 a)
35 116 110.12 31.7097917
40 122 #4
a) b)
110.008 31.8202031
110 31.8125 #5
a) b)
110.12 31.7246547
#6
a) b)
110.03936

Aclaración: Se utilizaron las variables “R” y “T” en la codificación para representar a la


Temperatura y a la Resistencia eléctrica en el ejemplo que hicimos en clase.

38
ROBERTO TREVIÑO

function [Ri] = lagrange(Ts,Rs,T)


n=length(Ts);
if length(Rs)~=n, error('T y R deben ser la misma longitud'); end
Ri=0;
for i=1:n
producto=Rs(i);
for j=1:n
if i~=j
producto=producto*(T-Ts(j))/(Ts(i)-Ts(j));
end
end
Ri=Ri+producto;
end

Evaluación en la ventana de comando de Matlab

>> T=[10 15 20 25 30 35 40];


>> R=[98 99.5 103 107 112 116 122];
>> lagrange(T,R,28)

ans =

109.9834

39
ROBERTO TREVIÑO

Ajuste de curvas por mínimos cuadrados

Método de mínimos cuadrados

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

3 19.08 20.8 396.864 364.0464 23.3131219 2.51312188 12.0823167


4 16.32 24.54 400.4928 266.3424 28.4982313 3.95823129 16.1297118
5 12.04 28.83 347.1132 144.9616 36.5389082 7.70890819 26.739189
6 12.12 32.71 396.4452 146.8944 36.3886152 3.67861516 11.2461485
7 10.51 39.71 417.3521 110.4601 39.4132623 0.29673769 0.74726186
8 9.15 45.49 416.2335 83.7225 41.9682438 3.52175624 7.7418251
9 8 52.52 420.16 64 44.128706 8.39129399 15.9773305
Sumatoria 136.05 276.83 3575.8538 2380.7323

βi βo ȳ ӿ

-1.87866283 59.1580086 30.7588889 15.1166667

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

β0=y media-β1(x media)


β0= 87.8571429

Yc=β0+β1Xi

% Diferencia= |Yi-Yc|/Yi *100

% Dif media= Σ%Dif/n


%Dif media= 0.95865327

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

Evaluación en la ventana de comando de Matlab


>> clear all
>> lsline([10 15 20 25 30 35 40],[98 99.5 103 107 112 116 122])

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

n X1 X2 Xm /XI-Xm/ f(V1) f(Vm) f(Vi)*f(Vm)


1 0.5 1 0.75 0.25 -1.7171875 2.6847168 (-)
2 0.5 0.75 0.625 0.125 -1.7171875 0.83518219 (-)
3 0.5 0.625 0.5625 0.0625 -1.7171875 -0.33418784 (+)
4 0.5625 0.625 0.59375 0.03125 -0.33418784 0.27473026 (-)
5 0.5625 0.59375 0.578125 0.015625 -0.33418784 -0.02336807 (+)
6 0.578125 0.59375 0.5859375 0.0078125 -0.02336807 0.12723307 (-)
7 0.578125 0.5859375 0.58203125 0.00390625 -0.02336807 0.05232524 (-)
8 0.578125 0.58203125 0.58007813 0.00195313 -0.02336807 0.01457737 (-)
9 0.578125 0.58007813 0.57910156 0.00097656 -0.02336807 -0.00437058 (+)
10 0.57910156 0.58007813 0.57958984 0.00048828 -0.00437058 0.00510957 (-)
11 0.57910156 0.57958984 0.5793457 0.00024414 -0.00437058 0.00037104 (-)
12 0.57910156 0.5793457 0.57922363 0.00012207 -0.00437058 -0.00199938 (+)
13 0.57922363 0.5793457 0.57928467 6.1035E-05 -0.00199938 -0.00081407 (+)
14 0.57928467 0.5793457 0.57931519 3.0518E-05 -0.00081407 -0.00022149 (+)

resultado es .579345

45
ROBERTO TREVIÑO

function raiz = biseccion(def,e)


f=inline(def);
x=linspace(-50,50,1000);
f(x);
y=f(x);
plot(x,y)
grid on
%basado en la grafica podemos introducir
%los limites inferiores y superiores
%que son los que se aproximan a cero
a=input ('Valor inicial inferior: ');
b=input ('Valor inicial superior: ');
r=f(a)*f(b);
if r<0
x=a;
while abs(f(x))>e
x=(a+b)/2;
if f(a)*f(x)<0
b=x;
else
a=x;
end
end
raiz=x;
else
raiz='No hay cmbio de signo';
end
end

>> biseccion('0.65*x.^5-9*x.^4+45.4*x.^3-88*x.^2+82.3*x-26',0.001)

Valor inicial inferior: 0.5

Valor inicial superior: 1

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)

eliminacion([4 1 -1;5 1 2;6 1 1],[-2;4;6])


A=
Columns 1 through 3

4.0000 1.0000 -1.0000

0 -0.2500 3.2500

6.0000 1.0000 1.0000

Column 4

-2.0000

6.5000

6.0000
A=
Columns 1 through 3

4.0000 1.0000 -1.0000

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

Metodo de Newton Raphson

2 2
f(x)=sen(x) + cos(1+xdy/dx=cos(x)-2xsen(1+x
) -1 ) x=radianes
x=2 127.32395

iteración x0 f(x0) f´(x0) ERROR


1 2.5 0.16639632 -4.91654801
2 2.53384414 -0.00882495 -5.41962265 0.00162833
3 2.5322158 -1.7544E-05 -5.39802724 3.2501E-06
4 2.53221255 -7.05E-11 -5.39798386 1.3061E-11
5 2.53221255 0 -5.39798386 2.53221255

el resultado es 2.5322158

53
ROBERTO TREVIÑO

function raiz= newtonraphson(def,v1,c,E)


syms x
f=sym(def);
df=diff(f);
fx=inline(char(f));
dfx=inline(char(df));
k=1;
while abs(fx(v1))>E
v1=v1-fx(v1)/dfx(v1);
k=k+1;
end
if k>c
raiz='No converge';

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

2)Velocidad de caida de un paracaidísta v=gm/c (1-e^-(c/m)t)


f(m)=490/9.8(1-e^-(98/m))
Método del punto fijo
i Mo f(Mo) Error |Mo-f(Mo)|
1 63 63.37794071 0.377940707
2 63.3779407 63.53636268 0.158421971
3 63.5363627 63.60287684 0.066514164
4 63.6028768 63.630822 0.027945162
5 63.630822 63.64256616 0.011744161
6 63.6425662 63.64750232 0.004936157
7 63.6475023 63.64957713 0.002074806
8 63.6495771 63.65044925 0.000872118
Solución m=63.6495771 con E=0.0008

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

Regresion por minimos cuadrados


n Dureza Cont cobre TemperaturaX1^2 X1X2 X2^2 YiXi YiX2 Calculado %D
1 78.9 0.02 1000 0.0004 20 1000000 1.578 78900 76.7625 2.709125
2 65.1 0.02 1100 0.0004 22 1210000 1.302 71610 68.4791667 5.190732
3 55.2 0.02 1200 0.0004 24 1440000 1.104 66240 60.1958333 9.050422
4 56.4 0.02 1300 0.0004 26 1690000 1.128 73320 51.9125 7.956560
5 80.9 0.1 1000 0.01 100 1000000 8.09 80900 79.4 1.854140
6 69.7 0.1 1100 0.01 110 1210000 6.97 76670 71.1166667 2.032520
7 65.4 0.1 1200 0.01 120 1440000 6.54 78480 62.8333333 3.924566
8 55.4 0.1 1300 0.01 130 1690000 5.54 72020 54.55 1.534296
9 85.3 0.18 1000 0.0324 180 1000000 15.354 85300 82.0375 3.824736
10 71.8 0.18 1100 0.0324 198 1210000 12.924 78980 73.7541667 2.721680
11 60.7 0.18 1200 0.0324 216 1440000 10.926 72840 65.4708333 7.859692
12 58.9 0.18 1300 0.0324 234 1690000 10.602 76570 57.1875 2.907470
SUMA 803.7 1.2 13800 0.1712 1380 16020000 82.058 911830 803.7 51.56594

12 1.2 13800 803.7 1 0.1 1150 66.975


1.2 0.1712 1380 82.058 1.2 0.1712 1380 82.058
13800 1380 16020000 911830 13800 1380 16020000 911830

1 0.1 1150 66.975 1 0.1 1150 66.975


0 0.0512 0 1.688 0 1 0 32.96875
0 0 150000 -12425 0 0 150000 -12425

1 0.1 1150 66.975 1 0 1150 63.678125


0 1 0 32.96875 0 1 0 32.96875
0 0 1 -0.08283333 0 0 1 -0.08283333

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

Xi Yi X1^2 X1^2 X2^2 X1*X2 Yi*X2 Yi*X1 Calculado %D


1 9 2 4 4 16 8 36 18 3.7161654 0.587092
2 6 3 9 9 81 27 54 18 4.28418819 0.285968
3 5 4 16 16 256 64 80 20 4.98776698 0.00244
4 10 7 49 49 2401 343 490 70 7.9118393 0.208816
5 9 8 64 64 4096 512 576 72 9.15764207 0.017515
6 11 9 81 81 6561 729 891 99 10.5390008 0.041909
7 2 5 25 25 625 125 50 10 5.82690176 1.913450
8 3 5 25 25 625 125 75 15 5.82690176 0.942300
Suma 55 43 273 273 14661 1933 2252 322 52.2504063 3.999500

8 55 273 55 1 6.875 34.125 6.875


43 273 1933 322 0 -22.625 465.625 26.375
273 1933 14661 2252 0 56.125 5344.875 375.125

1 0 175.61326 14.8895028 1 0 0 2.9867878


0 1 -20.5801105 -1.16574586 0 1 0 0.22913281
0 0 6499.9337 440.552486 0 0 1 0.067778
B0 2.9867878
B1 0.22913281
B2 0.067778

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

8 55 457 43 1 6.875 57.125


5.375
55 457 4165 322 55 457 4165322 B0
457 4165 39781 2872 457 4165 39781
2872 8.915998
B1
1 6.875 57.125 5.375 1 6.875 57.125 5.375 -2.028896
0 78.875 1023.125 26.375 0 1 12.9714739 0.33438986 B3
0 1023.125 13674.875 415.625 0 1023.125 13674.875 415.625 0.182191

1 0 -32.0538827 3.07606973 1 0 0 8.91599887


0 1 12.9714739 0.33438986 0 1 0 -2.02889601
0 0 403.435816 73.5023772 0 0 1 0.18219101

58
ROBERTO TREVIÑO

59
ROBERTO TREVIÑO

60
ROBERTO TREVIÑO

Encontrar una ecuación que relaciona la transferencia de calor de líquidos…

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

x1x2 x1x3 x2x3 x1y x2y x3y Nc calc %D


5.066985581 -0.283819861 -0.088937192 7.997268267 2.506007098 -0.140370359 1.989014 97.5021 0.00053
5.044792605 -0.187216365 -0.056418808 8.344244706 2.514589676 -0.093318472 2.039558 109.5364 0.00033
5.124751494 -0.074149055 -0.021723223 8.839989883 2.589824911 -0.037471684 2.112975 129.7104 0.0014
5.04968928 0.090318351 0.025102781 9.247630098 2.570255447 0.04597139 2.16935 147.6897 0.00047
4.681154126 0.144499321 0.036190753 9.450363599 2.366902325 0.073062277 2.186051 153.4798 0.00025
4.422320416 0.267270324 0.060960138 9.808904138 2.23725607 0.135212309 2.228063 169.0686 0.00099
4.186270617 0.320288844 0.06753453 10.02351865 2.113509827 0.161703263 2.250045 177.8465 0.00110
3.654488037 0.388234448 0.07020306 10.08546123 1.823718225 0.193742661 2.242874 174.9338 0.00129
37.23045216 0.665426007 0.09291204 73.79738056 18.72206358 0.338531384 17.21793 1159.767 0.00645

Gauss-Jordan

61
ROBERTO TREVIÑO

8 34.23539 8.742608 0.139485 17.21793038


34.23539 146.7145 37.23045 0.665426 73.79738056
8.742608 37.23045 9.737546 0.092912 18.72206358
0.139485 0.665426 0.092912 0.025265 0.338531384
1 4.279424115 1.092825946 0.017435675 2.152241298
0 0.206768802 -0.182873483 0.068508818 0.114554065
0 -0.182873483 0.183397687 -0.059521226 -0.094137473
0 0.068508818 -0.059521226 0.022833128 0.038325144

1 4.279424115 1.092825946 0.017435675 2.152241298


0 1 -0.884434601 0.331330534 0.554020062
0 -0.182873483 0.183397687 -0.059521226 -0.094137473
0 0.068508818 -0.059521226 0.022833128 0.038325144
1 0 4.877697 -1.40047 -0.218645517
0 1 -0.88443 0.331331 0.554020062
0 0 0.021658 0.00107 0.007178105
0 0 0.00107 0.000134 0.000369884

1 0 4.877696704 -1.4004682 -0.218645517


0 1 -0.884434601 0.331330534 0.554020062
0 0 1 0.049420102 0.33142897
0 0 0.001070343 0.000134065 0.000369884
1 0 0 -1.641524467 -1.835255512
0 1 0 0.375039381 0.847147311
0 0 1 0.049420102 0.33142897
0 0 0 8.11685E-05 1.51415E-05

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

Los valores representan s en gramos de K2Cr2O2 disueltos en 100 partes de agua…

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

4 260.2 16976.44 79.5 1 65.05 4244.11 19.875


260.2 16976.44 1110954.61 5397.25 0 50.43 6637.188 225.775
16976.44 1110955 72923657.29 367068 0 6637.188 873778.5 29661.25

1 65.05 4244.11 19.875 1 0 -4317.24 -271.354


0 1 131.6118977 4.476998 0 1 131.6119 4.476998
0 6637.188 873778.5264 29661.25 0 0 245.6185 -53.4262

1 0 -4317.24394 -271.354 1 0 0 -1210.43


0 1 131.6118977 4.476998 0 1 0 33.10483
0 0 1 -0.21752 0 0 1 -0.21752

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

7 2.8 1.4 2.366 1 0.4 0.2 0.338


2.8 1.4 0.784 1.1407 0 0.28 0.224 0.1943
1.4 0.784 0.4676 0.62177 0 0.224 0.1876 0.14857

1 0 -0.12 0.06042857 1 0 0 -0.03771429 ṭ


0 1 0.8 0.69392857 0 1 0 1.34821429 2.26563969
0 0 0.0084 -0.00687 0 0 1 -0.81785714

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

7 1.1555363 0.79993549 2393 1 0.16507661 0.1142765 341.857143


1.1555363 0.79993549 0.65501719 454.805493 0 0.60918347 0.52296654 59.7771549
0.79993549 0.65501719 0.55766679 318.815671 0 0.52296654 0.46625296 45.3520109

1 0 -0.02743704 325.658722 1 0 0 316.199193


0 1 0.85847134 98.1266862 0 1 0 394.103717
0 0 0.01730117 -5.96496314 0 0 1 -344.772177

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

6 13.95 35.2763 66 1 2.325 5.87938333 11


13.95 35.2763 93.826815 181.8 0 2.84255 11.8094175 28.35
35.2763 93.826815 257.352189 513.1524 0 11.8094175 49.9492982 125.1131

1 0 -3.77986477 -12.1882465 1 0 0 19.0626719


0 1 4.15451531 9.97343934 0 1 0 -24.3749903
0 0 0.8868924 7.33259091 0 0 1 8.26773452

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

7 4.2 4.24 11.2935 1 0.6 0.60571429 1.61335714


4.2 4.24 5.04 8.90653 0 1.72 2.496 2.13043
4.24 5.04 6.5428 10.116727 0 2.496 3.97457143 3.27609271

1 0.6 0.60571429 1.61335714 1 0 -0.26498339 0.87018389


0 1 1.45116279 1.23862209 0 1 1.45116279 1.23862209
0 2.496 3.97457143 3.27609271 0 0 0.3524691 0.18449197

1 0 -0.26498339 0.87018389 1 0 0 1.00888344


0 1 1.45116279 1.23862209 0 1 0 0.47904379
0 0 1 0.52342735 0 0 1 0.52342735

64
ROBERTO TREVIÑO

5.3 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.82733698
2 22.4 17.53 1.35024802 1.24378192 1.67941407 1.82316971 1.23872038 17.3268806 1.15869602
3 19.08 20.8 1.28057837 1.31806333 1.6878834 1.63988096 1.31145604 20.4859469 1.50987063
4 16.32 24.54 1.21272015 1.38987456 1.68552889 1.47069017 1.38230055 24.1157378 1.72885964
5 12.04 28.83 1.08062649 1.45984464 1.57754679 1.1677536 1.52020738 33.1289279 14.9113005
6 12.12 32.71 1.08350262 1.51468054 1.64116034 1.17397793 1.51720468 32.900665 0.58289527
7 10.51 39.25 1.02160272 1.59383966 1.62827093 1.04367211 1.58182866 38.1793617 2.72774092
8 9.15 45.49 0.96142109 1.65791594 1.59395535 0.92433052 1.64465875 44.1223616 3.00645934
9 8 52.52 0.90308999 1.72032472 1.55360803 0.81557152 1.70555688 50.7641226 3.34325469
Sumatoria 136.05 276.37 10.3158866 13.0656426 14.7074065 12.0814069 13.0656426 275.602386 29.796414

β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=

2.6878 2.8639 3.0350


z=
8.8014 8.9041 8.9490
w=
10.7223 9.6663 8.6945

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

8.8014 8.9041 8.9490 8.9422 8.8806 8.7764 8.6329


Column 8
8.4510
w=
Columns 1 through 7
10.7223 9.6663 8.6945 7.7974 6.9797 6.2243 5.5334
Column 8
4.9007
Valor de X: log(8)
x=
Columns 1 through 7
3.2745 3.1091 2.9486 2.7924 2.6419 2.4949 2.3523
Columns 8 through 9
2.2138 2.0794
Valor de Y: log(52.52)
y=
Columns 1 through 7
2.6878 2.8639 3.0350 3.2023 3.3614 3.5178 3.6700
Columns 8 through 9
3.8175 3.9612
z=
Columns 1 through 7
8.8014 8.9041 8.9490 8.9422 8.8806 8.7764 8.6329
Columns 8 through 9
8.4510 8.2371
w=
Columns 1 through 7
10.7223 9.6663 8.6945 7.7974 6.9797 6.2243 5.5334
Columns 8 through 9
4.9007 4.3241
y=
3.3463
mx =
2.6563
B1 =
-1.0651
B0 =
6.1756
f=
-21.5389
d=

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

f(x)=.2+25x-200x^2+675x^3-900x^4+400x^5 a=0 b=.8


trapezoidal n=1 n=2 n=8
N=1 A %D
0.1728 89.466626
N=2 h 0.4
A x f(x)

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

simpson n=2 n=3


n=2 h 0.4
A %D x f(x)
1.367466 16.64329
67 98 0 0.2
0.4 2.456
0.8 0.232
0.266666
n=3 h 67 x f(x)
A %D 0 0.2
1.519170 7.395893 0.266666 1.432724
37 3 67 28
0.533333 3.487176
33 95
0.8 0.232
function
y=trapeciocom(f,a,b,n)
f0=subs(f,a);
fn=subs(f,b);
h=(b-a)/n;
fs=0;
for i=1:n-1
x(i)=a+h*i;
fs=fs+subs(f,x(i));
end
fs
integral=0.5*h*(f0+2*fs+f
n)

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

Método de Simpson 1/3

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

Método de Simpson 3/8

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 RUNGE-KUTTA 2`ORDEN


t a K0 yi+hk0 K1 Runge
0 3 -0.02044595 2.38662143 -0.01823637 2.41976511
30 2.41976511 -0.01836256 1.86888819 -0.01613758 1.90226297
60 1.90226297 -0.01628103 1.41383194 -0.01403607 1.44750637
90 1.44750637 -0.01420224 1.02143906 -0.01193034 1.05551756
120 1.05551756 -0.01212773 0.69168572 -0.0098175 0.72633907
150 0.72633907 -0.01006043 0.42452626 -0.00769129 0.46006337
180 0.46006337 -0.00800674 0.21986127 -0.00553504 0.25693666

METODO DE RUNGE-KUTTA 4`ORDEN


t a K1 K2 K3 K4 RUNGE yi+hk1/2 yi+hk2/2 yi+hk3
0 3 -0.02044595 -0.00437361 -0.00456517 -0.00450932 2.78583583 2.69331072 2.93439579 2.86304502
30 2.78583583 -0.01970264 -0.00420555 -0.00439745 -0.00434151 2.57958505 2.49029619 2.72275259 2.65391221
60 2.57958505 -0.01895927 -0.00403745 -0.00422974 -0.00417368 2.38124845 2.29519598 2.51902331 2.45269296
90 2.38124845 -0.01821583 -0.00386931 -0.00406201 -0.00400583 2.19082688 2.10801094 2.32320879 2.25938805
120 2.19082688 -0.01747233 -0.00370113 -0.00389428 -0.00383797 2.00832126 1.92874198 2.13530994 2.07399835
150 2.00832126 -0.01672874 -0.0035329 -0.00372655 -0.00367009 1.83373261 1.75739012 1.95532777 1.89652475
180 1.83373261 -0.01598508 -0.00336462 -0.00355881 -0.00350219 1.66706202 1.59395646 1.78326338 1.72696827

METODO DE HEUM CON UN CORRECTOR SIMPLE


t a k1 k2 yi+hk1 Heum
0 3 -0.02044595 -0.01823637 2.38662143 2.41976511
30 2.41976511 -0.01836256 -0.01613758 1.86888819 1.90226297
60 1.90226297 -0.01628103 -0.01403607 1.41383194 1.44750637
90 1.44750637 -0.01420224 -0.01193034 1.02143906 1.05551756
120 1.05551756 -0.01212773 -0.0098175 0.69168572 0.72633907
150 0.72633907 -0.01006043 -0.00769129 0.42452626 0.46006337
180 0.46006337 -0.00800674 -0.00553504 0.21986127 0.25693666

METODO MEJORADO DEL POLIGONO


t a K1 K2 0.5*h*k1 yi+0.5hk1 POLIGONO
0 3 -0.02044595 0.01937269 -0.30668928 2.69331072 3.58118072
30 3.58118072 -0.0223388 0.02126805 -0.335082 3.24609873 4.21922208
60 4.21922208 -0.02424727 0.02317863 -0.3637091 3.85551298 4.91458104
90 4.91458104 -0.02616917 0.02510233 -0.39253757 4.52204347 5.66765102
120 5.66765102 -0.02810271 0.02703743 -0.42154071 5.24611031 6.47877395
150 6.47877395 -0.03004645 0.02898252 -0.45069671 6.02807724 7.3482495
180 7.3482495 -0.03199917 0.03093643 -0.47998749 6.86826201 8.27634229

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

Calculated values of NLE variables


Variable Value f(x) Initial Guess
1 y 0.102644 0.0616789 1.2
2 x 0.5834336 0.4043172 1.2

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

Calculated values of NLE variables


Variable Value f(x) Initial Guess
1 z 0.8884766 0.5966802 1.
2 y 1.407415 0.2281202 1.
3 x -0.2945764 -0.3401726 1.

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

Number of implicit equations 3


Number of explicit equations 0
Elapsed time 1.1574 sec
Solution method SAFENEWT
Max iterations 150
Tolerance F 0.0000001
Tolerance X 0.0000001
Tolerance min 0.0000001

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

3 5.875 2.5 -0.25 4 3 4.375


3.5 7.125 -0.25 -7.5 4.71825 3.5 4.9375
4 7 -7.5 -20.75 3 4 3
S 46.5 25.8745 S 28.5
V

METODO DE RUNGE-KCIRA DE 2DO ORDEN


X Y K0
0 1 8.5
0.5 2.4375 1.25
1 0.4375 -1.5
1.5 0.3125 -1.25
2 1.3125 0.5
2.5 2.6875 2.25
3 3.6875 2.5
3.5 3.5625 -0.25
4 1.5625 -7.5
S 17

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

Evaluación en la ventana de comando de Matlab


>> f=inline('y-t^2+1')

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

0.5000 0.8000 1.1520 1.5504 1.9885 2.4582 2.9498

Columns 8 through 11

3.4518 3.9501 4.4282 4.8658

ans =

Columns 1 through 7

0 0.2000 0.4000 0.6000 0.8000 1.0000 1.2000

Columns 8 through 11

1.4000 1.6000 1.8000 2.0000

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

Evaluación en la ventana de comando de Matlab

>> clear all


>> f=inline('y-t^2+1')

f=

Inline function:
f(t,y) = y-t^2+1

>> Heun(f,0,2,0.5,10)

w=

Columns 1 through 7

0.5000 0.8260 1.2069 1.6372 2.1102 2.6177 3.1496

Columns 8 through 11

3.6937 4.2351 4.7556 5.2331

ans =

87
ROBERTO TREVIÑO

Columns 1 through 7

0 0.2000 0.4000 0.6000 0.8000 1.0000 1.2000

Columns 8 through 11

1.4000 1.6000 1.8000 2.0000

Método de Runge-Kutta de orden 4

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

Evaluación en la ventana de comando de Matlab

>> clear all


>> f=inline('t^2-y')

f=

Inline function:
f(t,y) = t^2-y

>> rk4(f,0,0.4,1,4)

w=

1.0000 0.9052 0.8213 0.7492 0.6897

ans =

0 0.1000 0.2000 0.3000 0.4000

89
ROBERTO TREVIÑO

División Sintética

Ejercicio: Sea el polinomio A(x) = x3 + 2x2 + 3x +4 y B(x) = x-5, determine el


cociente y el residuo.
clc;
%Division sintetica
x=input('Ingrese los coeficientes del polinomio (A(x)) de n
grado en forma de vector:\n');

90
ROBERTO TREVIÑO

y=input('Ingrese el polinomio (B(x)) de primer grado en forma


de vecotr: \n');
N=length(x);
L=zeros(1,N);
L(1,:)=x(1);
d=-y(2)/y(1);
for k=2:N
Z=(d*L(1,k-1)+x(1,k));
L(:,k)=Z;
end
RESIDUO=L(1,N)
L(:,N)=[ ];
COCIENTE=L

Evaluación en la ventana de comandos de Matlab


Ingrese los coeficientes del polinomio (A(x)) de n grado en forma de vector:
[1 2 3 4]
Ingrese el polinomio (B(x)) de primer grado en forma de vecotr:
[1 -5]
RESIDUO =
194
COCIENTE =
1 7 38

91

Potrebbero piacerti anche