// Example 1.2 // Lagrange Polynomial Interpolation of Runge Function // // Interpolation of the Runge function using // 11 NON equally spaced points on [-1,1] // (data points are more finely spaced near ends) // // Author: Manolo Venturin // http://www.openeering.com // This code is released under a Creative Commons // Attribution - NonCommercial - NoDerivs 3.0 Unported License. // // Adapted to Scilab from the MATLABŪ examples presented // in Prof. Parviz Moin book // "Fundamentals of Engineering Numerical Analysis" // available at http://numerics.stanford.edu/ // Close all opened figures and clear workspace xdel(winsid()); clear; clc; // Import funciton exec("lagrange_interp.sci",-1); // set floating point exception mode ieee(2); // Define Vectors x = linspace(-1,1,201); X = [-1,-0.95,-0.81,-0.59,-0.31,0,0.31,0.59,0.81,0.95,1]; y = 1 ./(1+25*(x .^2)); Y = 1 ./(1+25*(X .^2)); // Lagrange Interpolation pol = lagrange_interp(X,Y,x); // Generate plots plot(x,pol,"r", x,y,"k--", X,Y,"b."); xlabel("$x$","fontsize",4,"color","blue"); ylabel("$y$","fontsize",4,"color","blue"); title("Runge function","fontsize",5,"color","red"); xstring(-0.8,0.8,"$f(x) = \frac{1}{1+25 x^2}$"); e = gce(); e.font_size = 4; legend(["Lagrange Polynomial";"Expected behavior";"Data Points"]); set(gca(),"data_bounds",matrix([-1,1,-0.05,1.2],2,-1)); // Save image to png xs2png(gcf(),"image"+filesep()+"ch1ex2.png");