Está en la página 1de 16

PC2-CV61

EJERCICIO 1

GRAFICO

ECXEL
X Y PRIMERO SEGUNDO TERCERO CUARTO QUINTO SEXTO SEPTIMO
5 30
10 28 -0.4
15 25 -0.6 -0.02
20 22 -0.6 0 0.00133333
25 18 -0.8 -0.02 -0.00133333 -0.00013333
30 20 0.4 0.12 0.00933333 0.00053333 2.66667E-05
35 20 0 -0.04 -0.01066667 -0.001 -6.1333E-05 -2.93333E-06
40 15 -1 -0.1 -0.004 0.00033333 5.33333E-05 3.82222E-06 1.93016E-07

CODIGO MATLAB
MEJOR AJJUSTE
x=[5 10 15 20 25 30 35 40]; %
y=[30 28 25 22 18 20 20 15];
xp=linspace(0,42);
for n=1:9
figure(1)
subplot(3,3,n)
p=polyfit(x,y,n);
ycalc=polyval(p,xp); % este ycalc es para el plot
ycal=polyval(p,x); % es necesario crear ycal para R
%R
nelem=length(y);
yp=sum(y)/nelem;
N=sum((ycal-yp).^2);
D=sum((y-yp).^2);
R=N/D
plot(x,y,'o',xp,ycalc,'--')
%ylim([0 7])
xlabel(sprintf('R: %7.7f',R))
title(sprintf('Grado del polinomio %d',n));
xlabel(sprintf('R: %7.7f',R));
end
Evaluamos

x=[5 10 15 20 25 30 35 40]; %
y=[30 28 25 22 18 20 20 15];

m=length(x);
x_1=linspace(x(1),x(m),100);

p=polyfit(x,y,6); %grado de polinomio


ycalc=polyval(p,x);

ycalc1=polyval(p,x_1);
x1=polyval(p,20)

x=[5 10 15 20 25 30 35 40]; %
y=[30 28 25 22 18 20 20 15];

m=length(x);
x_1=linspace(x(1),x(m),100);

p=polyfit(x,y,7); %grado de polinomio


ycalc=polyval(p,x);

ycalc1=polyval(p,x_1);
x1=polyval(p,20)

EJERCICIO 2

Para un paso de 4ft, entonces le corresponde 9 intervalos

REGLA DEL TRAPECIO MULTIPLE


x=0:4:36
f='200.*(x./(5+x)).*(exp(1).^(-2.*x./30))'
f=inline(f);
y=f(x)

a=x(1); %limite inferior


b=x(end); %limite superior
n=9; %númerode intervalos
x=linspace(a,b,n+1);
fx=200.*(x./(5+x)).*(exp(1).^(-2.*x./30));
V=[1 2*ones(1,n-1) 1];
I= sum(fx.*V)*(b-a)/(2*n)

%GRAFICA
plot(x,fx,'o')

hold on
x1=linspace(a,b);
y1=200.*(x1./(5+x1)).*(exp(1).^(-2.*x1./30));
plot(x1,y1,'r','lineWidth',2)

hold on
stem(x,fx,'b')

hold on
y2=interp1(x,fx,x1,'linear');
plot(x1,y2,'k');

title('TRAPECIO MULTIPLE')
xlabel(sprintf('El valor de la Integral es: %7.6f',I));

REGLA DEL SIMPSON 1/3 MULTIPLE


x=0:4:36
f='200.*(x./(5+x)).*(exp(1).^(-2.*x./30))';
f=inline(f)

a=x(1);
b=x(end);
n=9; %cambio
x=linspace(a,b,n+1);
fx=200.*(x./(5+x)).*(exp(1).^(-2.*x./30)); %cambia f
for i=2:n+1
if mod(i,2)==0
V(i)=4;
else V(i)=2;
end
end
V(1)=1; V(n+1)=1;
disp(V)
I=sum(fx.*V)*(b-a)/(3*n)

%GRAFICA
x=linspace(a,b,n+1);
y=f(x);
plot(x,y,'o')

hold on
x1=linspace(a,b);
y1=f(x1);
plot(x1,y1,'r','lineWidth',2)

hold on
stem(x,y,'b')

%Interpolación Cuadrática para cada intervalo de 2


hold on
y2=interp1(x,y,x1,'pchip');
plot(x1,y2,'k');

grid on
grid minor
hold on
title('SIMPSON 1/3 MULTIPLE')
xlabel(sprintf('El valor de la Integral es: %7.6f',I))
REGLA DEL SIMPSON 3/8 MULTIPLE
x=0:4:36;
f='200.*(x./(5+x)).*(exp(1).^(-2.*x./30))';
f=inline(f);

a=x(1);
b=x(end);
n=3;
h=(b-a)/(3*n);
x=a:h:b;
m=length(x);
j=1;
s=0;

for i=1:3:m-1
I(j)=(f(x(i))+3*f(x(i+1))+3*f(x(i+2))+f(x(i+3)))*h*3/8;
s=s+I(j);
j=j+1;
end
%Graficando cambia
%x=a:h:b;
y=f(x);
plot(x,y,'o')

hold on
%para las curvas
x1=linspace(a,b);
y1=f(x1);
plot(x1,y1,'r','lineWidth',2)

hold on
stem(x,y,'b')
hold on
y2=spline(x,y,x1);

plot(x1,y2,'k');
grid on
grid minor
hold on
title('SIMPSON 3/8 SIMPLE-MULTIPLE')
xlabel(sprintf('El valor de la Integral es: %7.6f',s));
sprintf('El valor de la Integral es: %7.6f \n',s)

CUADRANTURA DE GAUSS
a=0; %limite inferior
b=36; %limite superior
n=6; %n: número de puntos
f_pond=[0.1713245,0.3607616,0.4679136,0.4679139,0.3607616,0.1713245];
arg_fun=[-0.932469514,-0.661209386,-
0.238619186,0.238619186,0.661209386,0.932469514];
f='200.*(x./(5+x)).*(exp(1).^(-2.*x./30))'; %integral
f=inline(f);

for i=1:n
y(i)=((b-a)*arg_fun(i)+(b+a))/2;
end
dV=(b-a)/2;
for i=1:n
fx(i)=f(y(i))*dV;
end
integral=0;
for i=1:n
integral=f_pond(i)*fx(i)+integral;
end
sprintf('El valor de la Integral es: %7.8f \n',integral)

ROMBERG21
x=[0 36]; %limites de integral
f='200.*(x./(5+x)).*(exp(1).^(-2.*x./30))'; %integral
f=inline(f);
%NIVEL 0
n1=1;
x1=linspace(x(1),x(2),n1+1);
y1=f(x1);
Ih1=(x(2)-x(1))/(2*n1).*(y1(1)+y1(n1+1))

n2=2;
x2=linspace(x(1),x(2),n2+1);
y2=f(x2);
Ih2=(x(2)-x(1))/(2*n2).*(y2(1)+2*y2(n2)+y2(n2+1))

n3=4;
x3=linspace(x(1),x(2),n3+1);
y3=f(x3);
Ih3=(x(2)-x(1))/(2*n3)*(y3(1)+2*sum(y3(2:n3))+y3(n3+1))

n4=8;
x4=linspace(x(1),x(2),n4+1);
y4=f(x4);
Ih4=(x(2)-x(1))/(2*n4).*(y4(1)+2*sum(y4(2:n4))+y4(n4+1))
disp('-------------------------------')
%NIVEL 1
I12=(4*Ih2-Ih1)/3
I23=(4*Ih3-Ih2)/3
I34=(4*Ih4-Ih3)/3
disp('-------------------------------')
%NIVEL 2
I123=(16*I23-I12)/15
I234=(16*I34-I23)/15
disp('-------------------------------')
%NIVEL 3
Ifinal=(64*I234-I123)/63
sprintf('El valor de la Integral es: %7.9f \n',Ifinal)
EJERCICIO 3

EXCEL

h 5
EULER y1  y0  f (x0 ,y0) h
x0 y0 f y1
0 1500.000 -9.81 1450.95
5 1450.950 -9.78731664 1402.01
10 1402.013 -9.76546206 1353.19
15 1353.186 -9.74442838 1304.46
20 1304.464 -9.72420804 1255.84
25 1255.843 -9.7047938 1207.32
30 1207.319 -9.68617873 1158.89
35 1158.888 -9.6683562 1110.55
40 1110.546 -9.65131991 1062.29
45 1062.290 -9.63506384 1014.11
50 1014.114 -9.61958226 966.02
55 966.016 -9.60486974 917.99
60 917.992 -9.59092113 870.04
65 870.037 -9.57773156 822.15
70 822.149 -9.56529643 774.32
75 774.322 -9.55361143 726.55
80 726.554 -9.54267251 678.84
85 678.841 -9.53247588 631.18
90 631.179 -9.52301803 583.56
95 583.563 -9.51429569 535.99
100 535.992 -9.50630587 488.46
105 488.460 -9.49904583 440.97
110 440.965 -9.49251307 393.50
115 393.503 -9.48670536 346.07
120 346.069 -9.48162072 298.66
125 298.661 -9.4772574 251.27
130 251.275 -9.47361392 203.91
135 203.907 -9.47068903 156.55
140 156.553 -9.46848175 109.21
145 109.211 -9.4669913 61.88
150 61.876 -9.4662172 14.54
155 14.545 -9.46615918 -32.79
160 -32.786 -9.46681721 -80.12
RK4
x y k1 k2 k3 k4 y1
0 1500.000 -9.81 -9.79855421 -9.79855421 -9.78731664 1451.00706
5 1451.00706 -9.78731664 -9.77628625 -9.77628625 -9.76546206 1402.12545
10 1402.12545 -9.76546206 -9.75484309 -9.75484309 -9.74442838 1353.35107
15 1353.35107 -9.74442838 -9.73421701 -9.73421701 -9.72420804 1304.67981
20 1304.67981 -9.72420804 -9.7144006 -9.7144006 -9.7047938 1256.10764
25 1256.10764 -9.7047938 -9.69538679 -9.69538679 -9.68617873 1207.63054
30 1207.63054 -9.68617873 -9.6771688 -9.6771688 -9.6683562 1159.24453
35 1159.24453 -9.6683562 -9.65974016 -9.65974016 -9.65131991 1110.94567
40 1110.94567 -9.65131991 -9.64309472 -9.64309472 -9.63506384 1062.73004
45 1062.73004 -9.63506384 -9.62722659 -9.62722659 -9.61958226 1014.59374
50 1014.59374 -9.61958226 -9.6121302 -9.6121302 -9.60486974 966.532931
55 966.532931 -9.60486974 -9.59780026 -9.59780026 -9.59092113 918.543771
60 918.543771 -9.59092113 -9.58423176 -9.58423176 -9.57773156 870.622454
65 870.622454 -9.57773156 -9.57141997 -9.57141997 -9.56529643 822.765198
70 822.765198 -9.56529643 -9.55936042 -9.55936042 -9.55361143 774.96824
75 774.96824 -9.55361143 -9.54804895 -9.54804895 -9.54267251 727.22784
80 727.22784 -9.54267251 -9.53748163 -9.53748163 -9.53247588 679.540278
85 679.540278 -9.53247588 -9.52765482 -9.52765482 -9.52301803 631.90185
90 631.90185 -9.52301803 -9.51856511 -9.51856511 -9.51429569 584.308872
95 584.308872 -9.51429569 -9.51020939 -9.51020939 -9.50630587 536.757672
100 536.757672 -9.50630587 -9.50258479 -9.50258479 -9.49904583 489.244597
105 489.244597 -9.49904583 -9.49568868 -9.49568868 -9.49251307 441.766002
110 441.766002 -9.49251307 -9.48951871 -9.48951871 -9.48670536 394.318257
115 394.318257 -9.48670536 -9.48407277 -9.48407277 -9.48162072 346.897743
120 346.897743 -9.48162072 -9.47934899 -9.47934899 -9.4772574 299.500848
125 299.500848 -9.4772574 -9.47534576 -9.47534576 -9.47361392 252.123969
130 252.123969 -9.47361392 -9.47206172 -9.47206172 -9.47068903 204.763511
135 204.763511 -9.47068903 -9.46949574 -9.46949574 -9.46848175 157.415883
140 157.415883 -9.46848175 -9.46764696 -9.46764696 -9.4669913 110.077499
145 110.077499 -9.4669913 -9.46651473 -9.46651473 -9.4662172 62.7447762
150 62.7447762 -9.4662172 -9.46609869 -9.46609869 -9.46615918 15.4141336
155 15.4141336 -9.46615918 -9.46639868 -9.46639868 -9.46681721 -31.9180089
160 -31.9180089 -9.46681721 -9.4674148 -9.4674148 -9.46819151 -79.2552322

MATLAB – METODO EULER

y =

1.0e+03 *

1.5000
1.4509
1.4020
1.3532
1.3045
1.2558
1.2073
1.1589
1.1105
1.0623
1.0141
0.9660
0.9180
0.8700
0.8221
0.7743
0.7266
0.6788
0.6312
0.5836
0.5360
0.4885
0.4410
0.3935
0.3461
0.2987
0.2513
0.2039
0.1566
0.1092
0.0619
0.0145
-0.0328

MATLAB – RK4
y =

1.0e+03 *

1.5000
1.4510
1.4021
1.3534
1.3047
1.2561
1.2076
1.1592
1.1109
1.0627
1.0146
0.9665
0.9185
0.8706
0.8228
0.7750
0.7272
0.6795
0.6319
0.5843
0.5368
0.4892
0.4418
0.3943
0.3469
0.2995
0.2521
0.2048
0.1574
0.1101
0.0627
0.0154
-0.0319

La altura máxima alcanzada será cuando la velocidad llegue a cero, por lo


tanto, para un h=5, ambos métodos tendrían 33 intervalos. Siendo en ambos casos
el tiempo 155 segundos el más próximo cuando la velocidad sea cero y la altitud
sea máxima.

Por otro lado, si se trabaja con un h=0.2, habría mas iteraciones y resulta un
t=156.6 segundos para la altitud máxima con una velocidad de 0.2

[x,y] =euler_1('(-9.81*6370000.^2)./((6370000+1500.*x-
9.81/2.*x.^2).^2)',0,160,1500,0.2)

MATLAB – ODE45
>> OD45
1.0e+03 *

1.5000
1.4608
1.4217
1.3826
1.3436
1.3047
1.2658
1.2270
1.1883
1.1496
1.1109
1.0724
1.0338
0.9954
0.9569
0.9185
0.8802
0.8419
0.8036
0.7654
0.7272
0.6891
0.6510
0.6129
0.5748
0.5368
0.4987
0.4608
0.4228
0.3848
0.3469
0.3090
0.2711
0.2332
0.1953
0.1574
0.1195
0.0817
0.0438
0.0059
-0.0319

GRAFICO: EULER – RK4 – ANALITICO

Para los gráficos se uso un h=0.2


Los tres métodos coinciden en gráficos

También podría gustarte