Está en la página 1de 18

INSTITUTO TECNOLOGICO DE SANTO DOMINGO

JARIXANDER PEREZ ROMERO

1071150

PRACTICA #1

ANALISIS NUMERICO

SECCION 03

PROF. MARIA PENKOVA VASSILEVA


Table of Contents
Tema 1 .............................................................................................................................. 1
Tema 2 .............................................................................................................................. 3
Tema 3 .............................................................................................................................. 5
Tema 4 .............................................................................................................................. 6
Tema 5 .............................................................................................................................. 8
Tema 6 .............................................................................................................................. 9
Tema 7 ............................................................................................................................ 10
Tema 8 ............................................................................................................................ 11
Tema 9 ............................................................................................................................ 11
Tema 10 .......................................................................................................................... 12
Tema 11 .......................................................................................................................... 13
Tema 13 .......................................................................................................................... 14

Tema 1
% Tamaño de paso 0.5

x0 = 0;
y0 = 1;
h = 0.5;
xf = 2.5;

n = (xf-x0)/h;

for i=(1:n)

y = y0 + h*(x0^2 - y0);
y0 = y;
x0 = x0 + h;

end

Y1 = y

% Tamaño de paso 0.25

x0 = 0;
y0 = 1;
h = 0.25;
xf = 2.5;

n = (xf-x0)/h;

for i=(1:n)

y = y0 + h*(x0^2 - y0);
y0 = y;
x0 = x0 + h;

1
end

Y2 = y

% Tamaño de paso 0.1

x0 = 0;
y0 = 1;
h = 0.1;
xf = 2.5;

n = (xf-x0)/h;

for i=(1:n)

y = y0 + h*(x0^2 - y0);
y0 = y;
x0 = x0 + h;

end

Y3 = y

% Solucion exacta

syms y(x)

y(x) = dsolve(diff(y) == x^2 - y, y(0) == 1)

Vreal = eval(y(2.5))

% Diferencia de error

Error_1 = abs(((Vreal-Y1)/Vreal)*100)

Error_2 = abs(((Vreal-Y2)/Vreal)*100)

Error_3 = abs(((Vreal-Y3)/Vreal)*100)

Y1 =

2.7344

Y2 =

2.9578

Y3 =

3.0854

2
y(x) =

x^2 - exp(-x) - 2*x + 2

Vreal =

3.1679

Error_1 =

13.6853

Error_2 =

6.6337

Error_3 =

2.6051

Tema 2
%Tamaño de paso 0.1

x1 = 0;
y1 = 1;
h = 0.1;
xf = 2.5;

n = (xf-x1)/h;

for i=(1:n)

y = y1 + h*(3*y1 - 3*x1);
y1 = y;
x1 = x1 + h;

end

Y1 = y

% Tamnaño de paso 0.05

x1 = 0;
y1 = 1;
h = 0.05;
xf = 2.5;

3
n = (xf-x1)/h;

for i=(1:n)

y = y1 + h*(3*y1 - 3*x1);
y1 = y;
x1 = x1 + h;

end

Y2 = y

% Tamnaño de paso 0.01

x1 = 0;
y1 = 1;
h = 0.01;
xf = 2.5;

n = (xf-x1)/h;

for i=(1:n)

y = y1 + h*(3*y1 - 3*x1);
y1 = y;
x1 = x1 + h;

end

Y3 = y

% Solucion Exacta

syms y(x)

y(x) = dsolve (diff(y) == 3*y - 3*x, y(0) == 1)

Vreal = eval(y(2.5))

% Error

Error1 = abs((Vreal - Y1)/Vreal)*100


Error2 = abs((Vreal - Y2)/Vreal)*100
Error3 = abs((Vreal - Y3)/Vreal)*100

Y1 =

473.2607

Y2 =

4
725.2716

Y3 =

1.0823e+03

y(x) =

x + (2*exp(3*x))/3 + 1/3

Vreal =

1.2082e+03

Error1 =

60.8291

Error2 =

39.9706

Error3 =

10.4189

Tema 3
% CASO 1: Tamaño de paso h = 0.5;

x1 = 0;
y1 = 0;
h = 0.5;
xf = 10;
Q = 500;
A = 1200;

n = (xf - x1)/h;

for i=(1:n)

y2 = y1 + h*( (Q/A)*(3*(sin(x1))^2 - 1) );
y1 = y2;
x1 = x1 + h;

end

5
Y1 = y2

% CASO 2: Tamaño de paso h = 0.5;

x1 = 0;
y1 = 0;
h = 0.5;
xf = 10;
a = 300;

n = (xf - x1)/h;

for i=(1:n)

y2 = y1 + h*( (3*Q/A)*((sin(x1))^2) - a*(1+y1)^1.5/A );


y1 = y2;
x1 = x1 + h;

end

Y2 = y2

Y1 =

1.7297

Y2 =

0.5463

Tema 4
% PARTE a) Solo se basa en escribir la ecuacion diferencial, teniendo
en cuenta
% que la velocidad apunta hacia arriba como positiva

% m*dv/dt = -m*g1*R^2/(R+x)^2 + cv

% PARTE b) En esta parte, el segundo termino relacionado con la fuerza


de
% arrastre "cv" se anula, o se hace 0

% m*dv/dt = -m*g1*R^2/(R+x)^2

% dv/dt = (dv/dx)*(dx/dt); pero dx/dt = v


% Finalmente; dv/dt = v*(dv/dx)
% v*(dv/dx) == -g0*(R^2/(R+x)^2)
% dv/dx == -g0*(R^2/(R+x)^2)*(1/v)
% En lenguaje de matlab seria pues:

6
% diff(v) == -g0*(R^2/(R+x)^2)*(1/v)

% Parte c)

syms v(x) g0 R v0
v(x) = dsolve(diff(v) == -g0*(R^2/(R+x)^2)*(1/v), v(0) == v0)

% La solucion de esto da como resultado dos partes iguales, pero de


signos
% contrarios, pues se trata de una raiz

% Parte d)

% Tamaño de paso h = 10000

x1 = 0; % Altura inical
v1 = 1400; % Velocidad inicial
h = 10000; % Tamaño de paso
xf = 100000; % Posicion final
g0 = 9.8; % Valor inicial de la gravedad
R = 6.37*10^6;

n = (xf - x1)/h;

for i=(1:n)

v2 = v1 + h*( -g0*(R^2/(R+x1)^2)*(1/v1) );
v1 = v2;
x1 = x1 + h;

end

% Valor aproximado de la velocidad final


V1 = v2

% Comparacion con la solucion real

syms v(x)
v(x) = dsolve(diff(v) == -g0*(R^2/(R+x)^2)*(1/v), v(0) == 1400) %
Donde la velocidad inicial es de 1400 m/s
V_exacto = eval(v(100000)) % Evaluando la solucion exacta en x =
100000

% Obtencion del error mediante error relativo porcentual


Error = abs((V_exacto - V1)/V_exacto)*100

% El error es muy grande debido al gigante tamaño de paso (son 10000)

v(x) =

2^(1/2)*(v0^2/2 - R*g0 + (R^2*g0)/(R + x))^(1/2)


-2^(1/2)*(v0^2/2 - R*g0 + (R^2*g0)/(R + x))^(1/2)

7
V1 =

376.5736

v(x) =

2^(1/2)*(397653620000000/(x + 6370000) - 61446000)^(1/2)

V_exacto =

174.0507

Error =

116.3585

Tema 5
a = 300000;
b = 9460000000000000;
c = 141.8*10^6;
d = 0.00000000000000000000000000169;
e = 0.0000000267;

A = vpa(a*1000, 2)
B = vpa(b, 3)
C = vpa(c*1000, 3)
D = vpa(d, 3)
E = vpa(e, 3)

A =

3.0e8

B =

9.46e15

C =

1.42e11

D =

8
1.69e-27

E =

2.67e-8

Tema 6
num = 48.649;

% Dos cifras significativas por truncamiento

num_T = round(num, 2, 'significant') - 1

% Cuatro cifras significativas por exceso

num_E = round(num, 4, 'significant')

% Tres cifras significativas por redondeo

num_R = round(num, 3, 'significant')

% Error absoluto de cada caso

ErrorAb_T = abs(num-num_T)
ErrorAb_E = abs(num-num_E)
ErrorAb_R = abs(num-num_R)

num_T =

48

num_E =

48.6500

num_R =

48.6000

ErrorAb_T =

0.6490

ErrorAb_E =

9
1.0000e-03

ErrorAb_R =

0.0490

Tema 7
exp1 = 101.5;
exp2 = 99;
exp3 = 100.5;
exp4 = 98;

m = (exp1+exp2+exp3+exp4)/4

%Errrores absolutos respecto a la media


Ea1 = abs(m-exp1)
Ea2 = abs(m-exp2)
Ea3 = abs(m-exp3)
Ea4 = abs(m-exp4)

%Errores relativos respecto a la media


Er1 = abs((m-exp1)/m)
Er2 = abs((m-exp2)/m)
Er3 = abs((m-exp3)/m)
Er4 = abs((m-exp4)/m)

m =

99.7500

Ea1 =

1.7500

Ea2 =

0.7500

Ea3 =

0.7500

Ea4 =

1.7500

10
Er1 =

0.0175

Er2 =

0.0075

Er3 =

0.0075

Er4 =

0.0175

Tema 8
bin1 = '1100111';
bin2 = '1111000';

dec1 = bin2dec(bin1)
dec2 = bin2dec(bin2)

dec1 =

103

dec2 =

120

Tema 9
num1 = 329;
num2 = 64.55;

binario1 = dec2bin(num1)
binario2 = dec2bin(num2)

binario1 =

'101001001'

11
binario2 =

'1000000'

Tema 10
a = -24.56;

% Primer, fijarse en el signo y observar que si es negativo, entonces


el
% signo valdra 1, pero si es positivo, el signo valdra 0

% Signo = 1

% Despues, convertir la parte entera en binaria

Parte_entera = dec2bin(24)

% Luego, se calcula el binario de la parte decimal justo como lo


hicimos
% con el tema 9

0.56*2
% Parte decimal = 0.12; parte entera = 1

0.12*2
% Parte decimal = 0.24; parte entera = 0

0.24*2
% Parte decimal = 0.48; parte entera = 0

0.48*2
% Parte decimal = 0.96; parte entera = 0

0.96*2
% Parte decimal = 0.92; parte entera = 1

% LO dejamos hasta aqui

% Binario = 11000.10001

% corremos el punto decimal hasta antes del ultimo 1

% Numero nuevo = 1.100010001

% Mantisa = 100010001 (que es todo lo que esta antes del punto del
nuevo numero)
% Pero recuerden que hay que completar con ceros hasta ocupar 23
digitos
% Mantisa = 10001000100000000000000

12
% ¿Cuantas veces se corrio el numero? 4 veces
% Exponente en exceso = 4+127 = 131
% Convertimos este nuevo numero en binario

Exp_exceso = dec2bin(131);

% Finalmente se unen: Signo, Mantisa, Exponente en exceso

Representacion_IEEE_754 = '1 10000011 10001000100000000000000'

Parte_entera =

'11000'

ans =

1.1200

ans =

0.2400

ans =

0.4800

ans =

0.9600

ans =

1.9200

Representacion_IEEE_754 =

'1 10000011 10001000100000000000000'

Tema 11
a = 256;
% Signo = 0
% Despues, convertir la parte entera en binaria

13
Parte_entera = dec2bin(256)

% Binario = 100000000

% corremos el punto decimal hasta antes del ultimo 1

% Numero nuevo = 1.00000000

% Exponente en exceso = 8 +127 = 135


Exp_exceso = dec2bin(135)
% Finalmente se unen: Signo, Mantisa, Exponente en exceso

Representacion_IEEE_754 = '0 10000111 00000000000000000000000'

Parte_entera =

'100000000'

Exp_exceso =

'10000111'

Representacion_IEEE_754 =

'0 10000111 00000000000000000000000'

Tema 13
syms x

a = 2;
n = 3;
Funcion1(x) = sqrt(x);
% Orden de todo: funcion, variable, a, 'Order',grado+1
Taylor1(x) = taylor(Funcion1, x, a, 'Order',n+1)
Taylor_sup1(x) = taylor(Funcion1, x, a, 'Order',n+2);
Resto1(x) = Taylor_sup1 - Taylor1
% x = 3.5
V_Funcion1 = eval(Funcion1(3.5))
V_Taylor1 = eval(Taylor1(3.5))
V_Taylor_sup1 = eval(Taylor_sup1(3.5));
V_Resto1 = eval(Resto1(3.5))
Error1 = abs(V_Funcion1 - V_Taylor1)

a = 0;
n = 4;
Funcion2(x) = sqrt(x+1);

Taylor2(x) = taylor(Funcion2, x, a, 'Order',n+1)

14
Taylor_sup2(x) = taylor(Funcion2, x, a, 'Order',n+2);
Resto2(x) = Taylor_sup2 - Taylor2
% x = 1
V_Funcion2 = eval(Funcion2(1))
V_Taylor2 = eval(Taylor2(1))
V_Taylor_sup2 = eval(Taylor_sup2(1));
V_Resto2 = eval(Resto2(1))
Error2 = abs(V_Funcion2- V_Taylor2)

a = pi/5;
n = 4;
Funcion3(x) = cos(x);

Taylor3(x) = taylor(Funcion3, x, a, 'Order',n+1)


Taylor_sup3(x) = taylor(Funcion3, x, a, 'Order',n+2);
Resto3(x) = Taylor_sup3 - Taylor3
% x = pi/2
V_Funcion3 = eval(Funcion3(pi/2))
V_Taylor3 = eval(Taylor3(pi/2))
V_Taylor_sup3 = eval(Taylor_sup3(pi/2));
V_Resto3 = eval(Resto3(pi/2))
Error3 = abs(V_Funcion3 - V_Taylor3)

Taylor1(x) =

2^(1/2) + (2^(1/2)*(x - 2))/4 - (2^(1/2)*(x - 2)^2)/32 + (2^(1/2)*(x -


2)^3)/128

Resto1(x) =

-(5*2^(1/2)*(x - 2)^4)/2048

V_Funcion1 =

1.8708

V_Taylor1 =

1.8824

V_Resto1 =

-0.0175

Error1 =

0.0116

15
Taylor2(x) =

- (5*x^4)/128 + x^3/16 - x^2/8 + x/2 + 1

Resto2(x) =

(7*x^5)/256

V_Funcion2 =

1.4142

V_Taylor2 =

1.3984

V_Resto2 =

0.0273

Error2 =

0.0158

Taylor3(x) =

5^(1/2)/4 - (5^(1/2)/8 + 1/8)*(x - pi/5)^2 + (5^(1/2)/96 + 1/96)*(x -


pi/5)^4 + (2^(1/2)*(x - pi/5)^3*(5 - 5^(1/2))^(1/2))/24 - (2^(1/2)*(x
- pi/5)*(5 - 5^(1/2))^(1/2))/4 + 1/4

Resto3(x) =

-(2^(1/2)*(x - pi/5)^5*(5 - 5^(1/2))^(1/2))/480

V_Funcion3 =

V_Taylor3 =

0.0043

V_Resto3 =

16
-0.0036

Error3 =

0.0043

Published with MATLAB® R2017a

17

También podría gustarte