mrAnderson33

Интерполяция методом Лангранжа

Nov 19th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.lang.Math; // headers MUST be above the first class
  2.  
  3. // one class needs to have a main() method
  4. public class HelloWorld
  5. {
  6.   // arguments are passed using the text field below this editor
  7.   public static void main(String[] args)
  8.   {
  9.      int size = 4;
  10.    
  11.     double [] x =  { 0.6, 0.65, 0.7, 0.75};
  12.     double [] y = {0.56464, 0.60519, 0.64422,0.68164};
  13.     double xn = 0.64;
  14.     double yn = 0;
  15.    
  16.     for (int i =0; i<size; ++i)
  17.     {
  18.       double temp = 1;
  19.       for(int j = 0; j < size; ++j )
  20.         if( j!=i) temp*=(xn-x[j])/(x[i]-x[j]);
  21.       yn += temp * y[i];
  22.     }
  23.    
  24.     System.out.println(yn);
  25.     System.out.println(Math.sin(xn));
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment