# include # include # include # include "fisher_exact.h" int main(); void f_residual_test ( ); void fisher_residual_test ( ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: fisher_exact_test() tests fisher_exact(). Licensing: This code is distributed under the MIT license. Modified: 04 May 2024 Author: John Burkardt */ { double a; double c; double k; printf ( "\n" ); printf ( "fisher_exact_test():\n" ); printf ( " C version\n" ); printf ( " Test fisher_exact(), for exact solutions of Fisher PDE.\n" ); /* Report the current parameter values. */ fisher_parameters ( NULL, NULL, NULL, &a, &c, &k ); printf ( "\n" ); printf ( " parameters:\n" ); printf ( " a = %14.6g\n", a ); printf ( " c = %14.6g\n", c ); printf ( " k = %14.6g\n", k ); f_residual_test ( ); fisher_residual_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "fisher_exact_test():\n" ); printf ( " Normal end of execution.\n" ); timestamp ( ); return 0; } /******************************************************************************/ void f_residual_test ( ) /******************************************************************************/ /* Purpose: f_residual_test() tests f_residual(). Licensing: This code is distributed under the MIT license. Modified: 05 May 2024 Author: John Burkardt */ { double c; double f; double fz; double fzz; int i; int j; double r; double *t; double *x; double z; printf ( "\n" ); printf ( "f_residual_test():\n" ); printf ( " Evaluate F(Z) and residual at selected points Z=X-cT\n" ); x = r8vec_linspace_new ( 6, 0.0, 1.0 ); t = r8vec_linspace_new ( 6, 0.0, 10.0 ); fisher_parameters ( NULL, NULL, NULL, NULL, &c, NULL ); printf ( "\n" ); printf ( " Z F(Z) Resid(Z)\n" ); printf ( "\n" ); for ( j = 0; j < 6; j++ ) { for ( i = 0; i < 6; i++ ) { z = x[i] - c * t[j]; f_exact ( z, &f, &fz, &fzz ); r = f_residual ( f, fz, fzz ); printf ( "%14.6g%14.6g%14.6g\n", z, f, r ); } printf ( "\n" ); } free ( t ); free ( x ); return; } /******************************************************************************/ void fisher_residual_test ( ) /******************************************************************************/ /* Purpose: fisher_residual_test() tests fisher_residual(). Licensing: This code is distributed under the MIT license. Modified: 05 May 2024 Author: John Burkardt */ { int i; int j; double r; double *t; double u; double ut; double ux; double uxx; double *x; printf ( "\n" ); printf ( "fisher_residual_test():\n" ); printf ( " Evaluate solution and residual at selected points (X,T)\n" ); x = r8vec_linspace_new ( 6, 0.0, 1.0 ); t = r8vec_linspace_new ( 6, 0.0, 10.0 ); printf ( "\n" ); printf ( " X T U(X,T) Resid(X,T)\n" ); printf ( "\n" ); for ( j = 0; j < 6; j++ ) { for ( i = 0; i < 6; i++ ) { fisher_exact ( x[i], t[j], &u, &ut, &ux, &uxx ); r = fisher_residual ( x[i], t[j] ); printf ( "%14.6g%14.6g%14.6g%14.6g\n", x[i], t[j], u, r ); } printf ( "\n" ); } free ( t ); free ( x ); return; } /******************************************************************************/ double *r8vec_linspace_new ( int n, double a, double b ) /******************************************************************************/ /* Purpose: r8vec_linspace_new() creates a vector of linearly spaced values. Discussion: An R8VEC is a vector of R8's. 4 points evenly spaced between 0 and 12 will yield 0, 4, 8, 12. In other words, the interval is divided into N-1 even subintervals, and the endpoints of intervals are used as the points. Licensing: This code is distributed under the MIT license. Modified: 29 March 2011 Author: John Burkardt Input: int N, the number of entries in the vector. double A, B, the first and last entries. Output: double R8VEC_LINSPACE_NEW[N], a vector of linearly spaced data. */ { int i; double *x; x = ( double * ) malloc ( n * sizeof ( double ) ); if ( n == 1 ) { x[0] = ( a + b ) / 2.0; } else { for ( i = 0; i < n; i++ ) { x[i] = ( ( double ) ( n - 1 - i ) * a + ( double ) ( i ) * b ) / ( double ) ( n - 1 ); } } return x; } /******************************************************************************/ 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 }