Students must solve at least one problem in C++, at least one in Modern Fortran, and may choose either language for the third.
In addition, students must provide a Makefile that compiles each of the solutions. The targets should be problem1, problem3, and problem3.
Write a program that evaluates the temperature of an object over time using the model
Tasks
-
Input parameters:
T0,a,b,t_c, and number of stepsN. -
Build a 1D array of times:
$t_i = i,\Delta t,\quad \Delta t = t_{\max} / (N-1)$ -
Evaluate
T(t)using a function you define. -
Print:
- the minimum temperature,
- the time at which it occurs,
- the last five values of the temperature array.
Concepts required: if/else, loops, functions, arrays, C++ pass-by-value/reference/pointer or Fortran intent.
Write a small "statistics library" that works on a 1D array of doubles.
Functions / subroutines to implement
mean(x, N)variance(x, N)(sample variance)normalize(x, N)— modifies the existing array so values have zero mean and unit variance
Tasks
- Initialize an array as
$x_i = \sin(i) + 0.1,i$ - Print the mean and variance before normalization.
- Normalize the array in place:
- C++: use reference or pointer semantics
- Fortran: use
intent(inout)
- Print the mean and variance after normalization.
Concepts required: arrays, function interfaces, pass-by-reference / intent(inout), numerical loops.
Construct a 2D uniform grid over
Tasks
- Input grid size
N. - Allocate:
u(N, N)Lu(N, N)
- Initialize
$u(x,y) = \sin(\pi x)\sin(\pi y)$ - Compute the 5-point Laplacian for all interior points: $(Lu){i,j} =\frac{u{i+1,j} + u_{i-1,j} + u_{i,j+1} + u_{i,j-1} - 4u_{i,j}}{h^2}$
- Apply Dirichlet boundaries by leaving edges unchanged (i.e., Laplacian = 0 there).
- Print:
-
Luat the center grid point, - maximum absolute entry of
Lu.
-
Concepts required: 2D arrays, nested loops, numerical stencils, function/subroutine for Laplacian, C++ flattened arrays or MF native 2D arrays.