// Example 1.3 // Interpolation of Runge function using splines // // 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 = linspace(-1,1,11); y = 1 ./(1+25*(x .^2)); Y = 1 ./(1+25*(X .^2)); // Cubic spline interpolation ("not_a_knot") dspline = splin(X,Y); yspline = interp(x,X,Y,dspline); // Generate plots plot(x,yspline,"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(["Cubic Spline";"Expected behavior";"Data Points"]); set(gca(),"data_bounds",matrix([-1,1,0,1.2],2,-1)); // Save image to png xs2png(gcf(),"image"+filesep()+"ch1ex3.png");