Está en la página 1de 22

ANALISIS NUMERICO EN INGENIERIA CON APLICACIONES EN MATLAB

JOSE ARAPA QUISPE

3.6. Problemas propuestos.

2. Determine las Raíces reales de:


𝑓(𝑥) = −26 + 82.3𝑥 − 88𝑥 2 + 45.4𝑥 3 − 9𝑥 4 + 0.65𝑥 5
a) Gráficamente.
b) Usando el método de bisección. 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
8. Determine las raíces de 𝑓(𝑥) = −2.0 + 6𝑥 − 4𝑥 2 + 0.5𝑥 3

a) Grafica.
b) Usando el Método de Newton Raphson empleando como valor inicial xi=0.5.

SOLUCION:

CÓDIGO DEL MÉTODO 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

𝑓(𝑥) = 0.0074𝑥 4 − 0.284𝑥 3 + 3.355𝑥 2 − 12 − 183𝑥 + 5

Aplique a esta función el método de Newton-Raphson usando como valor inicial 𝑥0 =16.15

SOLUCION:

CÓDIGO DEL MÉTODO 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 solución del sistema:

𝑥 − 𝑒 −𝑦 = 0
𝑒 −𝑦 − 𝑦 = 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 método de eliminación de Gauss-Jordán para resolver:

2𝑥1 + 𝑥2 − 𝑥3 = 1
5𝑥1 + 2𝑥2 + 2𝑥3 = −4
−3𝑥1 + 𝑥2 + 𝑥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=

-4

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 1−1 1
|𝐴| = | 1 2 2 − 3 |
3−1−12
2 3 1 4
SOLUCION:

CODIGO”ELIMINACION 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 función 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

Método 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 Solución 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 CÁLCULO DEL COEFICIENTE DE FRICCION

Calculo del factor de fricción

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 raíz es :7.697724028738633 número de iteraciones: 10


MÉTODO DE EULER Y ANÁLISIS DE ERROR
Introducción
Recuerde la estructura del Método de Euler
yn+1 = yn + hf (xn, yn)

Errores en Métodos Numéricos


Una fuente de error que siempre está presente en los cálculos es el error de rondeo.

EJEMPLO:
2 −1
𝑦´ = 2𝑥𝑦 ˰ 𝑦 = 𝑒 𝑥 , 𝑦(1) = 1

𝑥0 = 1 ˰ 𝑦0 = 1
Método de Euler:

𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓(𝑥𝑛 , 𝑦𝑛 ) ˰ 𝑥𝑛+1 = 𝑥𝑛 + ℎ

Método de Euler mejorado:

𝑦𝑛+1 = 𝑦𝑛 + ℎ(𝑥𝑛 𝑦𝑛 + 𝑥𝑛+1 𝑦´𝑛+1 ˰ 𝑥𝑛+1 = 𝑥𝑛 + ℎ

Método de Runge-Kutta:

1
𝑦𝑛+1 = 𝑦𝑛 + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 ) ˰ 𝑥𝑛+1 = 𝑥𝑛 + ℎ
6
𝑘1 = ℎ𝑓(𝑥𝑛 𝑦𝑛 )
1 1
𝑘2 = ℎ𝑓(𝑥𝑛 + ℎ , 𝑦𝑛 + 𝑘1 )
2 2
1 1
𝑘3 = ℎ𝑓(𝑥𝑛 + ℎ , 𝑦𝑛 + 𝑘2 )
2 2
𝑘4 = ℎ𝑓(𝑥𝑛 + ℎ , 𝑦𝑛 + 𝑘3 )
SOLUCION:
2 −1
Grafica de la función: 𝑦 = 𝑒 𝑥

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 0.5 1 1.5 2
Grafica Método 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 0.5 1 1.5 2
Grafica Método de Euler mejorado:

h 0.1
n xn yn y'n+1
0 1 1 1.2
1 1.1 1.232 1.50304
2 1.2 1.5478848 1.91937715
3 1.3 1.98315001 2.49876901
4 1.4 2.59078717 3.31620757
5 1.5 3.45092851 4.48620706
6 1.6 4.68636091 6.1859964
7 1.7 6.48779805 8.69364938
8 1.8 9.1555806 12.4515896
9 1.9 13.1693871 18.1737543

14

12

10

0
0 0.5 1 1.5 2
Grafica Método de Runge-Kutta:

n xn yn k1 k2 k3 k4 Yn+1
0 1 1 0.2 0.231 0.234255 0.2715361 1.23367435
1 1.1 1.23367435 0.27140836 0.31495706 0.319965163 0.37287348 1.5526954
2 1.2 1.5526954 0.3726469 0.43475471 0.442518188 0.51875553 1.99368677
3 1.3 1.99368677 0.51835856 0.60827383 0.620412395 0.73194777 2.61163323
4 1.4 2.61163323 0.73125731 0.86340595 0.8825675 1.04826022 3.49021064
5 1.5 3.49021064 1.04706319 1.24426009 1.274825612 1.5248116 4.75855167
6 1.6 4.75855167 1.52273653 1.82157358 1.870881691 2.25400734 6.61882741
7 1.7 6.61882741 2.25040132 2.71040982 2.790911311 3.38750594 9.39225233
8 1.8 9.39225233 3.38121084 4.10065737 4.233754973 5.17788277 13.5969054
9 1.9 13.5969054 5.16682404 6.31032378 6.533306234 8.05208464 20.0812668

16

14

12

10

0
0 0.5 1 1.5 2
Comparacion de curvas
16
14
12
10
Yn

8
6
4
2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Xn

Solucion exacta Euler Euler mejorado Runge-Kutta

También podría gustarte