Documente Academic
Documente Profesional
Documente Cultură
MATLAB
JOSE ARAPA QUISPE
SOLUCION:
fplot('[-26+82.3*x-88*x.^2+45.4*x.^3-9*x.^4+0.65*x.^5]',[-1,1]),grid
function z=funcionk(x)
z=-26+82.3*x-88*x^2+45.4*x^3-9*x^4+0.65*x^5;
clear;clc;
disp('CALCULO DE LA RAIZ DE UNA ECUACION NO LINEAL')
disp('POR EL METODO CERRADO DE BISECCION')
n=input('Ingrese precision de cifras significativas n=');
x1=input('Ingrese limite inferior x1=');
xu=input('Ingrese limite superior xu=');
Es=(0.5*10^(2-n));
Ea=100;
xr=0;
i=0;
while Ea>Es
xa=xr;
xr=(x1+xu)/2; %formula de biseccion
if funcionk(x1)*funcionk(xr)<0
xu=xr;
Ea=abs((xr-xa)/xr)*100;
elseif funcionk(x1)*funcionk(xr)>0
x1=xr;
Ea=abs((xr-xa)/xr)*100;
end
i=i+1;
end
fprintf('raiz solucion:%12.15f\n',xr)
fprintf('Error aproximado:%12.10f\n',Ea)
fprintf('numero iteraciones:%12.0f\n',i)
a) Grafica.
b) Usando el Mtodo de Newton Raphson empleando como valor inicial
xi=0.5.
SOLUCION:
CDIGO DEL MTODO NEWTON RAPHSON
clear;clc
n=input('ingrese precision de cifras significativas n=');
xi=input('ingrese VALOR INICIAL xi=');
Es=(0.5*10^(2-n));
Ea=100;
i=0;
while Ea>Es
xa=xi;
fxi=-2+6*xi-4*xi.^2+0.5*xi.^3;
dxi=6-8*xi+1.5*xi.^2; % simpre que la derivada sea diferente de cero
xi=xi-fxi/dxi;
Ea=abs((xi-xa)/xi)*100; %calculo el error porentual
aproximado
f=
@(x)4*x.^4-6*x.^2-11/4
>> x=0:0.1:2
x=
Columns 1 through 16
Columns 17 through 21
>> plot(x,f(x))
>>
GRAFICA
13. El polinomio
4 3 2
f ( x )=0.0074 x 0.284 x +3.355 x 12183 x+5
SOLUCION:
CDIGO DEL MTODO NEWTON RAPHSON
clear;clc
n=input('ingrese precision de cifras significativas n=');
xi=input('ingrese VALOR INICIAL xi=');
Es=(0.5*10^(2-n));
Ea=100;
i=0;
while Ea>Es
xa=xi;
fxi=0.0074*xi.^4-0.284*xi.^3+3.355*xi.^2-12-183*xi+5;
dxi=0.0296*xi.^3-0.852*xi.^2+6.71*xi-183; % simpre que la
derivada sea diferente de cero
xi=xi-fxi/dxi;
Ea=abs((xi-xa)/xi)*100; %calculo el error porentual
aproximado
Columns 1 through 16
Columns 17 through 21
>> plot(x,f(x))
GRAFICA
Ejemplo
1.- Encontrar la solucin del sistema:
xe y =0
e y y=0
SOLUCION.
CODIGO DEL METODO DE ITERACION DE PUNTO FIJO
clear;clc;
disp('calcula la raiz de un sistema de dos ecuaciones no lineales')
disp('por el metodo abierto')
disp('iteracion simple punto fijo')
n=input('n=');
x0=input('x0=');
y0=input('y0=');
Es=(0.5*10^(2-n));
Eax=100;
Eay=100;
i=0;
%EL SISTEMA DE ECUACIONES ES
%U(x,y)=exp(-y)
%V(x,y)=exp(-x)
while Eax>Es && Eay>Es
xi=exp(-y0);
yi=exp(-x0);
Eax=abs((xi-x0)/xi)*100;
Eay=abs((yi-y0)/yi)*100;
x0=xi;
y0=yi;
i=i+1;
end
fprintf('la raiz "x" es :%12.15f\n',xi)
fprintf('la raiz "y" es :%12.15f\n',yi)
fprintf('numero de iteraciones:%12.0f\n',i)
5 x1 +2 x 2+2 x 3=4
3 x 1 + x 2+ x 3
SOLUCION:
CODIGO REGLA DE CRAMER
% REGLA DE CRAMER Solucion de sistemas de E.L
clear;clc
a=input('ingrese Matriz A[] nxn:');
n=length(a);
for i=1:n
A=a;
A(:,i)=+b;
d(i)=det(A);
end
D=det(a);
x=(d/D)';
a,b,x
PRUEBA DEL PROGRAMA
ingrese Matriz A[] nxn:[2 1 -1;5 2 2;-3 1 1]
ingrese Vector B[] nx1:[1 -4 1]'
a=
2 1 -1
5 2 2
-3 1 1
b=
1
-4
1
x=
-0.5455
0.7273
-1.3636
SOLUCION:
CODIGOELIMINACION DE GAUSS DETERMINANTE
%Eliminacion de Gauss Determinante
clear;
A=input('ingrese Matriz A=')
n=length(A);
for i=1:n-1
for k=i+1:n
f=A(k,i)/A(i,i);
for j=i+1:n
A(k,j)=A(k,j)-f*A(i,j);
end
end
end
det=1;
for i=1:n
det=det*A(i,i);
end
fprintf('El determinante de |A| es %12.4f\n:',det)
A=
2 1 -1 1
1 2 2 -3
3 -1 -1 2
2 3 1 4
RESULTADO
A3=-0.91
A2=0.5
A1=1.9
A0=4.5
n=length(a);
for i=1:n
A=a;
A(:,i)=+b;
d(i)=det(A);
end
D=det(a);
x=(d/D)';
a,b,x
a=
-8 4 -2 1
-1 1 -1 1
1 1 1 1
8 4 2 1
b=
10
4
6
3
x=
-0.9167
0.5000
1.9167
4.5000
f=
@(x)-0.9167*x.^3+0.5000*x.^2+1.9167*x+4.5000
x=0:0.1:2
x=
Columns 1 through 16
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
0.8000 0.9000 1.0000 1.1000 1.2000 1.3000 1.4000 1.5000
Columns 17 through 21
>> plot(x,f(x))
METODOS NUMERICOS APLICADOS AL CLCULO DEL COEFICIENTE DE
FRICCION
Calculo del factor de friccin
Ejemplo:
SOLUCION:
CODIGO METODO PUNTO FIJO
%iteraciones tuberias
clear;clc;
disp('calcula la raiz de la ecuacion no lineal')
disp('por el metodo abierto')
disp('iteracion simple punto fijo')
n=input('n=')
xi=input('x0=')
Es=(0.5*10^(2-n));
Ea=100;
i=0;
while Ea>Es
xa=xi;
xa
xi=-2*log10(0.0002/(3.7*0.7)+2.51*xi/300000)
Ea=abs((xi-xa)/xi)*100;
i=i+1;
end
fprintf('la raiz es :%12.15f\',xi)
fprintf('numero de iteraciones:%12.0f\n',i)
PRUEBA DEL PROGRAMA:
calcula la raiz de la ecuacion no lineal
por el metodo abierto
iteracion simple punto fijo
n=10
x0=31.6227766
xi =31.6228
xa =31.6228
xi = 6.9325
xa =6.9325
xi = 7.7379
xa =7.7379
xi =7.6957
xa = 7.6957
xi = 7.6978
xa =7.6978
xi = 7.6977
xa = 7.6977
xi = 7.6977
xa =7.6977
xi =7.6977
xa =7.6977
xi =7.6977
xa =7.6977
xi =7.6977
xa = 7.6977
xi =7.6977
EJEMPLO:
2
y =2 xy y=e x 1 , y (1 ) =1
y n+1= y n+ hf ( xn , y n ) x n+1=x n +h
Mtodo de Runge-Kutta:
1
y n+1= y n+ ( k 1 +2 k 2 +2 k 3 +k 4 ) x n+1 =xn + h
6
k 1=hf (x n y n )
1 1
k 2=hf ( x n+ h , y n + k 1)
2 2
1 1
k 3 =hf (x n + h , y n+ k 2)
2 2
k 4=hf (x n +h , y n +k 3)
SOLUCION:
2
h 0.1
n xn yn
0 1 1
1 1.1 1.23367806
2 1.2 1.55270722
3 1.3 1.99371553
4 1.4 2.61169647
5 1.5 3.49034296
6 1.6 4.75882125
7 1.7 6.61936868
8 1.8 9.39333129
9 1.9 13.5990509
16
14
12
10
0
0.8 1 1.2 1.4 1.6 1.8 2
Grafica Mtodo de Euler:
h 0.1
n xn yn
0 1 1
1 1.1 1.2
2 1.2 1.464
3 1.3 1.81536
4 1.4 2.2873536
5 1.5 2.92781261
6 1.6 3.80615639
7 1.7 5.02412644
8 1.8 6.73232942
9 1.9 9.15596802
10
9
8
7
6
5
4
3
2
1
0
0.8 1 1.2 1.4 1.6 1.8 2
Grafica Mtodo de Euler mejorado:
h 0.1
n xn yn y'n+1
0 1 1 1.2
1.
1 1 1.232 1.50304
1.
2 2 1.5478848 1.91937715
1.
3 3 1.98315001 2.49876901
1.
4 4 2.59078717 3.31620757
1.
5 5 3.45092851 4.48620706
1.
6 6 4.68636091 6.1859964
1.
7 7 6.48779805 8.69364938
1.
8 8 9.1555806 12.4515896
1.
9 9 13.1693871 18.1737543
14
12
10
0
0.8 1 1.2 1.4 1.6 1.8 2
Grafica Mtodo de Runge-Kutta:
n xn yn k1 k2 k3 k4 Yn+1
0.271536 1.233674
0 1 1 0.2 0.231 0.234255 1 35
1.233674 0.271408 0.314957 0.319965 0.372873 1.552695
1 1.1 35 36 06 163 48 4
1.552695 0.372646 0.434754 0.442518 0.518755 1.993686
2 1.2 4 9 71 188 53 77
1.993686 0.518358 0.608273 0.620412 0.731947 2.611633
3 1.3 77 56 83 395 77 23
2.611633 0.731257 0.863405 0.882567 1.048260 3.490210
4 1.4 23 31 95 5 22 64
3.490210 1.047063 1.244260 1.274825 1.524811 4.758551
5 1.5 64 19 09 612 6 67
4.758551 1.522736 1.821573 1.870881 2.254007 6.618827
6 1.6 67 53 58 691 34 41
6.618827 2.250401 2.710409 2.790911 3.387505 9.392252
7 1.7 41 32 82 311 94 33
9.392252 3.381210 4.100657 4.233754 5.177882 13.59690
8 1.8 33 84 37 973 77 54
13.59690 5.166824 6.310323 6.533306 8.052084 20.08126
9 1.9 54 04 78 234 64 68
16
14
12
10
0
0.8 1 1.2 1.4 1.6 1.8 2
Comparacion de curvas
16
14
12
10
Yn 8
6
4
2
0
0.8 1 1.2 1.4 1.6 1.8 2
Xn