SHARE
TWEET

Untitled

a guest Dec 6th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.concurrent.Callable;
  2.  
  3.  
  4. public class Calka_Callable implements Callable<Double>{
  5.  
  6.     private double dx;
  7.     private double xp;
  8.     private double xk;
  9.     private int N;
  10.  
  11.     public Calka_Callable(double xp, double xk, double dx) {
  12.         this.xp = xp;
  13.         this.xk = xk;
  14.         this.N = (int) Math.ceil((xk-xp)/dx);
  15.         this.dx = (xk-xp)/N;
  16.         System.out.println("Creating an instance of Calka_callable");
  17.         System.out.println("xp = " + xp + ", xk = " + xk + ", N = " + N);
  18.         System.out.println("dx requested = " + dx + ", dx final = " + this.dx);
  19.  
  20.     }
  21.  
  22.     private double getFunction(double x) {
  23.         return Math.sin(x);
  24.     }
  25.  
  26.     public double compute() {
  27.         double calka = 0;
  28.         int i;
  29.         for(i=0; i<N; i++){
  30.             double x1 = xp+i*dx;
  31.             double x2 = x1+dx;
  32.             calka += ((getFunction(x1) + getFunction(x2))/2.)*dx;
  33.         }
  34.         return calka;
  35.     }
  36.  
  37.     @Override
  38.     public Double call() throws Exception {
  39.         double calka = compute();
  40.         System.out.println("Calka czastkowa: " + calka);
  41.         return calka;
  42.     }
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top