double *p02_data ( int dim_num, int data_num ) /******************************************************************************/ /* Purpose: P02_DATA returns the data for problem p02. Discussion: Two pairs of identical X values have now been slightly separated. Licensing: This code is distributed under the GNU LGPL license. Modified: 20 July 2012 Author: John Burkardt Parameters: Input, int DIM_NUM, the spatial dimension of the dependent variables. Input, int DATA_NUM, the number of data points. Output, double P02_DATA[DIM_NUM*DATA_NUM], the data. */ { double *p_data; static double p_data_save[2*18] = { 0.00, 0.00, 1.34, 5.00, 5.00, 8.66, 10.00, 10.00, 10.60, 10.40, 10.70, 12.00, 10.705, 28.60, 10.80, 30.20, 11.40, 30.60, 19.60, 30.60, 20.20, 30.20, 20.295, 28.60, 20.30, 12.00, 20.40, 10.40, 21.00, 10.00, 26.00, 8.66, 29.66, 5.00, 31.00, 0.00 }; p_data = r8mat_copy_new ( dim_num, data_num, p_data_save ); return p_data; }
double *gmsh_mesh2d_node_data_example ( int node_num, int node_dim ) /******************************************************************************/ /* Purpose: GMSH_MESH2D_NODE_DATA_EXAMPLE returns the node information for the example. Licensing: This code is distributed under the GNU LGPL license. Modified: 18 October 2014 Author: John Burkardt Parameters: Input, int NODE_NUM, the number of nodes. Input, int NODE_DIM, the spatial dimension. Output, double GMSH_MESH2D_NODE_DATA_EXAMPLE[NODE_DIM*NODE_NUM], the nodal coordinates. */ { double *node_coord; double node_coord_save[2*21] = { 0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 1.0, 3.0, 1.0, 4.0, 1.0, 0.0, 2.0, 1.0, 2.0, 2.0, 2.0, 3.0, 2.0, 4.0, 2.0, 0.0, 3.0, 1.0, 3.0, 2.0, 3.0, 0.0, 4.0, 1.0, 4.0, 2.0, 4.0 }; node_coord = r8mat_copy_new ( 2, 21, node_coord_save ); return node_coord; }
double *p01_data ( int dim_num, int data_num ) /******************************************************************************/ /* Purpose: P01_DATA returns the data for problem p01. Licensing: This code is distributed under the GNU LGPL license. Modified: 06 February 2012 Author: John Burkardt Parameters: Input, int DIM_NUM, the spatial dimension of the dependent variables. Input, int DATA_NUM, the number of data points. Output, double P01_DATA[DIM_NUM*DATA_NUM], the data. */ { double *p_data; static double p_data_save[2*18] = { 0.0, 4.0, 1.0, 5.0, 2.0, 6.0, 4.0, 6.0, 5.0, 5.0, 6.0, 3.0, 7.0, 1.0, 8.0, 1.0, 9.0, 1.0, 10.0, 3.0, 11.0, 4.0, 12.0, 4.0, 13.0, 3.0, 14.0, 3.0, 15.0, 4.0, 16.0, 4.0, 17.0, 3.0, 18.0, 0.0 }; p_data = r8mat_copy_new ( dim_num, data_num, p_data_save ); return p_data; }
double *p08_data ( int dim_num, int data_num ) /******************************************************************************/ /* Purpose: P08_DATA returns the data for problem p08. Licensing: This code is distributed under the GNU LGPL license. Modified: 20 July 2012 Author: John Burkardt Parameters: Input, int DIM_NUM, the spatial dimension of the dependent variables. Input, int DATA_NUM, the number of data points. Output, double P08_DATA[DIM_NUM*DATA_NUM], the data. */ { double *p_data; static double p_data_save[2*12] = { -1.0, 1.00, -0.8, 0.64, -0.6, 0.36, -0.4, 0.16, -0.2, 0.04, 0.0, 0.00, 0.2, 0.04, 0.20001, 0.05, 0.4, 0.16, 0.6, 0.36, 0.8, 0.64, 1.0, 1.00 }; p_data = r8mat_copy_new ( dim_num, data_num, p_data_save ); return p_data; }
double *p05_data ( int dim_num, int data_num ) /******************************************************************************/ /* Purpose: P05_DATA returns the data for problem p05. Licensing: This code is distributed under the GNU LGPL license. Modified: 06 February 2012 Author: John Burkardt Parameters: Input, int DIM_NUM, the spatial dimension of the dependent variables. Input, int DATA_NUM, the number of data points. Output, double P05_DATA[DIM_NUM*DATA_NUM], the data. */ { double *p_data; static double p_data_save[2*9] = { 0.00, 0.00, 0.10, 0.90, 0.20, 0.95, 0.30, 0.90, 0.40, 0.10, 0.50, 0.05, 0.60, 0.05, 0.80, 0.20, 1.00, 1.00 }; p_data = r8mat_copy_new ( dim_num, data_num, p_data_save ); return p_data; }
double *qr_solve ( int m, int n, double a[], double b[] ) /******************************************************************************/ /* Purpose: QR_SOLVE solves a linear system in the least squares sense. Discussion: If the matrix A has full column rank, then the solution X should be the unique vector that minimizes the Euclidean norm of the residual. If the matrix A does not have full column rank, then the solution is not unique; the vector X will minimize the residual norm, but so will various other vectors. Licensing: This code is distributed under the GNU LGPL license. Modified: 11 September 2012 Author: John Burkardt Reference: David Kahaner, Cleve Moler, Steven Nash, Numerical Methods and Software, Prentice Hall, 1989, ISBN: 0-13-627258-4, LC: TA345.K34. Parameters: Input, int M, the number of rows of A. Input, int N, the number of columns of A. Input, double A[M*N], the matrix. Input, double B[M], the right hand side. Output, double QR_SOLVE[N], the least squares solution. */ { double *a_qr; int ind; int itask; int *jpvt; int kr; int lda; double *qraux; double *r; double tol; double *x; a_qr = r8mat_copy_new ( m, n, a ); lda = m; tol = r8_epsilon ( ) / r8mat_amax ( m, n, a_qr ); x = ( double * ) malloc ( n * sizeof ( double ) ); jpvt = ( int * ) malloc ( n * sizeof ( int ) ); qraux = ( double * ) malloc ( n * sizeof ( double ) ); r = ( double * ) malloc ( m * sizeof ( double ) ); itask = 1; ind = dqrls ( a_qr, lda, m, n, tol, &kr, b, x, r, jpvt, qraux, itask ); free ( a_qr ); free ( jpvt ); free ( qraux ); free ( r ); return x; }
void rbf_interp_nd_test01 ( void ) /******************************************************************************/ /* Purpose: RBF_INTERP_ND_TEST01 tests RBF_WEIGHTS and RBF_INTERP_ND with PHI1. Licensing: This code is distributed under the GNU LGPL license. Modified: 01 July 2012 Author: John Burkardt */ { double a; double app_error; double b; int debug = 0; double *fd; double *fe; double *fi; int i; double int_error; int j; int m = 2; int n1d = 5; int nd; int ni; double r0; int seed; double *w; double *x1d; double *xd; double *xi; printf ( "\n" ); printf ( "RBF_INTERP_ND_TEST01:\n" ); printf ( " RBF_WEIGHT computes weights for RBF interpolation.\n" ); printf ( " RBF_INTERP_ND evaluates the RBF interpolant.\n" ); printf ( " Use the multiquadratic basis function PHI1(R).\n" ); a = 0.0; b = 2.0; r0 = ( b - a ) / ( double ) ( n1d ); printf ( " Scale factor R0 = %g\n", r0 ); x1d = r8vec_linspace_new ( n1d, a, b ); nd = i4_power ( n1d, m ); xd = ( double * ) malloc ( m * nd * sizeof ( double ) ); for ( i = 0; i < m; i++ ) { r8vec_direct_product ( i, n1d, x1d, m, nd, xd ); } if ( debug ) { r8mat_transpose_print ( m, nd, xd, " The product points:" ); } fd = ( double * ) malloc ( nd * sizeof ( double ) ); for ( j = 0; j < nd; j++ ) { fd[j] = xd[0+j*m] * xd[1+j*m] * exp ( - xd[0+j*m] * xd[1+j*m] ); } if ( debug ) { r8vec_print ( nd, fd, " Function data:" ); } w = rbf_weight ( m, nd, xd, r0, phi1, fd ); if ( debug ) { r8vec_print ( nd, w, " Weight vector:" ); } /* #1: Interpolation test. Does interpolant match function at interpolation points? */ ni = nd; xi = r8mat_copy_new ( m, ni, xd ); fi = rbf_interp_nd ( m, nd, xd, r0, phi1, w, ni, xi ); int_error = r8vec_norm_affine ( nd, fd, fi ) / ( double ) ( nd ); printf ( "\n" ); printf ( " L2 interpolation error averaged per interpolant node = %g\n", int_error ); free ( fi ); free ( xi ); /* #2: Approximation test. Estimate the integral (f-interp(f))^2. */ ni = 1000; seed = 123456789; xi = r8mat_uniform_ab_new ( m, ni, a, b, &seed ); fi = rbf_interp_nd ( m, nd, xd, r0, phi1, w, ni, xi ); fe = ( double * ) malloc ( ni * sizeof ( double ) ); for ( j = 0; j < ni; j++ ) { fe[j] = xi[0+j*m] * xi[1+j*m] * exp ( - xi[0+j*m] * xi[1+j*m] ); } app_error = pow ( b - a, m ) * r8vec_norm_affine ( ni, fi, fe ) / ( double ) ( ni ); printf ( " L2 approximation error averaged per 1000 samples = %g\n", app_error ); free ( fd ); free ( fe ); free ( fi ); free ( w ); free ( x1d ); free ( xd ); free ( xi ); return; }
double *p06_data ( int dim_num, int data_num ) /******************************************************************************/ /* Purpose: P06_DATA returns the data for problem p06. Licensing: This code is distributed under the GNU LGPL license. Modified: 06 February 2012 Author: John Burkardt Parameters: Input, int DIM_NUM, the spatial dimension of the dependent variables. Input, int DATA_NUM, the number of data points. Output, double P06_DATA[DIM_NUM*DATA_NUM], the data. */ { double *p_data; static double p_data_save[2*49] = { 595.0, 0.644, 605.0, 0.622, 615.0, 0.638, 625.0, 0.649, 635.0, 0.652, 645.0, 0.639, 655.0, 0.646, 665.0, 0.657, 675.0, 0.652, 685.0, 0.655, 695.0, 0.644, 705.0, 0.663, 715.0, 0.663, 725.0, 0.668, 735.0, 0.676, 745.0, 0.676, 755.0, 0.686, 765.0, 0.679, 775.0, 0.678, 785.0, 0.683, 795.0, 0.694, 805.0, 0.699, 815.0, 0.710, 825.0, 0.730, 835.0, 0.763, 845.0, 0.812, 855.0, 0.907, 865.0, 1.044, 875.0, 1.336, 885.0, 1.881, 895.0, 2.169, 905.0, 2.075, 915.0, 1.598, 925.0, 1.211, 935.0, 0.916, 945.0, 0.746, 955.0, 0.672, 965.0, 0.627, 975.0, 0.615, 985.0, 0.607, 995.0, 0.606, 1005.0, 0.609, 1015.0, 0.603, 1025.0, 0.601, 1035.0, 0.603, 1045.0, 0.601, 1055.0, 0.611, 1065.0, 0.601, 1075.0, 0.608 }; p_data = r8mat_copy_new ( dim_num, data_num, p_data_save ); return p_data; }