How to find a definite integral by the Simpson method from 1 to (e) ((x * ln (x)) ^ 2) dx? The number of partitions is 52. The calculation step is primitive (e-1) / 8. accuracy is 0.001 . Rather tell me how you can check it for accuracy? Here is my implementation:
public double f(double x){ return Math.pow(x*Math.log(x), 2); } public double Integral(int n, double a, double b){ double sum=0,sum2=0; double[] x=new double[n]; double h=(ba)/n; for(int i=0;i<n;i++){ x[i]=a+i*h; } for(int i=1;i<n;i++){ sum+=f(x[i]); sum2+=f((x[i-1]+x[i])/2); } return h/6*(f(a)+f(b)+2*sum+4*(sum2+b)); } public static void main(String[] args) { Simpson s=new Simpson(); System.out.println(s.Integral(52,1, Math.E)); }
Math.pow(xMath.log(x), 2)
- do not write so,pow
is considered to be viaexp
fromlog
, better through a temporary variable, writey=xMath.log(x); return y*y;
y=xMath.log(x); return y*y;
Array is not needed here at all - sercxjo