he añadido una linea de código para calcular la cota de error, pero no se ejecuta:
%--------------------------------------------------
function P = HPoly(x,y,yp)
n = length(x) ;
for k=1:(2*n)
Bx(:,k)=x'.^(k-1) ;
end
Bp(:,1)=zeros(n,1) ;
for k=2:(2*n)
Bp(:,k)=(k-1)*x'.^(k-2) ;
end
P = flip([Bx;Bp]\[y,yp]')';
end
%--------------------------------------------------
function y = f(x)
y = 3*x.*exp(x)-exp(2*x) ;
end
function y = fp(x)
y = 3*exp(x).*(x + 1) - 2*exp(2*x);
end
%--------------------------------------------------
% GRADO 3
%
x = [1, 1.05] ;
y = f(x) ;
yp = fp(x);
xtest = 1.03 ;
%--------------------------------------------------
P = HPoly(x,y,yp) ;
Err3 = polyval(P,xtest) - f(xtest)
function Lagrange_error_bound = max(abs((xtest-x(1))*(xtest-x(2)))*(abs(fp(t))/(2*factorial(3))), abs((xtest-x(1))*(xtest-x(2))*(xtest-x(3)))*(abs(fp(t))/(6*factorial(4))));
end
xb = [1:.001:1.05];
yb = f(xb) ;
H = polyval(P,xb) ;
subplot(2,2,1);plot(xb,yb,"r",xb,H,"g",x,y,"r*")
subplot(2,2,2);plot(xb,H-yb,xtest,Err3,"r*")
%--------------------------------------------------
% GRADO 5
%
x = [1, 1.05, 1.07] ;
y = f(x) ;
yp = fp(x);
xtest = 1.03 ;
%--------------------------------------------------
P = HPoly(x,y,yp) ;
Err5 = polyval(P,xtest) - f(xtest)
xb = [1:.001:1.07];
yb = f(xb) ;
H = polyval(P,xb) ;
subplot(2,2,3);plot(xb,yb,"r",xb,H,"g",x,y,"r*")
subplot(2,2,4);plot(xb,H-yb,xtest,Err5,"r*")
%--------------------------------------------------
:'(