Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. public class Simpson {
  2.  
  3.     double Res = 0, Resc = 0, Resn = 0;
  4.  
  5.     public Simpson(double a, double b, float n){
  6.         double h = (b - a) / n;
  7.         Resc = f(a + h);
  8.         for (int i = 2; i < n; i += 2)
  9.         {
  10.             Resc += f(a + (i + 1) * h);
  11.             Resn += f(a + i * h);
  12.         }
  13.         Res = f(a) + 4 * Resc + 2 * Resn  + f(b);
  14.         Res = Res*h / 3;
  15.  
  16.         System.out.println("Значение интеграла " + Res);
  17.     }
  18.  
  19.     public static double f(double xn) {
  20.         return xn * Math.sin(xn);
  21.     }
  22.  
  23.     public static void main (String[]args){
  24.         Simpson L1 = new Simpson(0, 1.6, 6);
  25.         Simpson L2 = new Simpson(0, 1.6, 12);
  26.         Simpson L3 = new Simpson(0, 1.6, 60);
  27.         Simpson L4 = new Simpson(0, 1.6, 600);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement