Documentos de Académico
Documentos de Profesional
Documentos de Cultura
% ***************************************************************
% ** Interpolacion Lineal **
% ** Programación y Métodos Numéricos **
% ***************************************************************
a=input('Ingrese valor del primer punto: ');
f(a)=input('Ingrese f(x) para el primer punto: ');
b=input('Ingrese el valor del segundo punto: ');
f(b)=input('Ingrese f(x) para el segundo punto: ');
x=input('Ingrese el punto a ser interpolado: ');
G = [((b-x)/(b-a))*f(a) + ((x-a)/(b-a))*f(b)];
disp(G)
Interpolación Lagrange
% ***************************************************************
% ** Interpolacion de Lagrange **
% ** Programación y Métodos Numéricos **
% ***************************************************************
x=input('Ingrese el valor a interpolar:');
N=input('Ingrese el numero de puntos:');
vx=input('Ingrese los valores correspondientes a x:');
vf=input('Ingrese los valores correspondientes f(x):');
g(x)=0;
p=1;
q=1;
for i=1:N
fN=vf(i);
for j=1:N;
p=p*(x-vx(j));
vxi=vx(i);
vxj=vx(j);
if i==j
p=p/(x-vx(j));
vxi=2;
vxj=1;
end
q=q*(vxi-vxj);
end
c=(p/q)*fN;
p=1;
q=1;
g(x)=g(x)+c;
end
disp(g(x))
Interpolacion Newton
% ***************************************************************
% ** Interpolacion de Newton **
% ** Programación y Métodos Numéricos **
% ***************************************************************
Biseccion
Falsa pocision
% ***************************************************************
% ** Método de la falsa Posición **
% ** Programación y Métodos Numéricos **
% ***************************************************************
syms x
y1=input('Ingrese la funcion: ');
a=input('Ingrese el límite inferior: ');
c=input('Ingrese el límite superior: ');
E=input('Ingrese la tolerancia E = ');
y=inline(y1);
if y(a)*y(c)>0
fprintf('\n No existe raíz en este intervalo,');
fprintf('\n intentelo nuevamente con un intervalo diferente\n');
return
end
n=ceil(log((c-a)/E)/log(2));
fprintf('\n Número de iteraciones: n = %2.0f\n',n)
for i= 1:n
b=((a*y(c))-(c*y(a)))/(y(c)-y(a));
fprintf(' n = %2.0f x = %5.4f\n',i,b)
if y(a)*y(b)<0
c=b;
else
a=b;
end
end
Newton Raphson
% ***************************************************************
% ** %Newton Raphson **
% ** Programación y Métodos Numéricos **
% ***************************************************************
x0=input('Ingrese el valor inicial: ');
tol=input('Ingrese el porcentaje de error: ');
f=input('Ingrese la función: ');
i=1;
fx(i)=x0;
syms x;
f1=subs(f,x,fx(i));
z=diff(f);
d=subs(z,x,fx(i));
ea(1)=100;
while abs(ea(i))>=tol;
fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); d=subs(z,x,fx(i+1));
ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100);
i=i+1;
end
fprintf('i fx(i) Error aprox (i) \n');
for j=1:i;
fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j));
end
Secante
% ***************************************************************
% ** Método de la Secante **
% ** Programación y Métodos Numéricos **
% ***************************************************************
syms x
y1=input('Ingrese la funcio: f(x) = ','s');
x0=input('Ingrese el valor inicial aproximado x0 = ');
x1=input('Ingrese el valor inicial aproximado x1 = ');
n=input('Ingrese el numero de iteraciones n = ');
fprintf('\n')
for i=1:n;
y=inline(y1);
a=(x1-x0)./(y(x1)-y(x0));
x2=x1-(y(x1).*a);
x0=x1;
x1=x2;
fprintf(' n = %2.0f x = %6.4f\n',i,x2)
end
% ***************************************************************
% ** %trapecio extendido **
% ** Programación y Métodos Numéricos **
% ***************************************************************
clc
clear
f='x^2+3*x+4';% f funcion
a=2;% a,b intevalo
b=-2;% a,b intevalo
n=8;% n numero partes
disp('Funcion: ');
f
disp(strcat('De [a: ',num2str(a),'Hacia b : ',num2str(b),']'));
f=inline(f);
h=(b-a)/n;
aprox=f(a)+f(b);
for i=1:n-1
x=a+i*h;
aprox=aprox+2*f(x);
end
aprox=(h/2)*aprox;a=0;
disp(aprox)