Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.util.function.Function;
  2. public class integralCalc
  3. {
  4.    public static void main(String[] args)
  5.    {
  6.       double a = 0;
  7.       double b = 3;
  8.       double n = 1000000;
  9.       double increment = ((b - a) / n);
  10.       Function<Double, Double> myFunc = c -> (Math.exp(c) * Math.pow(c, 2));
  11.       double result = 0.0;
  12.       for (double i = 1.0; i <= 1000000; i++)
  13.       {
  14.          result += ((myFunc.apply(i * increment) + myFunc.apply(increment * i - increment)) * (increment / 2));
  15.       }
  16.       System.out.println("Integral Approximation for function: " + result);
  17.    }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement