4. Numerics and documentation
In this assignment, your task is to write a fully commented and documented module - using Doxygen - that can solve the fixed point equation f(x) = x for arbitrary functions f.
The primary function in this module should be of the following form:
std::pair<double,int> solve_fixed_point(std::function<double(double)> f, double x0, double reltol, int max);
Here, "std::function<double(double)>" is a C++ way to pass a function to another function; it requires the "<functional>" header.
The pair returned should contain the solved value of x and the number of times f was repeatedy called. To use "std::pair", you need to include the "<utility>" header.
This function should use the following method: Starting from a given guess "x0" for x, compute a new value x'=f(x) to replace x, and repeat until the relative difference |(x'-x)/x| is smaller than "reltol". The number of repeats should not exceed "max".
In addition, the module should have a second function called "relative_error" that can compute the relative error given f and x, i.e., how much f(x) and x differ relatively.
Your module should have a proper header file and separate cpp file, with comments in Doxygen format.
As an example use case, the program solverexample.ccp (see below) should work with this module.
Use a Makefile to build the module, to build and run the example use case, and to create the documentation for the module with Doxygen (both in pdf and in html format).
Use git version control throughout with several meaningful commits. Make sure your repo contains:
- The header and cpp file of the module
- The example code solverexample.cpp
- The Makefile
- The Doxygen file
- The documentation pdf that Doxygen produced.
Submit the assignment with git2zip as in the previous assignments. The deadline for this assignment is Friday February 13th, at 23:59 PM. The late policy can be found in the syllabus.
- 6 February 2026, 11:45 AM