NAG Library Function Document nag_2d_spline_eval (e02dec)

Similar documents
NAG Library Function Document nag_2d_spline_eval (e02dec)

NAG Library Function Document nag_2d_spline_eval_rect (e02dfc)

NAG Library Function Document nag_1d_spline_interpolant (e01bac)

NAG Library Function Document nag_corr_cov (g02bxc)

nag 2d spline eval rect (e02dfc)

NAG Library Function Document nag_kruskal_wallis_test (g08afc)

NAG Library Function Document nag_1d_spline_evaluate (e02bbc)

NAG Library Function Document nag_mv_distance_mat (g03eac)

NAG Library Function Document nag_prob_lin_non_central_chi_sq (g01jcc)

NAG Library Function Document nag_1d_cheb_fit_constr (e02agc)

NAG Library Function Document nag_smooth_spline_fit (g10abc)

NAG Library Function Document nag_real_cholesky_skyline_solve (f04mcc)

NAG Library Function Document nag_partial_corr (g02byc)

NAG Library Function Document nag_1d_spline_deriv (e02bcc)

NAG Library Function Document nag_mv_ordinal_multidimscale (g03fcc)

NAG Library Function Document nag_all_regsn (g02eac)

NAG Library Function Document nag_1d_spline_fit_knots (e02bac)

NAG Library Function Document nag_dtr_load (f16qgc)

NAG Library Function Document nag_2d_spline_deriv_rect (e02dhc)

NAG Library Function Document nag_3d_shep_interp (e01tgc)

NAG Library Function Document nag_dummy_vars (g04eac)

NAG Library Function Document nag_dtrmv (f16pfc)

NAG Library Function Document nag_mv_discrim (g03dac)

NAG Library Function Document nag_dsymv (f16pcc)

NAG Library Function Document nag_asian_geom_price (s30sac)

NAG Library Function Document nag_tsa_cross_spectrum_bivar (g13cec)

NAG Library Function Document nag_zeros_complex_poly (c02afc)

NAG Library Function Document nag_2_sample_ks_test (g08cdc)

NAG Library Function Document nag_mv_cluster_indicator (g03ejc)

NAG Library Function Document nag_1d_cheb_intg (e02ajc)

NAG Library Function Document nag_glm_tran_model (g02gkc)

NAG Library Function Document nag_2d_panel_sort (e02zac)

NAG Library Function Document nag_dgetri (f07ajc)

NAG Library Function Document nag_dtrsyl (f08qhc)

NAG Library Function Document nag_dgglse (f08zac)

NAG Library Function Document nag_tsa_multi_part_lag_corr (g13dnc)

NAG Library Function Document nag_zero_nonlin_eqns_deriv_1 (c05ubc)

NAG Library Function Document nag_superlu_diagnostic_lu (f11mmc)

NAG Library Function Document nag_opt_one_var_deriv (e04bbc)

NAG Library Function Document nag_mesh2d_inc (d06aac)

NAG Library Function Document nag_1d_spline_fit (e02bec)

NAG Library Function Document nag_zhpr2 (f16ssc)

NAG Library Function Document nag_rngs_varma_time_series (g05pcc)

NAG Library Function Document nag_real_sym_posdef_tridiag_lin_solve (f04bgc)

NAG Library Function Document nag_anova_random (g04bbc)

NAG Library Function Document nag_rgsn_matrix_multi_normal (g05lyc)

NAG Library Routine Document E02DFF.1

NAG Library Function Document nag_herm_posdef_tridiag_lin_solve (f04cgc)

NAG Library Function Document nag_rand_2_way_table (g05pzc)

NAG Library Function Document nag_asian_geom_greeks (s30sbc)

NAG Library Function Document nag_rngs_copula_students_t (g05rbc)

NAG Library Function Document nag_complex_gen_lin_solve (f04cac)

NAG Library Function Document nag_dsytrf (f07mdc)

NAG Library Function Document nag_ztbcon (f07vuc)

NAG Library Function Document nag_bsm_greeks (s30abc)

NAG Library Function Document nag_rand_arma (g05phc)

NAG Library Function Document nag_dpbtrf (f07hdc)

NAG Library Function Document nag_zero_cont_func_brent_rcomm (c05azc)

NAG Library Function Document nag_real_symm_sparse_eigensystem_init (f12fac)

NAG Library Function Document nag_1d_quad_wt_alglog (d01apc)

NAG Library Function Document nag_rand_copula_clayton (g05rhc)

NAG Library Function Document nag_tsa_transf_filter (g13bbc)

NAG Library Function Document nag_friedman_test (g08aec)

NAG Library Function Document nag_1d_quad_wt_alglog_1 (d01spc)

NAG Library Function Document nag_complex_tridiag_lin_solve (f04ccc)

NAG Library Function Document nag_rand_bivariate_copula_frank (g05rfc)

NAG Library Function Document nag_real_symm_sparse_eigensystem_sol (f12fcc)

NAG C Library Function Document nag_binary_factor_service (g11sbc)

NAG Library Function Document nag_ode_bvp_fd_nonlin_fixedbc (d02gac)

NAG Library Function Document nag_regress_confid_interval (g02cbc)

NAG Library Function Document nag_ode_bvp_fd_lin_gen (d02gbc)

NAG Library Function Document nag_corr_cov (g02bxc)

NAG Library Function Document nag_opt_check_deriv (e04hcc)

NAG Library Function Document nag_5d_shep_eval (e01tnc)

NAG Library Function Document nag_pde_parab_1d_euler_exact (d03pxc)

NAG Library Function Document nag_durbin_watson_stat (g02fcc)

NAG Library Function Document nag_kruskal_wallis_test (g08afc)

NAG Library Function Document nag_stable_sort (m01ctc)

NAG Library Function Document nag_complex_bessel_j (s17dec)

nag 1d spline deriv (e02bcc)

NAG Library Function Document nag_search_vector (m01fsc)

NAG Library Function Document nag_prob_durbin_watson (g01epc)

NAG Library Function Document nag_tsa_varma_diagnostic (g13dsc)

NAG Library Function Document nag_summary_stats_onevar_combine (g01auc)

NAG Library Function Document nag_complex_bessel_i (s18dec)

NAG C Library Function Document nag_linf_fit (e02gcc)

NAG Library Function Document nag_smooth_spline_fit (g10abc)

NAG Library Function Document nag_quad_md_gauss (d01fbc)

NAG Library Function Document nag_sum_sqs_update (g02btc)

NAG Library Function Document nag_nd_shep_eval (e01znc)

NAG Library Function Document nag_complex_bessel_y (s17dcc)

NAG Library Function Document nag_dger (f16pmc)

NAG C Library Function Document nag_kruskal_wallis_test (g08afc)

NAG Library Function Document nag_tsa_dickey_fuller_unit (g13awc)

NAG Library Function Document nag_frequency_table (g01aec)

NAG Library Function Document nag_wfilt (c09aac)

NAG Library Function Document nag_zaxpby (f16gcc)

NAG Library Function Document nag_dummy_vars (g04eac)

NAG C Library Function Document nag_cp_stat (g02ecc)

NAG Library Function Document nag_4d_shep_eval (e01tlc)

Transcription:

1 Purpose NAG Library Function Document nag_2d_spline_eval () nag_2d_spline_eval () calculates values of a bicubic spline from its B-spline representation. 2 Specification #include <nag.h> #include <nage02.h> void nag_2d_spline_eval (Integer m, const double x[], const double y[], double ff[], Nag_2dSpline *spline, NagError *fail) 3 Description nag_2d_spline_eval () calculates values of the bicubic spline sx;y ð Þ at prescribed points ðx r ;y r Þ, for r ¼ 1; 2;...;m, from its augmented knot sets fg and fg and from the coefficients c ij, for i ¼ 1; 2;...; spline! nx 4 and j ¼ 1; 2;...; spline! ny 4, in its B-spline representation sx;y ð Þ ¼ X i;j c ij M i ðxþn j ðþ. y Here M i ðxþ and N j ðþdenote y normalized cubic B-splines, the former defined on the knots i to iþ4 and the latter on the knots j to jþ4. This function may be used to calculate values of a bicubic spline given in the form produced by nag_2d_spline_interpolant (e01dac), nag_2d_spline_fit_grid (e02dcc) and nag_2d_spline_fit_scat (e02ddc). It is derived from the routine B2VRE in Anthony et al. (1982). 4 References Anthony G T, Cox M G and Hayes J G (1982) DASL Data Approximation Subroutine Library National Physical Laboratory Cox M G (1978) The numerical evaluation of a spline from its B-spline representation J. Inst. Math. Appl. 21 135 143 5 Arguments 1: m Integer On entry: m, the number of points at which values of the spline are required. Constraint: m 1. 2: x½mš const double 3: y½mš const double On entry: x and y must contain x r and y r, for r ¼ 1; 2;...;m, respectively. These are the coordinates of the points at which values of the spline are required. The order of the points is immaterial. Constraint: x and y must satisfy spline! lamda½3š x½r 1Š spline! lamda½spline! nx 4Š and spline! mu½3š y½r 1Š spline! mu½spline! ny 4Š, for r ¼ 1; 2;...;m. The spline representation is not valid outside these intervals.1

NAG Library Manual 4: ff½mš double Output On exit: ff½r 1Š contains the value of the spline at the point ðx r ;y r Þ, for r ¼ 1; 2;...;m. 5: spline Nag_2dSpline Pointer to structure of type Nag_2dSpline with the following members: nx Integer On entry: nx must specify the total number of knots associated with the variables x. such that nx 8 is the number of interior knots. Constraint: nx 8. It is lamda double On entry: a pointer to which memory of size nx must be allocated. lamda must contain the complete sets of knots fg associated with the x variable. Constraint: the knots must be in non-decreasing order, with lamda½nx 4Š > lamda½3š. ny Integer On entry: ny must specify the total number of knots associated with the variable y. It is such that ny 8 is the number of interior knots. Constraint: ny 8. mu double On entry: a pointer to which memory of size ny must be allocated. mu must contain the complete sets of knots fg associated with the y variable. Constraint: the knots must be in non-decreasing order, with mu½ny 4Š > mu½3š. c double On entry: a pointer to which memory of size ðnx 4Þðny 4Þ must be allocated. c½ðny 4Þði 1Þþj 1Š must contain the coefficient c ij described in Section 3, for i ¼ 1; 2;...; nx 4 and j ¼ 1; 2;...; ny 4. In normal usage, the call to nag_2d_spline_eval () follows a call to nag_2d_spline_interpolant (e01dac), nag_2d_spline_fit_grid (e02dcc) or nag_2d_spline_fit_scat (e02ddc), in which case, members of the structure spline will have been set up correctly for input to nag_2d_spline_eval (). 6: fail NagError * /Output The NAG error argument (see Section 3.6 in the Essential Introduction). 6 Error Indicators and Warnings NE_ALLOC_FAIL Dynamic memory allocation failed. NE_END_KNOTS_CONS On entry, the end knots must satisfy hvaluei, hvaluei ¼ hvaluei, hvaluei ¼ hvaluei. NE_INT_ARG_LT On entry, m ¼ hvaluei. Constraint: m 1..2

On entry, spline! nx must not be less than 8: spline! nx ¼ hvaluei. On entry, spline! ny must not be less than 8: spline! ny ¼ hvaluei. NE_NOT_INCREASING The sequence spline! lamda is not increasing: spline! lamda½hvalueiš ¼ hvaluei, spline! lamda½hvalueiš ¼ hvaluei. The sequence spline! mu is not increasing: spline! mu½hvalueiš ¼ hvaluei, spline! mu½hvalueiš ¼ hvaluei. NE_POINT_OUTSIDE_RECT On entry, point ðx½hvalueiš ¼ hvaluei; y½hvalueiš ¼ hvalueiþ lies outside the rectangle bounded by spline! lamda½3š ¼hvaluei, spline! lamda½hvalueiš ¼ hvaluei, spline! mu½3š ¼hvaluei, spline! mu½hvalueiš ¼ hvaluei. 7 Accuracy The method used to evaluate the B-splines is numerically stable, in the sense that each computed value of sx ð r ;y r Þ can be regarded as the value that would have been obtained in exact arithmetic from slightly perturbed B-spline coefficients. See Cox (1978) for details. 8 Further Comments Computation time is approximately proportional to the number of points, m, at which the evaluation is required. 9 Example This program reads in knot sets spline! lamda½0š;...; spline! lamda½spline! nx 1Š and spline! mu½0š;...; spline! mu½spline! ny 1Š, and a set of bicubic spline coefficients c ij. Following these are a value for m and the co-ordinates ðx r ;y r Þ, for r ¼ 1; 2;...;m, at which the spline is to be evaluated. 9.1 Program Text /* nag_2d_spline_eval () Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. */ #include <nag.h> #include <nagx04.h> #include <stdio.h> #include <nag_stdlib.h> #include <nage02.h> int main(int argc, char *argv[]) FILE *fpin, *fpout; Integer exit_status = 0, i, m; NagError fail; Nag_2dSpline spline; double *ff = 0, *x = 0, *y = 0; INIT_FAIL(fail); /* Initialise spline */ spline.lamda = 0; spline.mu = 0;.3

NAG Library Manual spline.c = 0; /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_2d_spline_eval () Example Program Results\n"); fscanf(fpin, "%*[^\n]"); /* Skip heading in data file */ /* Read m, the number of spline evaluation points. */ fscanf(fpin, "%ld", &m); if (m >= 1) if (!(x = NAG_ALLOC(m, double))!(y = NAG_ALLOC(m, double))!(ff = NAG_ALLOC(m, double))) fprintf(fpout, "Allocation failure\n"); exit_status = -1; else fprintf(fpout, "Invalid m.\n"); /* Read nx and ny, the number of knots in the x and y directions. */ fscanf(fpin, "%ld%ld", &(spline.nx), &(spline.ny)); if (spline.nx >= 8 && spline.ny >= 8) if (!(spline.c = NAG_ALLOC((spline.nx-4)*(spline.ny-4), double))!(spline.lamda = NAG_ALLOC(spline.nx, double))!(spline.mu = NAG_ALLOC(spline.ny, double))) fprintf(fpout, "Allocation failure\n"); exit_status = -1; else fprintf(fpout, "Invalid spline.nx or spline.ny.\n"); /* read the knots lamda[0].. lamda[nx-1] and mu[0].. mu[ny-1]. */ for (i = 0; i < spline.nx; i++) fscanf(fpin, "%lf", &(spline.lamda[i])); for (i = 0; i < spline.ny; i++) fscanf(fpin, "%lf", &(spline.mu[i])); /* Read c, the bicubic spline coefficients. */ for (i = 0; i < (spline.nx-4)*(spline.ny-4); fscanf(fpin, "%lf", &(spline.c[i])), i++) ; /* Read the x and y co-ordinates of the evaluation points. */ for (i = 0; i < m; i++) fscanf(fpin, "%lf%lf", &x[i], &y[i]); /* Evaluate the spline at the m points. */ /* nag_2d_spline_eval (). * Evaluation of bicubic spline, at a set of points */ nag_2d_spline_eval(m, x, y, ff, &spline, &fail); if (fail.code!= NE_NOERROR) fprintf(fpout, "Error from nag_2d_spline_eval ().\n%s\n", fail.message);.4

/* Print the results. */ fprintf(fpout, " i x[i] y[i] ff[i]\n"); for (i = 0; i < m; i++) fprintf(fpout, "%7ld %11.3f%11.3f%11.3f\n", i, x[i], y[i], ff[i]); NAG_FREE(spline.lamda); NAG_FREE(spline.mu); NAG_FREE(spline.c); END: if (fpin!= stdin) fclose(fpin); if (fpout!= stdout) fclose(fpout); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (ff) NAG_FREE(ff); 9.2 Program Data nag_2d_spline_eval () Example Program Data 7 11 10 1.0 1.0 1.0 1.0 1.3 1.5 1.6 2.0 2.0 2.0 2.0 0.0 0.0 0.0 0.0 0.4 0.7 1.0 1.0 1.0 1.0 1.0000 1.1333 1.3667 1.7000 1.9000 2.0000 1.2000 1.3333 1.5667 1.9000 2.1000 2.2000 1.5833 1.7167 1.9500 2.2833 2.4833 2.5833 2.1433 2.2767 2.5100 2.8433 3.0433 3.1433 2.8667 3.0000 3.2333 3.5667 3.7667 3.8667 3.4667 3.6000 3.8333 4.1667 4.3667 4.4667 4.0000 4.1333 4.3667 4.7000 4.9000 5.0000 1.0 0.0 1.1 0.1 1.5 0.7 1.6 0.4 1.9 0.3 1.9 0.8 2.0 1.0 9.3 Program Results nag_2d_spline_eval () Example Program Results i x[i] y[i] ff[i] 0 1.000 0.000 1.000 1 1.100 0.100 1.310 2 1.500 0.700 2.950 3 1.600 0.400 2.960 4 1.900 0.300 3.910 5 1.900 0.800 4.410 6 2.000 1.000 5.000.5 (last)