Computer Science Coursework
Routine Name: generateMesh
Author: Philip Nelson
Language: C++
generateMesh(T a, T b)
generates a 2D mesh from a
to b
with N
steps
generateMesh(T a, T b)
requires:
T a
- the start of the meshT b
- the end of the meshN
- the sizeThe mesh of \(i\cdot j\)
template <typename T, std::size_t N>
Matrix<T, N - 2, N - 2> generateMesh(T a, T b)
{
auto h = (b - a) / (N - 1);
return Matrix<T, N - 2, N - 2>(
[&](int i, int j) { return (a + (i + 1) * h) * (a + (j + 1) * h); });
}
int main()
{
std::cout << "mesh\n" << generateMesh<double, 7>(0, 1) << std::endl;
}
mesh
| 0.0278 0.0556 0.0833 0.111 0.139 |
| 0.0556 0.111 0.167 0.222 0.278 |
| 0.0833 0.167 0.25 0.333 0.417 |
| 0.111 0.222 0.333 0.444 0.556 |
| 0.139 0.278 0.417 0.556 0.694 |
Last Modification date: 27 February 2018