# # grid: # # A grid represents a discretization of an interval of the x-axis. # printf("grid procedures: \ create_grid, \ get_n_cells_of_grid, \ get_spacing_of_grid, \ get_interval_of_grid"); create_grid := proc(x_min, x_max, n_cells) # # Create a uniformly-spaced grid. # # The return value from create_grid(), call it g, is the new grid. # The grid extends from x_min to x_max and is divided into n_cells # cells. The grid points are located at the edges of cells, and # are numbered from j = 0, ..., n_cells. The position of the grid # point j is g[j]. # local grid, dx, j; grid := array(0..n_cells); dx := evalf((x_max - x_min)/n_cells); for j from 0 to n_cells do grid[j] := x_min + j*dx; od; grid end: get_n_cells_of_grid := proc(grid) # # Return the number of cells in the grid. # op(2,op(2,eval(g))) end: get_spacing_of_grid := proc(grid) # # Return grid spacing, i.e., the length of each grid cell. # grid[1] - grid[0] end: get_interval_of_grid := proc(grid) # # Return endpoints [x_min, x_max] of the grid. # [grid[0], grid[get_n_cells_of_grid(grid)]] end: