You are on page 1of 23

ANALISIS NUMERICO EN INGENIERIA CON APLICACIONES EN

MATLAB
JOSE ARAPA QUISPE

3.6. Problemas propuestos.

2. Determine las Races reales de:


f ( x )=26+82.3 x88 x 2 +45.4 x 39 x 4 + 0.65 x 5
a) Grficamente.
b) Usando el mtodo de biseccin. Utilice como valores iniciales
x1=0.5 y xu=1.0

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;

CODIGO DEL METODO BISECCION

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)

PRUEBA DEL PROGRAMA

CALCULO DE LA RAIZ DE UNA ECUACION NO LINEAL


POR EL METODO CERRADO DE BISECCION
Ingrese precision de cifras significativas n=4
Ingrese limite inferior x1=0.5
Ingrese limite superior xu=1
raiz solucion:0.579330444335938
Error aproximado:0.0026338663
numero iteraciones: 15
2 3
8. Determine las races de f ( x )=2.0+6 x4 x + 0.5 x

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

i=i+1;%cuenta el numero de iteraciones efectuadas


end
fprintf(' raiz :%12.15f\n',xi)

fprintf( ' numero de iteraciones :%12.15f\n',i)

PRUEBA DEL PROGRAMA


ingrese precision de cifras significativas n=3
ingrese VALOR INICIAL xi=0.5
raiz :0.474572439155140
numero de iteraciones :3.000000000000000
>> f=@(x)4*x.^4-6*x.^2-11/4

f=
@(x)4*x.^4-6*x.^2-11/4

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

1.6000 1.7000 1.8000 1.9000 2.0000

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

Aplique a esta funcin el mtodo de Newton-Raphson usando como valor inicial


x 0 =16.15

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

i=i+1;%cuenta el numero de iteraciones efectuadas


end
fprintf(' raiz :%12.15f\n',xi)

fprintf( ' numero de iteraciones :%12.15f\n',i)

PRUEBA DEL PROGRAMA

ingrese precision de cifras significativas n=15


ingrese VALOR INICIAL xi=16.5
raiz :-0.038224492309283
numero de iteraciones :5.000000000000000
>> f=@(x)0.0074*x.^4-0.284*x.^3+3.355*x.^2-12-183*x+5;
>> 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

1.6000 1.7000 1.8000 1.9000 2.0000

>> 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)

PRUEBA DEL PROGRAMA PUNTO FIJO


calcula la raiz de un sistema de dos ecuaciones no lineales
por el metodo abierto
iteracion simple punto fijo
n=5
x0=0.5
y0=0.6
la raiz "x" es :0.567136722466623
la raiz "y" es :0.567157143707645
numero de iteraciones: 15

4.7. Problemas propuestos


5. Utilice el mtodo de eliminacin de Gauss-Jordn para resolver:
2 x 1 + x 2x 3=1

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:');

b=input('ingrese Vector B[] nx1:');

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

2. Elaborar un programa en Matlab que permita ingresar y obtener el


determinante de una matriz cuadrada cualquiera.
| |
2 11 1
| A|= 1 223
311 2
2314

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)

PRUEBA DEL PROGRAMA


Ingrese Matriz A=[2 1 -1 1;1 2 2 -3;3 -1 -1 2;2 3 1 4]

A=

2 1 -1 1
1 2 2 -3
3 -1 -1 2
2 3 1 4

El determinante de |A| es 86.0000


INTERPOLACION
INTERPOLACION POLINOMIAL
DADO n+1 puntos de una funcin f: R R, UN POLINOMIO de grado menor o
igual a n que pasa por cada uno de los n+1 puntos dados, es llamado
polinomio interpolador:
P(x)=an xn +an-1xn-1 + an-2 x n-2
+ +a2x2 + a1x + a
LAGRANGE
Puntos: (1,2), (3,1) y (5,4) :
P(X)=z0(X-3)(X-5)+z1(X-1)(X-5)+Z2(X-1)(X-3)
P(1)=2 EQUIVALENTEMENTE 2=Z0(-2)(-4)
Z0=0.25
Z1=-0.25
Z2=0.5
Mtodo de series de potencias
EJEMPLO: DADOS LOS PUNTOS: (-2,10),(-1,4),(1,6),(2,3) PUNTOS DISTINTOS DE
F.
SOLUCION
P(x)=a3 x3 +a2x2 + a1x + a0 .Tenemos P(-2)=10
GENERAMOS LA MATRIZ:
-8 4 -2 1 a3 = 10
-1 1 -1 1 a2 = 4
1 1 1 1 a1 = 6
8 4 2 1 a0 = 3

RESULTADO
A3=-0.91
A2=0.5
A1=1.9
A0=4.5

SOLUCION POR EL METODO DE CRAMER:

CODIGO METODO DE CRAMER


% REGLA DE CRAMER Solucin de sistemas de E.L
clear;clc
a=input('ingrese Matriz A[] nxn:');

b=input('ingrese Vector B[] nx1:');

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:[-8 4 -2 1;-1 1 -1 1;1 1 1 1;8 4 2 1]
ingrese Vector B[] nx1:[10 4 6 3]'

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

GRAFICA DEL POLINOMIO


f=@(x)-0.9167*x.^3+0.5000*x.^2+ 1.9167*x+ 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

1.6000 1.7000 1.8000 1.9000 2.0000

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

la raz es :7.697724028738633 nmero de iteraciones: 10

MTODO DE EULER Y ANLISIS DE ERROR


Introduccin
Recuerde la estructura del Mtodo de Euler
yn+1 = yn + hf (xn, yn)

Errores en Mtodos Numricos


Una fuente de error que siempre est presente en los clculos es el error
de rondeo.

EJEMPLO:
2

y =2 xy y=e x 1 , y (1 ) =1

x 0=1 y 0=1 Mtodo de Euler:

y n+1= y n+ hf ( xn , y n ) x n+1=x n +h

Mtodo de Euler mejorado:

x n y n + x n+1 y n+1 x n+1=x n +h


y n+1= y 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

Grafica de la funcin: y=e x 1

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

Solucion exacta Euler Euler mejorado Runge-Kutta

You might also like