function v = func_caida
syms x
g=9.8;
m=68.1;
c=12.5;
%haciendo V(t)=V(x)
v=g*m*(1-exp(-c*x/m))/c;
v=char(v);
end
function p=simpson3(f,a,b,n)
%{
f='f(x)'
a=límite inferior
b=límite superior
n=número de segmentos
%}
f=inline(f);
h=(b-a)/n;
n=n+1;
y=zeros(n,1);
x=zeros(n,1);
suma=0;
for i=1:n
x(i)=a+h*(i-1);
y(i)=feval(f,x(i));
end
for i=2:n-1
if rem(i,2)==1
suma=suma+2*y(i);
else
suma=suma+4*y(i);
end
end
p=h*(y(1)+suma+y(n))/3;
end
function p = trapezoide(f,a,b,n)
%{
f='f(x)'
a=límite inferior
b=límite superior
n=número de segmentos
%}
f=inline(f);
h=(b-a)/n;
n=n+1;
y=zeros(n,1);
x=zeros(n,1);
suma=0;
%p=(h/2)*(f(a)+2f(a+h)+2f(a+2h)+...+f(b))
for i=1:n
x(i)=a+h*(i-1);
y(i)=feval(f,x(i));
end
for i=2:n-1
suma=suma+y(i);
end
p=0.5*h*(y(1)+2*suma+y(n));
PROGRAMA
%% INPUTS
clear;close all;clc
disp('EXAMEN PARCIAL - MÉTODOS NUMÉRICOS I')
disp('RESOLUCIÓN DEL PROBLEMA N°4')
fprintf('\n\n')
f=input('Ingrese la función: ');%func_caida
a=input('Digite el límite inferior: ');%0
b=input('Digite el límite superior: ');%10
es=input('Error estimado: ');%0.0012
d=input('Introducir valor exacto: ');%289.43515 Distancia exacta
et=100;
i=0;
t=0;
s=0;
%% LAZO
fprintf('INTEGRACIÓN dividiendo segmentos para MÉTODOS DE TRAPECIO y
SIMPSON 1/3\n')
fprintf('en la relación de 1 a 2\n')
fprintf('\n Segment\tTamaño\t\tT/S3\td aprox\t\t\tet\n')
while et>es
t=t+1;
s=s+2;
h=(b-a)/(t+s);
p1=trapezoide(f,a,a+t*h,t);
p2=simpson3(f,a+t*h,b,s);
p=p1+p2;
et=abs(d-p)*100/d;
fprintf('\t%d\t\t %3.5f\t%d/%d\t %3.5f\t\t%3.5f\n',t+s,h,t,s,p,et)
i=i+1;
end
fprintf('\nNúmero de segmentos trabajados con TRAPOEZOIDE: %d',t)
fprintf('\nNúmero de segmentos trabajados con SIMPSON 1/3: %d',s)
fprintf('\nCantidad de iteraciones: %d',i)
fprintf('\nLa integral es %4.5f\n\n',p)
EXAMEN PARCIAL - MÉTODOS NUMÉRICOS I
RESOLUCIÓN DEL PROBLEMA N°4
Ingrese la función: func_caida
Digite el límite inferior: 0
Digite el límite superior: 10
Error estimado: 0.0012
Introducir valor exacto: 289.43515
INTEGRACIÓN dividiendo segmentos para MÉTODOS DE TRAPECIO y SIMPSON 1/3
en la relación de 1 a 2
Segment Tamaño T/S3 d aprox et
3 3.33333 1/2 285.22509 1.45458
6 1.66667 2/4 288.39321 0.35999
9 1.11111 3/6 288.97298 0.15968
12 0.83333 4/8 289.17536 0.08976
15 0.66667 5/10 289.26894 0.05743
18 0.55556 6/12 289.31975 0.03987
21 0.47619 7/14 289.35037 0.02929
24 0.41667 8/16 289.37024 0.02242
27 0.37037 9/18 289.38387 0.01772
30 0.33333 10/20 289.39361 0.01435
33 0.30303 11/22 289.40082 0.01186
36 0.27778 12/24 289.40630 0.00997
39 0.25641 13/26 289.41057 0.00849
42 0.23810 14/28 289.41396 0.00732
45 0.22222 15/30 289.41669 0.00638
48 0.20833 16/32 289.41892 0.00561
51 0.19608 17/34 289.42078 0.00497
54 0.18519 18/36 289.42233 0.00443
57 0.17544 19/38 289.42364 0.00398
60 0.16667 20/40 289.42476 0.00359
63 0.15873 21/42 289.42573 0.00325
66 0.15152 22/44 289.42657 0.00297
69 0.14493 23/46 289.42730 0.00271
72 0.13889 24/48 289.42794 0.00249
75 0.13333 25/50 289.42850 0.00230
78 0.12821 26/52 289.42900 0.00212
81 0.12346 27/54 289.42945 0.00197
84 0.11905 28/56 289.42985 0.00183
87 0.11494 29/58 289.43021 0.00171
90 0.11111 30/60 289.43053 0.00160
93 0.10753 31/62 289.43083 0.00149
96 0.10417 32/64 289.43109 0.00140
99 0.10101 33/66 289.43133 0.00132
102 0.09804 34/68 289.43155 0.00124
105 0.09524 35/70 289.43176 0.00117
Número de segmentos trabajados con TRAPOEZOIDE: 35
Número de segmentos trabajados con SIMPSON 1/3: 70
Cantidad de iteraciones: 35
La integral es 289.43176
>>