viernes, 17 de febrero de 2017

Linear Interpolation code C# and FORTRAN


With this method any two points are simple joined together by a straight line segment. The desired interpolation point should therefore lie on this same line segment. The next codes calculate single point linear interpolation (xval,yval) using to vectors data (x,y).


You can this code to linear interpolation in FORTRAN

       

SUBROUTINE LinearInterpolation(x,y,xval,yval,n)
  real::x(n),y(n),xval,yval
  integer::n,i
     yval = 0
     do i=1,n
  
   IF (xval >= x(i) .AND. xval < x(i+1)) then   
   
   yval = y(i)+(xval-x(i))*(y(i+1)-y(i))/(x(i+1)-x(i));
 
   end if
      end do
   return
   
      end SUBROUTINE 





This code is to linear interpolation in C#

       

public static double LinearInterpolationkro(double[] x, double[] y, double xval)
        {
            double yval = 0.0;
            for (int i = 0; i < x.Length - 1; i++)
            {
                if (xval >= x[i] && xval < x[i + 1])  
                {
                    yval = y[i] + (xval - x[i]) * (y[i + 1] - y[i]) / (x[i + 1] - x[i]);
                }
            }
            return yval;
        }

No hay comentarios:

Publicar un comentario