# include # include # include # include # include "ppc_gauss_quad.h" int main ( ); void demo1 ( ); void demo2 ( ); double f ( double x ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: ppc_gauss_quad_test() tests ppc_gauss_quad(). Licensing: This code is distributed under the MIT license. Modified: 19 May 2024 Author: John Burkardt. Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 */ { timestamp ( ); printf ( "\n" ); printf ( "ppc_gauss_quad_test():\n" ); printf ( " C version\n" ); printf ( " Test ppc_gauss_quad():\n" ); demo1 ( ); demo2 ( ); /* Terminate. */ printf ( "\n" ); printf ( "ppc_gauss_quad_test():\n" ); printf ( " Normal end of execution.\n" ); timestamp ( ); return 0; } /******************************************************************************/ void demo1 ( ) /******************************************************************************/ /* Purpose: demo1() retrieves and prints the points and weights. Licensing: This code is distributed under the MIT license. Modified: 19 May 2024 Author: John Burkardt. Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 */ { struct Gauss_qdat *gqdat; int i; int n; printf ( "\n" ); printf ( "demo1():\n" ); printf ( " Request a 10 point quadrature rule.\n" ); printf ( " Print the points and weights.\n" ); n = 10; gqdat = gauss_qdat ( &n ); printf ( "\n" ); printf ( " Weight Point\n" ); printf ( "\n" ); for ( i = 0; i < n; i++ ) { printf ( " %10.4f %10.4f\n", gqdat[i].w, gqdat[i].p ); } return; } /******************************************************************************/ void demo2 ( ) /******************************************************************************/ /* Purpose: demo2() estimates an integral over [-1,+1]. Licensing: This code is distributed under the MIT license. Modified: 19 May 2024 Author: John Burkardt. Reference: Rouben Rostamian, Programming Projects in C for Students of Engineering, Science, and Mathematics, SIAM, 2014, ISBN: 978-1-611973-49-5 */ { double e; double exact = 1.9922524079504000171; struct Gauss_qdat *gqdat; int i; int n; double s; printf ( "\n" ); printf ( "demo2():\n" ); printf ( " Estimate an integral with a sequence of rules.\n" ); printf ( "\n" ); printf ( " N Estimate Error\n" ); printf ( "\n" ); for ( n = 1; n <= 10; n++ ) { gqdat = gauss_qdat ( &n ); s = 0.0; for ( i = 0; i < n; i++ ) { s = s + gqdat[i].w * f ( gqdat[i].p ); } e = fabs ( s - exact ); printf ( " %2d %16.8f %16.8f\n", n, s, e ); } return; } /******************************************************************************/ double f ( double x ) /******************************************************************************/ { double value; value = 1.0 / ( pow ( x, 6 ) + 0.9 ); return value; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 01 May 2021 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }