double lebesgue_constant ( int n, double x[], int nfun, double xfun[] ) /******************************************************************************/ /* Purpose: LEBESGUE_CONSTANT estimates the Lebesgue constant for a set of points. Licensing: This code is distributed under the GNU LGPL license. Modified: 03 March 2014 Author: John Burkardt. Parameters: Jean-Paul Berrut, Lloyd Trefethen, Barycentric Lagrange Interpolation, SIAM Review, Volume 46, Number 3, September 2004, pages 501-517. Parameters: Input, int N, the number of interpolation points. Input, double X[N], the interpolation points. Input, int NFUN, the number of evaluation points. Input, double XFUN[NFUN], the evaluation points. Output, double LEBESGUE_CONSTANT, an estimate of the Lebesgue constant for the points. */ { double *lfun; double lmax; lfun = lebesgue_function ( n, x, nfun, xfun ); lmax = r8vec_max ( nfun, lfun ); free ( lfun ); return lmax; }
void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 samples the solution at the initial time. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 January 2015 Author: John Burkardt */ { double a; double d; int n; double *p; const double r8_pi = 3.141592653589793; int seed; double t; double *u; double *v; double *w; double *x; double xyz_hi; double xyz_lo; double *y; double *z; a = r8_pi / 4.0; d = r8_pi / 2.0; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " Estimate the range of velocity and pressure\n" ); printf ( " at the initial time T = 0, in a region that is the\n" ); printf ( " cube centered at (0,0,0) with 'radius' 1.0.\n" ); printf ( " Parameter A = %g\n", a ); printf ( " Parameter D = %g\n", d ); n = 1000; p = ( double * ) malloc ( n * sizeof ( double ) ); u = ( double * ) malloc ( n * sizeof ( double ) ); v = ( double * ) malloc ( n * sizeof ( double ) ); w = ( double * ) malloc ( n * sizeof ( double ) ); xyz_lo = -1.0; xyz_hi = +1.0; seed = 123456789; x = r8vec_uniform_ab_new ( n, xyz_lo, xyz_hi, &seed ); y = r8vec_uniform_ab_new ( n, xyz_lo, xyz_hi, &seed ); z = r8vec_uniform_ab_new ( n, xyz_lo, xyz_hi, &seed ); t = 0.0; uvwp_ethier ( a, d, n, x, y, z, t, u, v, w, p ); printf ( "\n" ); printf ( " Minimum Maximum\n" ); printf ( "\n" ); printf ( " U: %14.6g %14.6g\n", r8vec_min ( n, u ), r8vec_max ( n, u ) ); printf ( " V: %14.6g %14.6g\n", r8vec_min ( n, v ), r8vec_max ( n, v ) ); printf ( " W: %14.6g %14.6g\n", r8vec_min ( n, w ), r8vec_max ( n, w ) ); printf ( " P: %14.6g %14.6g\n", r8vec_min ( n, p ), r8vec_max ( n, p ) ); free ( p ); free ( u ); free ( v ); free ( w ); free ( x ); free ( y ); free ( z ); return; }
void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 tests NACA4_SYMMETRIC. Licensing: This code is distributed under the GNU LGPL license. Modified: 22 May 2014 Author: John Burkardt */ { double c; char command_filename[] = "symmetric_commands.txt"; FILE *command_unit; char data_filename[] = "symmetric_data.txt"; int i; int n = 51; double ratio; double t; double *x; double x_max; double x_min; double *xy; double *y; double y_max; double y_min; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " NACA4_SYMMETRIC evaluates y(x) for a NACA\n" ); printf ( " symmetric airfoil defined by a 4-digit code.\n" ); c = 10.0; t = 0.15; x = r8vec_linspace_new ( n, 0.0, c ); y = naca4_symmetric ( t, c, n, x ); /* Reorganize data into a single object. */ xy = ( double * ) malloc ( 2 * 2 * n * sizeof ( double ) ); for ( i = 0; i < n; i++ ) { xy[0+i*2] = x[i]; xy[1+i*2] = -y[i]; } for ( i = 0; i < n; i++ ) { xy[0+(n+i)*2] = x[n-1-i]; xy[1+(n+i)*2] = y[n-1-i]; } /* Determine size ratio. */ x_min = r8vec_min ( n, x ); x_max = r8vec_max ( n, x ); y_max = r8vec_max ( n, y ); y_min = - y_max; ratio = ( y_max - y_min ) / ( x_max - x_min ); /* Save data to a file. */ r8mat_write ( data_filename, 2, 2 * n, xy ); printf ( " Data saved in file '%s'\n", data_filename ); /* Create the command file. */ command_unit = fopen ( command_filename, "wt" ); fprintf ( command_unit, "set term png\n" ); fprintf ( command_unit, "set grid\n" ); fprintf ( command_unit, "set style data lines\n" ); fprintf ( command_unit, "set size ratio %g\n", ratio ); fprintf ( command_unit, "set timestamp\n" ); fprintf ( command_unit, "unset key\n" ); fprintf ( command_unit, "set output 'symmetric.png'\n" ); fprintf ( command_unit, "set xlabel '<---X--->'\n" ); fprintf ( command_unit, "set ylabel '<---Y--->'\n" ); fprintf ( command_unit, "set title 'NACA Symmetric Airfoil'\n" ); fprintf ( command_unit, "plot '%s' using 1:2 with lines lw 3\n", data_filename ); fprintf ( command_unit, "quit\n" ); fclose ( command_unit ); printf ( " Created command file '%s'\n", command_filename ); free ( x ); free ( y ); return; }
void test02 ( ) /******************************************************************************/ /* Purpose: TEST02 tests NACA4_CAMBERED. Licensing: This code is distributed under the GNU LGPL license. Modified: 21 May 2014 Author: John Burkardt */ { double c; char command_filename[] = "cambered_commands.txt"; FILE *command_unit; char data_filename[] = "cambered_data.txt"; int i; double m; int n = 51; double p; double ratio; double t; double x_max; double x_min; double *xc; double *xl; double *xu; double *xy; double y_max; double y_min; double *yl; double *yu; printf ( "\n" ); printf ( "TEST02\n" ); printf ( " NACA4_CAMBERED evaluates (xu,yu) and (xl,yl) for a NACA\n" ); printf ( " cambered airfoil defined by a 4-digit code.\n" ); m = 0.02; p = 0.4; t = 0.12; c = 10.0; xc = r8vec_linspace_new ( n, 0.0, c ); xu = ( double * ) malloc ( n * sizeof ( double ) ); xl = ( double * ) malloc ( n * sizeof ( double ) ); yu = ( double * ) malloc ( n * sizeof ( double ) ); yl = ( double * ) malloc ( n * sizeof ( double ) ); naca4_cambered ( m, p, t, c, n, xc, xu, yu, xl, yl ); /* Reorganize data into a single object. */ xy = ( double * ) malloc ( 2 * 2 * n * sizeof ( double ) ); for ( i = 0; i < n; i++ ) { xy[0+i*2] = xl[i]; xy[1+i*2] = yl[i]; } for ( i = 0; i < n; i++ ) { xy[0+(n+i)*2] = xu[n-1-i]; xy[1+(n+i)*2] = yu[n-1-i]; } /* Determine size ratio. */ x_min = r8_min ( r8vec_min ( n, xl ), r8vec_min ( n, xu ) ); x_max = r8_max ( r8vec_max ( n, xl ), r8vec_max ( n, xu ) ); y_min = r8_min ( r8vec_min ( n, yl ), r8vec_min ( n, yu ) ); y_max = r8_max ( r8vec_max ( n, yl ), r8vec_max ( n, yu ) ); ratio = ( y_max - y_min ) / ( x_max - x_min ); /* Save data to a file. */ r8mat_write ( data_filename, 2, 2 * n, xy ); printf ( " Data saved in file '%s'\n", data_filename ); /* Create the command file. */ command_unit = fopen ( command_filename, "wt" ); fprintf ( command_unit, "set term png\n" ); fprintf ( command_unit, "set grid\n" ); fprintf ( command_unit, "set style data lines\n" ); fprintf ( command_unit, "set size ratio %g\n", ratio ); fprintf ( command_unit, "set timestamp\n" ); fprintf ( command_unit, "unset key\n" ); fprintf ( command_unit, "set output 'cambered.png'\n" ); fprintf ( command_unit, "set xlabel '<---X--->'\n" ); fprintf ( command_unit, "set ylabel '<---Y--->'\n" ); fprintf ( command_unit, "set title 'NACA Cambered Airfoil'\n" ); fprintf ( command_unit, "plot '%s' using 1:2 with lines lw 3\n", data_filename ); fprintf ( command_unit, "quit\n" ); fclose ( command_unit ); printf ( " Created command file '%s'\n", command_filename ); free ( xc ); free ( xl ); free ( xu ); free ( xy ); free ( yl ); free ( yu ); return; }
void test02 ( void ) /******************************************************************************/ /* Purpose: TEST02 evaluates the objective function at each starting point. Licensing: This code is distributed under the GNU LGPL license. Modified: 17 February 2012 Author: John Burkardt */ { double *a; double *b; double *f; double *fs; int i; int know; int m; int n = 100000; int problem; int problem_num; int seed; char title[100]; double *x; double *xs; printf ( "\n" ); printf ( "TEST02\n" ); printf ( " For each problem, evaluate the function at many points.\n" ); printf ( " Number of sample points = %d\n", n ); /* Get the number of problems. */ problem_num = p00_problem_num ( ); for ( problem = 1; problem <= problem_num; problem++ ) { printf ( "\n" ); printf ( " Problem %d\n", problem ); p00_title ( problem, title ); printf ( " %s\n", title ); m = p00_m ( problem ); printf ( " M = %d\n", m ); a = ( double * ) malloc ( m * sizeof ( double ) ); b = ( double * ) malloc ( m * sizeof ( double ) ); p00_ab ( problem, m, a, b ); printf ( "\n" ); printf ( " I A(i) B(i)\n" ); printf ( "\n" ); for ( i = 0; i < m; i++ ) { printf ( " %4d %10g %10g\n", i, a[i], b[i] ); } seed = 123456789; x = r8col_uniform_new ( m, n, a, b, &seed ); f = p00_f ( problem, m, n, x ); printf ( "\n" ); printf ( " Max(F) = %g\n", r8vec_max ( n, f ) ); printf ( " Min(F) = %g\n", r8vec_min ( n, f ) ); know = 0; xs = p00_sol ( problem, m, &know ); if ( know != 0 ) { fs = p00_f ( problem, m, 1, xs ); printf ( " F(X*) = %g\n", fs[0] ); free ( fs ); free ( xs ); } else { printf ( " X* is not given.\n" ); } free ( a ); free ( b ); free ( f ); free ( x ); } return; }
void uvp_stokes1_test ( ) /******************************************************************************/ /* Purpose: UVP_STOKES1_TEST samples the solution #1. Licensing: This code is distributed under the GNU LGPL license. Modified: 24 January 2015 Author: John Burkardt */ { int n = 1000; double *p; int seed; double *u; double *v; double *x; double xy_hi; double xy_lo; double *y; printf ( "\n" ); printf ( "UVP_STOKES1_TEST\n" ); printf ( " Exact Stokes solution #1:\n" ); printf ( " Estimate the range of velocity and pressure\n" ); printf ( " using a region that is the unit square.\n" ); xy_lo = 0.0; xy_hi = 1.0; seed = 123456789; x = r8vec_uniform_ab_new ( n, xy_lo, xy_hi, &seed ); y = r8vec_uniform_ab_new ( n, xy_lo, xy_hi, &seed ); u = ( double * ) malloc ( n * sizeof ( double ) ); v = ( double * ) malloc ( n * sizeof ( double ) ); p = ( double * ) malloc ( n * sizeof ( double ) ); uvp_stokes1 ( n, x, y, u, v, p ); printf ( "\n" ); printf ( " Minimum Maximum\n" ); printf ( "\n" ); printf ( " U: %14.6g %14.6g\n", r8vec_min ( n, u ), r8vec_max ( n, u ) ); printf ( " V: %14.6g %14.6g\n", r8vec_min ( n, v ), r8vec_max ( n, v ) ); printf ( " P: %14.6g %14.6g\n", r8vec_min ( n, p ), r8vec_max ( n, p ) ); free ( p ); free ( u ); free ( v ); free ( x ); free ( y ); return; }
void xk_contour ( ) /******************************************************************************/ /* Purpose: XK_CONTOUR displays contour plots of a 1D stochastic diffusivity function. Discussion: The diffusivity function is compute by DIFFUSIVITY_1D_XK. Licensing: This code is distributed under the GNU LGPL license. Modified: 06 August 2013 Author: John Burkardt Reference: Dongbin Xiu, George Karniadakis, Modeling uncertainty in steady state diffusion problems via generalized polynomial chaos, Computer Methods in Applied Mechanics and Engineering, Volume 191, 2002, pages 4927-4948. */ { double *dc; double dc_max; double dc0; char command_filename[] = "xk_commands.txt"; FILE *command_unit; char data_filename[] = "xk_data.txt"; FILE *data_unit; int j; int m; int n; int seed; double *omega; double *x; double x_min; double x_max; printf ( "\n" ); printf ( "XK_CONTOUR\n" ); printf ( " Plot the stochastic diffusivity function\n" ); printf ( " defined by DIFFUSIVITY_1D_XK.\n" ); /* Set up the spatial grid. */ n = 51; x_min = -1.0; x_max = +1.0; x = r8vec_linspace_new ( n, x_min, x_max ); /* Sample the OMEGA values. */ m = 5; seed = 123456789; omega = r8vec_normal_01_new ( m, &seed ); /* Compute the diffusivity field. */ dc0 = 10.0; dc = diffusivity_1d_xk ( dc0, m, omega, n, x ); /* Create data file. */ data_unit = fopen ( data_filename, "wt" ); for ( j = 0; j < n; j++ ) { fprintf ( data_unit, " %14.6g %14.6g\n", x[j], dc[j] ); } fclose ( data_unit ); printf ( "\n" ); printf ( " Created graphics data file '%s'\n", data_filename ); /* Create the command file. */ dc_max = r8vec_max ( n, dc ); command_unit = fopen ( command_filename, "wt" ); fprintf ( command_unit, "# %s\n", command_filename ); fprintf ( command_unit, "#\n" ); fprintf ( command_unit, "# Usage:\n" ); fprintf ( command_unit, "# gnuplot < %s\n", command_filename ); fprintf ( command_unit, "#\n" ); fprintf ( command_unit, "set term png\n" ); fprintf ( command_unit, "set output 'xk_contour.png'\n" ); fprintf ( command_unit, "set xlabel '<---X--->'\n" ); fprintf ( command_unit, "set ylabel '<---DC(X)--->'\n" ); fprintf ( command_unit, "set yrange [0.0:%g]\n", dc_max ); fprintf ( command_unit, "set title 'XK Stochastic diffusivity function'\n" ); fprintf ( command_unit, "set grid\n" ); fprintf ( command_unit, "set style data lines\n" ); fprintf ( command_unit, "plot '%s' using 1:2 lw 3 linecolor rgb 'red'\n", data_filename ); fclose ( command_unit ); printf ( " Created graphics command file '%s'\n", command_filename ); free ( dc ); free ( omega ); free ( x ); return; }
void test02 ( void ) /******************************************************************************/ /* Purpose: TEST02 samples each function using each grid. Licensing: This code is distributed under the GNU LGPL license. Modified: 30 January 2012 Author: John Burkardt */ { double *f; double f_ave; double f_max; double f_min; int f_num; int fi; char ft[100]; int g_num; int gi; int gn; char gt[100]; double *gx; double *gy; printf ( "\n" ); printf ( "TEST02\n" ); printf ( " Sample each function over each grid.\n" ); g_num = g00_num ( ); f_num = f00_num ( ); for ( fi = 1; fi <= f_num; fi++ ) { f00_title ( fi, ft ); printf ( "\n" ); printf ( " %2d %s\n", fi, ft ); printf ( " Grid Title " ); printf ( "Min(F) Ave(F) Max(F)\n" ); printf ( "\n" ); for ( gi = 1; gi <= g_num; gi++ ) { g00_title ( gi, gt ); gn = g00_size ( gi ); gx = ( double * ) malloc ( gn * sizeof ( double ) ); gy = ( double * ) malloc ( gn * sizeof ( double ) ); g00_xy ( gi, gn, gx, gy ); f = ( double * ) malloc ( gn * sizeof ( double ) ); f00_f0 ( fi, gn, gx, gy, f ); f_max = r8vec_max ( gn, f ); f_min = r8vec_min ( gn, f ); f_ave = r8vec_sum ( gn, f ); f_ave = f_ave / ( double ) ( gn ); printf ( " %4d %25s %14g %14g %14g\n", gi, gt, f_min, f_ave, f_max ); free ( f ); free ( gx ); free ( gy ); } } return; }
void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 generates a field and estimates its range. Licensing: This code is distributed under the GNU LGPL license. Modified: 19 January 2015 Author: John Burkardt */ { int n; double c; int seed; double *u; double *v; double *x; double xy_hi; double xy_lo; double *y; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " Sample a spiral velocity field and estimate\n" ); printf ( " the range of the solution values.\n" ); n = 1000; xy_lo = +0.0; xy_hi = +1.0; seed = 123456789; x = r8vec_uniform_ab_new ( n, xy_lo, xy_hi, &seed ); y = r8vec_uniform_ab_new ( n, xy_lo, xy_hi, &seed ); c = 1.0; u = ( double * ) malloc ( n * sizeof ( double ) ); v = ( double * ) malloc ( n * sizeof ( double ) ); uv_spiral ( n, x, y, c, u, v ); printf ( "\n" ); printf ( " Minimum Maximum\n" ); printf ( "\n" ); printf ( " U: %14.6g %14.6g\n", r8vec_min ( n, u ), r8vec_max ( n, u ) ); printf ( " V: %14.6g %14.6g\n", r8vec_min ( n, v ), r8vec_max ( n, v ) ); free ( u ); free ( v ); free ( x ); free ( y ); return; }