Numerical calculation, using trapezoidal method and Parabola method to calculate pi

Source: Internet
Author: User
Tags array arrays

Formula pai=4*∫10dx/(1+X2)

The [0.1] is divided into 10 equal parts, which are calculated separately by two methods.

=======================================================

Class Work2 {public static void main (String args[]) {Double h = 0.1;//parameter H double m1 = 0;//complex trapezoid sum sum double n = 10;   Double i=0;//final result double h_2 = 0.2; Double m = 5;//Because of n=2m.n=10, so m=5 double s1=0;//parabolic first array summation double s2=0;//complex parabola second array summation double ss[] = new DOUBLE[10] The sum element in the calculation of the trapezoid formula double ss1[]=new The first array used in the double[5];//parabolic line double ss2[]=new double[4];//second array used in the complex parabola

Double K[]={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};//10 [0,1] for (int i=0;i<10;i++) {Ss[i] = 1/(1+k[i]*k[i));     }//teat pass for (int i =0;i<10;i++) {m1 = M1 +ss[i]; //test Pass I = h_2* (0.5+2*M1);//0.5 is f (b)

--------------------Test Code System.out.println ("= = = Complex Trapezoid formula calculation (including test and results) = =");     System.out.println ("The single result of the complex trapezoid formula"); for (int i =0;i<10;i++) {System.out.println (ss[i]);

    }     System.out.println ("Result sum M is" + M1);     SYSTEM.OUT.PRINTLN ("The result is" + I);     System.out.println ("=================================="); / ------------------------------------------------    //== start the complex parabolic formula calculation ======      System.out.println ("Complex parabola formula calculation");    //Because the operation of the array of parabolic operations is more complex, I redefine arrays k[]      double k_2[] = {0,0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};    // So the array k corresponds to the actual, oh haha           for (int i =1;i<=m;i++) {       int n1 = 2*i-1;      ss1[i-1] = 1/(1+K_2[N1]*K_2[N1));     & nbsp;      system.out.println (ss1[i-1])//test calculation is correct,    }      System.out.println ("correct operation");     System.out.println ("second array calculation"); &NBSP;&NBsp;   for (int i = 1;i<= (m-1), i++) {      int n1 = 2*i;     & NBSP;SS2[I-1]=1/(1+k_2[n1]*k_2[n1]);      system.out.println (ss2[i-1));//test calculation is correct,     }     System.out.println ("correct operation");    //sum of 2 arrays      for (int i =0;i<5;i++) {        S1 = S1 +ss1[i];      }     System.out.println ("Ss1 sum is" + S1);     for ( int i =0;i<4;i++) {        s2 = s2 +ss2[i];     }      System.out.println ("Ss2 sum is" + s2);     System.out.println ("correct operation");      i = (H/3) * (1+0.5+4*S1+2*S2);     System.out.println ("result is" + i);     //Parabolic method do not know is not correct, the book has no answer          } &nbsP } ===========================================


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.