# Maple code to compute 1-D Lagrange interpolation coefficients (orders 1-4) # $Id$ ################################################################################ # # interpolating functions # fn_1d_order1 := proc(x) + c0 + c1*x end proc; fn_1d_order2 := proc(x) + c0 + c1*x + c2*x^2 end proc; fn_1d_order3 := proc(x) + c0 + c1*x + c2*x^2 + c3*x^3 end proc; fn_1d_order4 := proc(x) + c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 end; fn_1d_order5 := proc(x) + c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 + c5*x^5 end; fn_1d_order6 := proc(x) + c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 + c5*x^5 + c6*x^6 end; ######################################## # # coefficients in interpolating functions # coeff_list_1d_order1 := [c0, c1]; coeff_list_1d_order2 := [c0, c1, c2]; coeff_list_1d_order3 := [c0, c1, c2, c3]; coeff_list_1d_order4 := [c0, c1, c2, c3, c4]; coeff_list_1d_order5 := [c0, c1, c2, c3, c4, c5]; coeff_list_1d_order6 := [c0, c1, c2, c3, c4, c5, c6]; ######################################## # # coordinates and interpolation points # coord_list_1d := [x]; # generate points in Fortran ordering posn_list_1d_size2 := map(ListTools[Reverse], hypercube_points([ 0], [+1])); posn_list_1d_size3 := map(ListTools[Reverse], hypercube_points([-1], [+1])); posn_list_1d_size4 := map(ListTools[Reverse], hypercube_points([-1], [+2])); posn_list_1d_size5 := map(ListTools[Reverse], hypercube_points([-2], [+2])); posn_list_1d_size6 := map(ListTools[Reverse], hypercube_points([-2], [+3])); posn_list_1d_size7 := map(ListTools[Reverse], hypercube_points([-3], [+3])); ################################################################################ # # generic stuff for 1d, cube, size=2 # data_var_list_1d_size2 := map(data_var_name, posn_list_1d_size2, "data_"); print_name_list_dcl(data_var_list_1d_size2, "fp", "1d.coeffs/1d.cube.size2/data-var.dcl.c"); print_data_var_assign(posn_list_1d_size2, "data_", "1d.coeffs/1d.cube.size2/data-var.assign.c"); print_interp_coeff_var_store(posn_list_1d_size2, "coeff_I_", "1d.coeffs/1d.cube.size2/coeff-I.store.c"); print_interp_coeff_var_store(posn_list_1d_size2, "coeff_dx_", "1d.coeffs/1d.cube.size2/coeff-dx.store.c"); print_interp_coeff_var_store(posn_list_1d_size2, "coeff_dxx_", "1d.coeffs/1d.cube.size2/coeff-dxx.store.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size2, "coeff_I_"), "fp", "1d.coeffs/1d.cube.size2/coeff-I.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size2, "coeff_dx_"), "fp", "1d.coeffs/1d.cube.size2/coeff-dx.dcl.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size2, "result", "coeff_I_", "data_", "1d.coeffs/1d.cube.size2/interp-I.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size2, "result", "coeff_dx_", "data_", "1d.coeffs/1d.cube.size2/interp-dx.compute.c"); ######################################## # # generic stuff for 1d, cube, size=3 # data_var_list_1d_size3 := map(data_var_name, posn_list_1d_size3, "data_"); print_name_list_dcl(data_var_list_1d_size3, "fp", "1d.coeffs/1d.cube.size3/data-var.dcl.c"); print_data_var_assign(posn_list_1d_size3, "data_", "1d.coeffs/1d.cube.size3/data-var.assign.c"); print_interp_coeff_var_store(posn_list_1d_size3, "coeff_I_", "1d.coeffs/1d.cube.size3/coeff-I.store.c"); print_interp_coeff_var_store(posn_list_1d_size3, "coeff_dx_", "1d.coeffs/1d.cube.size3/coeff-dx.store.c"); print_interp_coeff_var_store(posn_list_1d_size3, "coeff_dxx_", "1d.coeffs/1d.cube.size3/coeff-dxx.store.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size3, "coeff_I_"), "fp", "1d.coeffs/1d.cube.size3/coeff-I.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size3, "coeff_dx_"), "fp", "1d.coeffs/1d.cube.size3/coeff-dx.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size3, "coeff_dxx_"), "fp", "1d.coeffs/1d.cube.size3/coeff-dxx.dcl.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size3, "result", "coeff_I_", "data_", "1d.coeffs/1d.cube.size3/interp-I.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size3, "result", "coeff_dx_", "data_", "1d.coeffs/1d.cube.size3/interp-dx.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size3, "result", "coeff_dxx_", "data_", "1d.coeffs/1d.cube.size3/interp-dxx.compute.c"); ######################################## # # generic stuff for 1d, cube, size=4 # data_var_list_1d_size4 := map(data_var_name, posn_list_1d_size4, "data_"); print_name_list_dcl(data_var_list_1d_size4, "fp", "1d.coeffs/1d.cube.size4/data-var.dcl.c"); print_data_var_assign(posn_list_1d_size4, "data_", "1d.coeffs/1d.cube.size4/data-var.assign.c"); print_interp_coeff_var_store(posn_list_1d_size4, "coeff_I_", "1d.coeffs/1d.cube.size4/coeff-I.store.c"); print_interp_coeff_var_store(posn_list_1d_size4, "coeff_dx_", "1d.coeffs/1d.cube.size4/coeff-dx.store.c"); print_interp_coeff_var_store(posn_list_1d_size4, "coeff_dxx_", "1d.coeffs/1d.cube.size4/coeff-dxx.store.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size4, "coeff_I_"), "fp", "1d.coeffs/1d.cube.size4/coeff-I.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size4, "coeff_dx_"), "fp", "1d.coeffs/1d.cube.size4/coeff-dx.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size4, "coeff_dxx_"), "fp", "1d.coeffs/1d.cube.size4/coeff-dxx.dcl.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size4, "result", "coeff_I_", "data_", "1d.coeffs/1d.cube.size4/interp-I.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size4, "result", "coeff_dx_", "data_", "1d.coeffs/1d.cube.size4/interp-dx.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size4, "result", "coeff_dxx_", "data_", "1d.coeffs/1d.cube.size4/interp-dxx.compute.c"); ######################################## # # generic stuff for 1d, cube, size=5 # data_var_list_1d_size5 := map(data_var_name, posn_list_1d_size5, "data_"); print_name_list_dcl(data_var_list_1d_size5, "fp", "1d.coeffs/1d.cube.size5/data-var.dcl.c"); print_data_var_assign(posn_list_1d_size5, "data_", "1d.coeffs/1d.cube.size5/data-var.assign.c"); print_interp_coeff_var_store(posn_list_1d_size5, "coeff_I_", "1d.coeffs/1d.cube.size5/coeff-I.store.c"); print_interp_coeff_var_store(posn_list_1d_size5, "coeff_dx_", "1d.coeffs/1d.cube.size5/coeff-dx.store.c"); print_interp_coeff_var_store(posn_list_1d_size5, "coeff_dxx_", "1d.coeffs/1d.cube.size5/coeff-dxx.store.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size5, "coeff_I_"), "fp", "1d.coeffs/1d.cube.size5/coeff-I.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size5, "coeff_dx_"), "fp", "1d.coeffs/1d.cube.size5/coeff-dx.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size5, "coeff_dxx_"), "fp", "1d.coeffs/1d.cube.size5/coeff-dxx.dcl.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size5, "result", "coeff_I_", "data_", "1d.coeffs/1d.cube.size5/interp-I.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size5, "result", "coeff_dx_", "data_", "1d.coeffs/1d.cube.size5/interp-dx.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size5, "result", "coeff_dxx_", "data_", "1d.coeffs/1d.cube.size5/interp-dxx.compute.c"); ######################################## # # generic stuff for 1d, cube, size=6 # data_var_list_1d_size6 := map(data_var_name, posn_list_1d_size6, "data_"); print_name_list_dcl(data_var_list_1d_size6, "fp", "1d.coeffs/1d.cube.size6/data-var.dcl.c"); print_data_var_assign(posn_list_1d_size6, "data_", "1d.coeffs/1d.cube.size6/data-var.assign.c"); print_interp_coeff_var_store(posn_list_1d_size6, "coeff_I_", "1d.coeffs/1d.cube.size6/coeff-I.store.c"); print_interp_coeff_var_store(posn_list_1d_size6, "coeff_dx_", "1d.coeffs/1d.cube.size6/coeff-dx.store.c"); print_interp_coeff_var_store(posn_list_1d_size6, "coeff_dxx_", "1d.coeffs/1d.cube.size6/coeff-dxx.store.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size6, "coeff_I_"), "fp", "1d.coeffs/1d.cube.size6/coeff-I.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size6, "coeff_dx_"), "fp", "1d.coeffs/1d.cube.size6/coeff-dx.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size6, "coeff_dxx_"), "fp", "1d.coeffs/1d.cube.size6/coeff-dxx.dcl.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size6, "result", "coeff_I_", "data_", "1d.coeffs/1d.cube.size6/interp-I.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size6, "result", "coeff_dx_", "data_", "1d.coeffs/1d.cube.size6/interp-dx.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size6, "result", "coeff_dxx_", "data_", "1d.coeffs/1d.cube.size6/interp-dxx.compute.c"); ######################################## # # generic stuff for 1d, cube, size=7 # data_var_list_1d_size7 := map(data_var_name, posn_list_1d_size7, "data_"); print_name_list_dcl(data_var_list_1d_size7, "fp", "1d.coeffs/1d.cube.size7/data-var.dcl.c"); print_data_var_assign(posn_list_1d_size7, "data_", "1d.coeffs/1d.cube.size7/data-var.assign.c"); print_interp_coeff_var_store(posn_list_1d_size7, "coeff_I_", "1d.coeffs/1d.cube.size7/coeff-I.store.c"); print_interp_coeff_var_store(posn_list_1d_size7, "coeff_dx_", "1d.coeffs/1d.cube.size7/coeff-dx.store.c"); print_interp_coeff_var_store(posn_list_1d_size7, "coeff_dxx_", "1d.coeffs/1d.cube.size7/coeff-dxx.store.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size7, "coeff_I_"), "fp", "1d.coeffs/1d.cube.size7/coeff-I.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size7, "coeff_dx_"), "fp", "1d.coeffs/1d.cube.size7/coeff-dx.dcl.c"); print_name_list_dcl(map(coeff_name, posn_list_1d_size7, "coeff_dxx_"), "fp", "1d.coeffs/1d.cube.size7/coeff-dxx.dcl.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size7, "result", "coeff_I_", "data_", "1d.coeffs/1d.cube.size7/interp-I.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size7, "result", "coeff_dx_", "data_", "1d.coeffs/1d.cube.size7/interp-dx.compute.c"); print_interp_cmpt__lc_of_data(posn_list_1d_size7, "result", "coeff_dxx_", "data_", "1d.coeffs/1d.cube.size7/interp-dxx.compute.c"); ################################################################################ # # 1d, cube, order=1, smoothing=0 (size=2) # # interpolating polynomial interp_1d_cube_order1_smooth0 := polynomial_interpolant(fn_1d_order1, coeff_list_1d_order1, coord_list_1d, posn_list_1d_size2); # I coeff_as_lc_of_data(%, posn_list_1d_size2); print_coeff__lc_of_data(%, "coeff_I_", "fp", "1d.coeffs/1d.cube.order1.smooth0/coeff-I.compute.c"); # d/dx simplify( diff(interp_1d_cube_order1_smooth0,x) ); coeff_as_lc_of_data(%, posn_list_1d_size2); print_coeff__lc_of_data(%, "coeff_dx_", "fp", "1d.coeffs/1d.cube.order1.smooth0/coeff-dx.compute.c"); ######################################## # # 1d, cube, order=2, smoothing=0 (size=3) # # interpolating polynomial interp_1d_cube_order2_smooth0 := polynomial_interpolant(fn_1d_order2, coeff_list_1d_order2, coord_list_1d, posn_list_1d_size3); # I coeff_as_lc_of_data(%, posn_list_1d_size3); print_coeff__lc_of_data(%, "coeff_I_", "fp", "1d.coeffs/1d.cube.order2.smooth0/coeff-I.compute.c"); # d/dx simplify( diff(interp_1d_cube_order2_smooth0,x) ); coeff_as_lc_of_data(%, posn_list_1d_size3); print_coeff__lc_of_data(%, "coeff_dx_", "fp", "1d.coeffs/1d.cube.order2.smooth0/coeff-dx.compute.c"); # d^2/dx^2 simplify( diff(interp_1d_cube_order2_smooth0,x,x) ); coeff_as_lc_of_data(%, posn_list_1d_size3); print_coeff__lc_of_data(%, "coeff_dxx_", "fp", "1d.coeffs/1d.cube.order2.smooth0/coeff-dxx.compute.c"); ######################################## # # 1d, cube, order=3, smoothing=0 (size=4) # # interpolating polynomial interp_1d_cube_order3_smooth0 := polynomial_interpolant(fn_1d_order3, coeff_list_1d_order3, coord_list_1d, posn_list_1d_size4); # I coeff_as_lc_of_data(%, posn_list_1d_size4); print_coeff__lc_of_data(%, "coeff_I_", "fp", "1d.coeffs/1d.cube.order3.smooth0/coeff-I.compute.c"); # d/dx simplify( diff(interp_1d_cube_order3_smooth0,x) ); coeff_as_lc_of_data(%, posn_list_1d_size4); print_coeff__lc_of_data(%, "coeff_dx_", "fp", "1d.coeffs/1d.cube.order3.smooth0/coeff-dx.compute.c"); # d^2/dx^2 simplify( diff(interp_1d_cube_order3_smooth0,x,x) ); coeff_as_lc_of_data(%, posn_list_1d_size4); print_coeff__lc_of_data(%, "coeff_dxx_", "fp", "1d.coeffs/1d.cube.order3.smooth0/coeff-dxx.compute.c"); ######################################## # # 1d, cube, order=4, smoothing=0 (size=5) # # interpolating polynomial interp_1d_cube_order4_smooth0 := polynomial_interpolant(fn_1d_order4, coeff_list_1d_order4, coord_list_1d, posn_list_1d_size5); # I coeff_as_lc_of_data(%, posn_list_1d_size5); print_coeff__lc_of_data(%, "coeff_I_", "fp", "1d.coeffs/1d.cube.order4.smooth0/coeff-I.compute.c"); # d/dx simplify( diff(interp_1d_cube_order4_smooth0,x) ); coeff_as_lc_of_data(%, posn_list_1d_size5); print_coeff__lc_of_data(%, "coeff_dx_", "fp", "1d.coeffs/1d.cube.order4.smooth0/coeff-dx.compute.c"); # d^2/dx^2 simplify( diff(interp_1d_cube_order4_smooth0,x,x) ); coeff_as_lc_of_data(%, posn_list_1d_size5); print_coeff__lc_of_data(%, "coeff_dxx_", "fp", "1d.coeffs/1d.cube.order4.smooth0/coeff-dxx.compute.c"); ######################################## # # 1d, cube, order=5, smoothing=0 (size=6) # # interpolating polynomial interp_1d_cube_order5_smooth0 := polynomial_interpolant(fn_1d_order5, coeff_list_1d_order5, coord_list_1d, posn_list_1d_size6); # I coeff_as_lc_of_data(%, posn_list_1d_size6); print_coeff__lc_of_data(%, "coeff_I_", "fp", "1d.coeffs/1d.cube.order5.smooth0/coeff-I.compute.c"); # d/dx simplify( diff(interp_1d_cube_order5_smooth0,x) ); coeff_as_lc_of_data(%, posn_list_1d_size6); print_coeff__lc_of_data(%, "coeff_dx_", "fp", "1d.coeffs/1d.cube.order5.smooth0/coeff-dx.compute.c"); # d^2/dx^2 simplify( diff(interp_1d_cube_order5_smooth0,x,x) ); coeff_as_lc_of_data(%, posn_list_1d_size6); print_coeff__lc_of_data(%, "coeff_dxx_", "fp", "1d.coeffs/1d.cube.order5.smooth0/coeff-dxx.compute.c"); ######################################## # # 1d, cube, order=6, smoothing=0 (size=7) # # interpolating polynomial interp_1d_cube_order6_smooth0 := polynomial_interpolant(fn_1d_order6, coeff_list_1d_order6, coord_list_1d, posn_list_1d_size7); # I coeff_as_lc_of_data(%, posn_list_1d_size7); print_coeff__lc_of_data(%, "coeff_I_", "fp", "1d.coeffs/1d.cube.order6.smooth0/coeff-I.compute.c"); # d/dx simplify( diff(interp_1d_cube_order6_smooth0,x) ); coeff_as_lc_of_data(%, posn_list_1d_size7); print_coeff__lc_of_data(%, "coeff_dx_", "fp", "1d.coeffs/1d.cube.order6.smooth0/coeff-dx.compute.c"); # d^2/dx^2 simplify( diff(interp_1d_cube_order6_smooth0,x,x) ); coeff_as_lc_of_data(%, posn_list_1d_size7); print_coeff__lc_of_data(%, "coeff_dxx_", "fp", "1d.coeffs/1d.cube.order6.smooth0/coeff-dxx.compute.c"); ################################################################################