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 via exp from log , better through a temporary variable, write y=xMath.log(x); return y*y; y=xMath.log(x); return y*y; Array is not needed here at all - sercxjo
  • Thanks, I will correct) and on the bill of accuracy you will not prompt? - Andrey2517
  • That seems to have the formula cleverstudents.ru/method_of_parabolas.html - sercxjo
  • should I add? : t = Math.abs ((sum-sum2) / 3); while (t> 0.001); return t; } only why does the answer print 2.8346697378812106E-4? This is normal? - Andrey2517
  • What a strange formula? why while? The number of segments of the partition is given. "The calculation step of the primitive (e-1) / 8" - this is not clear to me, if n = 52, then why divide by 8? - sercxjo pm

1 answer 1

For the simpson method, it is necessary to make an estimate

 Math.Abs(I1 - I2)/15 > eps 

I1 is the result of the previous calculation. I2 is the result of the current count. 15 is taken according to the formula 2 ^ O - 1, where O is the order of complexity, it is 4 in Simpson.