clear clc %----------------------------- Exercise 3.7 -----------------------------------% % Dados x = [1965 1970 1980 1985 1990 1991]; y = [17769 24001 25961 34336 29036 33417]; L62 = Intpol_Lagrange(x,y,1962); S62 = spline(x, y, 1962); L77 = Intpol_Lagrange(x,y,1977); S77 = spline(x, y, 1977); L92 = Intpol_Lagrange(x,y,1992); S92 = spline(x, y, 1992); printf('Ano 1962: \n Lagrange: %d \n Spline: %d \n Valor real: %d \n', L62, S62, 12380) printf('Ano 1977: \n Lagrange: %d \n Spline: %d \n Valor real: %d \n', L77, S77, 27403) printf('Ano 1992: \n Lagrange: %d \n Spline: %d \n Valor real: %d \n', L92, S92, 32059) % Calculos para o plot z =[1962:0.1:1992]; for i = 1:length(z) yl(i) = Intpol_Lagrange(x,y,z(i)); end s3 = spline(x, y, z); figure set(gcf, 'color', [1 1 1]); plot(x,y,'*k',z,yl,'--',z,s3,'-') legend('Dados','Lagrange','Spline')