package 高数;
import java.util.*;
public class DefiniteIntegralApp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入积分上下限:");
double a = input.nextDouble();
double b = input.nextDouble();
double sum = 0;
double e = cha(a, b, 10000.0);
for (int j = 1; j <= 10000; j++) {
double x = zhongjian(a, b, 10000.0, j);
sum = sum + f(x);
}
System.out.print("f(x)=2*x*x+x的定积分:");
System.out.println(sum * e);
}
public static double f(double x) {
return 2*x*x+x;
}
public static double zhongjian(double a, double b, double n, int i) {
return a + i * (b - a) / n;
}
public static double cha(double a, double b, double n) {
return (b - a) / n;
}
}
例子:计算分f(x)=2*x*x+x的定积分: