Documentos de Académico
Documentos de Profesional
Documentos de Cultura
LABORATORIO N°4
Grupo: 1
Integrantes:
2022
Problema 1
Construya la tabla de diferencia finita e indique si es perfecta o hay propagación de errores.
x f(x) 𝛥1 𝑓𝑖 𝛥2 𝑓𝑖 𝛥3 𝑓𝑖 𝛥4 𝑓𝑖
k 1 1 - - - -
k+1 2 8 7 - - -
k+2 3 27 19 12 - -
k+3 4 64 37 18 6 -
k+4 5 125 61 24 6 0
Verificar si dados los puntos (1,1), (1.4, 1.1832), (2.2, 1.4832), (2.6, 1.6125), (3, 1.7321).
¿Es una tabla perfecta? De lo contrario explicar porque no lo es.
x f(x) 𝛥1 𝑓𝑖 𝛥2 𝑓𝑖 𝛥3 𝑓𝑖 𝛥4 𝑓𝑖
k 1 1 - - - -
En Scilab:
function problema1()
d = zeros(length(a) - 1, 1);
disp(a)
for j = 1:length(a) - 1;
disp(d)
end
d2 = zeros(length(d) - 1, 1);
for k = 1:length(d) - 1;
disp(d2)
end
d3 = zeros(length(d2) - 1, 1);
for m = 1:length(d2) - 1;
disp(d3)
end
d4 = zeros(length(d3) - 1, 1);
for n = 1:length(d3) - 1;
disp(d4)
end
endfunction
Problema 2:
x f(X)
8 0.9030900
12 1.0791812.
xo = 8
f(xo) = 0.9030900
x1 = 12
f(x1) = 1.0791812
x = 10
1.0791812 − 0.9030900
f(x) = 0.9030900 + ∗ (10 − 8)
12 − 8
f(x) = 0.9030900 + 0.0880456
f(x) = 0.9911356
log (10) = 1 valor verdadero
1 − 0.9911356
𝜉v =
1
∗ 100% = 0.0088644% error relativo porcentual verdadero
x f(X)
9 0.9542425
11 1.0413927
xo = 9
f(xo) = 0.9542425
x1 = 11
f(x1) = 1.0413927
x = 10
1.0413927 − 0.9542425
f(x) = 0.9542425 + ∗ (10 − 9)
11 − 9
f(x) = 0.9542425 + 0.0435751
f(x) = 0.9978176
1 − 0.9978176
𝜉v =
1
∗ 100% = 0.0021824% error relativo porcentual verdadero
function y=Lineal(X, Y, x)
n=length(X);
val=x
for i=1:n
if X(i)==val then
valy=Y(i)
break
else
if X(i)>val then
cota_sup=i;
cota_inf=i-1;
deltaX=X(cota_sup)-X(cota_inf);
deltaY=Y(cota_sup)-Y(cota_inf);
m=deltaY/deltaX;
valy=Y(cota_inf)+m*(val-X(cota_inf));
break
end
end
end
y=valy
endfunction
Problema 3
//Función utilizando interpolacion lineal y calculando un valor de x
clc;
clear all;
close all;
function Inter()
x=input('Ingrese el vector x: ');
y=input('Ingrese el vector y: ');
x=[0.10377, 0.11144, 0.1254];
y=[6.4147, 6.5453, 6.7664];
xi=input('Introducir un valor a interpolar : ');
n=length(x)-1;
S=0;
for k=0:n
n=k;
S=0;
for i=1:n+1
P=y(i);
for j=1:n+1
if i~=j
P=P*(xi-x(j))/(x(i)-x(j));
end
end
S=S+P;
end
sol(k+1)=S;
end
sol;
printf('\nLa interpolacion para x= %5.5f es:\n',xi)
printf(' Grado Yint');
u=0;
for t=1:n
printf('\n %d %5.8f \n',u,sol(t));
u=u+1;
end
printf('\n %d %5.8f \n',u,sol(t+1));
endfunction
EJERCICIO 4
F(x) 2 8 14 15 8 2
Elija la secuencia de puntos más apropiada para alcanzar la mayor exactitud posible para
sus estimaciones
b) Utilice la ecuación Rn= f [xn+1, xn, xn-1, ... , x0](x – x0)(x – x1)... (x – xn) (Ver
errores de la
ORDEN 1
· 𝑥0 = 2.5
· 𝑥1 = 3.2
i Xi fi DD1 DD2
1 3.2 15 -8.75
2 4 8
F (x1, x0) = 15 - 14 / 3.2 – 2.5 = 1.4285
Para 𝑓1(2.8):
Remplazando:
Hallamos el error
Remplazando:
𝑅1 = 0.8143
· 𝑥0 = 2
· 𝑥1 = 3.2
I Xi fi DD1 DD2
0 2 8 5.83 -7.291
1 3.2 15 -8.75
2 4 8
F (x1, x0) = 15-8 / 3.2-2 = 5.83
Remplazando:
𝑓 ∗1 (2.8) = 12.664
Hallamos el error
Remplazando:
𝑅1 = 2.33312
ORDEN 2
· 𝑥0 = 2
· 𝑥1 = 2.5
· 𝑥2 = 3.2
0 2 8 12 -8.81 1.01
3 4 8
𝑓2 (2.8) = 𝑓0 + 𝐹 [𝑥1; 𝑥0] (𝟐. 𝟖−𝒙𝟎) + 𝐹 [𝑥2; 𝑥1; 𝑥0] (𝟐. 𝟖−𝒙𝟎) (𝟐. 𝟖−𝒙𝟏)
Remplazando:
𝑓2 (2.8) = 15.4856
Hallamos el error
Reemplazando:
𝑅2 = −0.09696
ORDEN 3
· 𝑥0 = 2
· 𝑥1 = 2.5
· 𝑥2 = 3.2
· 𝑥3 = 4
3 4 8 -12
4 4.5 2
𝑓3 (2.8) = 𝑓0 + 𝐹 [𝑥1; 𝑥0] (𝟐. 𝟖−𝒙𝟎) + 𝐹 [𝑥2; 𝑥1; 𝑥0] (𝟐. 𝟖−𝒙𝟎) (𝟐. 𝟖−𝒙𝟏) + 𝐹 [𝑥3; 𝑥2; 𝑥1; 𝑥0]
(𝟐.𝟖−𝒙𝟎) (𝟐. 𝟖−𝒙𝟏) (𝟐. 𝟖−𝒙𝟐)
Remplazando:
𝑓3 (2.8) = 15.38864
Hallamos el error
𝑅3 = 0.05184
Scilab:
RESULTADOS EN SCILAB
Scilab:
clc
clear
opc = input('Ingrese el grado polinomial de 1 a 4 en el que desea trabajar: ')
x1 = input('Ingrese qué valor de X desea conocer: ')
select(opc)
//Grado 1
case 1
for i=1:2
v(i)=input('Ingrese los valores X: ')
fv(i)=input('Ingrese los valores Y: ')
end
fog1 = (fv(2)-fv(1))/(v(2)-v(1)) // F[X1,X0]
function y1=f1(x)
y1=fv(1)+ f0g1*(x-v(1))
endfunction
u = f1(x1)
//Grado 2
case 2
for i=1:3
v(i)=input('Ingrese los valores X: ')
fv(i)=input('Ingrese los valores Y: ')
end
f0g2=(fv(2)-fv(1))/(v(2)-v(1)) // F[X1,X0]
f1g2=(fv(3)-fv(2))/(v(3)-v(2)) // F[X2,X1]
f2g2=(f1g2-f0g2)/(v(3)-v(1)) // F[X2,X1,X0]
function y2=f2(x)
y2 = fv(1)+f0g2*(x-v(1))+f2g2*(x-v(1))*(x-v(2))
endfunction
u = f2(x1)
//Grado 3
case 3
for i=1:4
v(i)=input('Ingrese los valores X: ')
fv(i)=input('Ingrese los valores Y: ')
end
f0g3=(fv(2)-fv(1))/(v(2)-v(1)) // F[X1,X0]
f1g3=(fv(3)-fv(2))/(v(3)-v(2)) // F[X2,X1]
f2g3=(fv(4)-fv(3))/(v(4)-v(3)) // F[X3,X2]
f3g3=(f1g3-f0g3)/(v(3)-v(1)) // F[X2,X1,X0]
f4g3=(f2g3-f1g3)/(v(4)-v(2)) // F[X3,X2,X1]
f5g3=(f4g3-f3g3)/(v(4)-v(1)) // F[X3,X2,X1,X0]
function y3 = f3(x)
y3 = fv(1)+f0g3*(x-v(1))+f3g3*(x-v(1))*(x-v(2))+f5g3*(xv(1))*(x-v(2))*(x-v(3))
endfunction
u = f3(x1)
//Grado 4
case 4
for i=1:5
v(i)=input('Ingrese los valores X: ')
fv(i)=input('Ingrese los valores Y: ')
end
f0g4=(fv(2)-fv(1))/(v(2)-v(1)) // F[X1,X0]
f1g4=(fv(3)-fv(2))/(v(3)-v(2)) // F[X2,X1]
f2g4=(fv(4)-fv(3))/(v(4)-v(3)) // F[X3,X2]
f3g4=(fv(5)-fv(4))/(v(5)-v(4)) // F[X4,X3]
f4g4=(f1g4-f0g4)/(v(3)-v(1)) // F[X2,X1,X0]
f5g4=(f2g4-f1g4)/(v(4)-v(2)) // F[X3,X2,X1]
f6g4=(f3g4-f2g4)/(v(5)-v(3)) // F[X4,X3,X2]
f7g4=(f5g4-f4g4)/(v(4)-v(1)) // F[X3,X2,X1,X0]
f8g4=(f6g4-f5g4)/(v(5)-v(2)) // F[X4,X3,X2,X1]
f9g4=(f8g4-f7g4)/(v(5)-v(1)) // F[X4,X3,X2,X1,X0]
function y4=f4(x)
y4=fv(1)+f0g4*(x-v(1))+f4g4*(x-v(1))*(x-v(2))+f7g4*(xv(1))*(x-v(2))*(x-v(3))+f9g4*(x-
v(1))*(x-v(2))*(x-v(3))*(x-v(4))
endfunction
u = f4(x1)
end
GRADO 4
Problema 6
6. Ajuste un polinomio de interpolación de Newton de segundo grado para estimar el log
10, con los datos siguientes: a) Interpole entre log 8= 0.9030900 y log 12=1.0791812.
b) Interpole entre log 9=0.9542425 y log 11= 1.0413927. Para cada una de las
X0 8 0.9030900
X1 9 0.9542425 0.0511525
P2(x)=0.9030900+0.051125(x-8)-0.0025258(x-8)(x-9)
=1.0003428
Ev=(1-1.0003428/1)*100=0.03428
CÓDIGO SCILAB:
clc
resp = 'S'
while resp == 'S'
for i=1:3
v(i)=input('Ingrese entre qué valores de X desea interpolar: ')
loga(i)=log10(v(i))
end
f0=(loga(2)-loga(1))/(v(2)-v(1))
f1=(loga(3)-loga(2))/(v(3)-v(2))
f2=(f1-f0)/(v(3)-v(1))
function y=f(x)
y = loga(1)+f0*(x-v(1))+f2*(x-v(1))*(x-v(2))
endfunction
x1=input('Ingrese el valor a conocer: ')
m = f(x1)
Ev = abs(log10(x1)-m)*100/log10(x1)
printf('El valor de Log(%.2f) es %.8f\n',x1,m)
printf('\nEl error relativo porcentual verdadero es %.8f\n',Ev)
resp = input('¿Desea hacer otra interpolación? Ingrese S o N: ','s')
while resp <> 'S' & resp <> 'N'
resp = input('\nIngrese S o N: \n','s')
end
end
Problema 7:
function problema5()
resp='s';
while resp=='s'|resp=='S' // estructura while
printf("\t\t\tINTERPOLACION POLINOMIAL DE LAGRANGE\n")
printf("\n");
n=input("Ingrese el numero de datos:")
x=zeros(n,1);
y=zeros(x);
printf("Introduzca los datos: ")
for i=1:n
x(i)=input("x"+string(i-1)+"=");
y(i)=log(x(i))
printf("y%d=%f",(i-1),y(i));
end
printf("\n");
xint=input("Ingrese el valor a interpolar:");
vv=log(xint);
if x(1)<xint & xint<x(n) then
printf("El valor de x=%0.2f se encuentra dentro del rango de las x, siendo este de:
[%0.2f,%0.2f],\n",xint,x(1),x(n));
elseif x(1)>xint | xint>x(n)
printf("ERROR\n")
printf("x=%0.2f se encuentra fuera del rango de las x\n",xint);
end
printf("\n");
for i=1:n
if x(1)>xint | xint>x(n) then
break
elseif x(i)<xint & xint<x(i+1)
printf("El valor de x=%0.2f se encuentra en el intervalo [%0.2f,%0.2f]\n",xint,x(i),x(i+1));
end
end
//calculo de los factores de interpolacion
//se toma valor inicial 1 porque es un producto
printf("\n");
if x(1)>xint | xint>x(n) then
break
else
printf('\t %s\t\t %s%d%s\t\t %s\t %s\n','x:','P',(n-1),"(x)","Ln(x)","%ERROR")
end
L=ones(x);
for i=1:n
37
for j=1:n
if j<>i then
L(i)=L(i)*(xint-x(j))/(x(i)-x(j));
end
end
end
//calculando el valor a interpolar
suma=0;
for i=1:n
if x(1)>xint | xint>x(n) then
break
else
suma=suma+L(i)*y(i);
end
end
et=((vv-suma)/vv)*100;
if x(1)>xint | xint>x(n) then
printf("No se puede interpolar\n")
break
else
printf('\t%0.2f\t\t%0.6f\t %0.6f\t %0.2f\n',xint,suma,vv,et);
end
printf("\n");
resp=input('Si desea repetir otra opcion del MENU general, precione s/S : ','s');
end//fin del while
endfunction
Codigo Scilab:
Problema 8:
Scilab:
function ocho()
//x0 y x1 son los extremos del intervalo que encierran al valor buscado
F=y0+((V-x0)/(x1-x0))*(y1-y0)
printf('Mediante interpolación lineal se tiene que para una T de 27°C la concentración de O es %3.3f\n',F)
endfunction
function ochob()
x=poly(0,'x')
r=((x-x0)/(x1-x0))
F=0
for i=0:n
if i==0
F=F+f0
elseif i==1
F=F+(f1*r)/factorial(i)
elseif i==2
F=F+((f2*r*(r-1))/factorial(i))
elseif i==3
F=F+((f3*r*(r-1)*(r-2))/factorial(i))
elseif i==4
F=F+((f4*r*(r-1)*(r-2)*(r-3))/factorial(i))
elseif i==5
F=F+((f5*r*(r-1)*(r-2)*(r-3)*(r-4))/factorial(i))
end
end
disp(F)
I=horner(F,V)
endfunction
Tendriamos:
function ochoc()
//x(i-1) y x(i) son los extremos del intervalo que encierran al valor buscado
F=((fx0)*((x1-V)^3)/(6*(x1-x0)))+((fx1)*((V-x0)^3)/(6*(x1-x0)))+((y0/(x1-x0))-((fx0*(x1-
x0))/6))*(x1-V)+((y1/(x1-x0))-((fx1*(x1-x0))/6))*(V-x0)
problema 9
0 0