Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,64 @@ Which will put the library's header files and the application `<install_path>/in

## Usage

The program can be executed with:

```
$ ./build/ROOT/ROOT/root_cli <arguments>
```
In order to print out helper to pass correctly the arguments `--help` can be added:
Comment thread
andreasaporito marked this conversation as resolved.
Outdated

```
$ ./build/ROOT/ROOT/root_cli <arguments>
Comment thread
andreasaporito marked this conversation as resolved.
Outdated
```
Every additional needed function must be added together with the function to find the root of.
Comment thread
andreasaporito marked this conversation as resolved.
Here's a list of examples of possible execution syntax:

- CLI input, CLI output, Newton-Raphson method to find the root of x^2-4, starting from initial guess 1 (default tolerance and maximum iterations):

```
$ ./build/ROOT/ROOT/root_cli --wcli cli --function "x^2-4" newton --initial 1.0 --derivative "2*x"
```
Comment thread
andreasaporito marked this conversation as resolved.
Outdated
Comment thread
andreasaporito marked this conversation as resolved.
Outdated

- .dat input file called input.dat with first row not being header and " " separating different values, .dat file output called output.dat, Bisection method to find the root of x^3-1, with initial interval [-2,2], verbose output (given tolerance and maximum iterations):
Comment thread
andreasaporito marked this conversation as resolved.
Outdated

```
$ ./build/ROOT/ROOT/root_cli --verbose --wdat output dat input
```
Comment thread
andreasaporito marked this conversation as resolved.
Outdated
Comment thread
andreasaporito marked this conversation as resolved.
Outdated

where input.dat is:

```
function = x^3-1
method = bisection
initial = -1
tolerance = 1e-5
max-iterations = 100
derivative = 2*x
```
Comment thread
andreasaporito marked this conversation as resolved.
Outdated

- .csv input file called input.csv with first row which is a header and "," separating different values, .csv file ouput
Comment thread
andreasaporito marked this conversation as resolved.
Outdated
called output.csv, Fixed Point Method to find the root of cos(x), with
initial guess 0.5, fixed point function cos(x):

```
$ ./build/ROOT/ROOT/root_cli --wcsv output --ocsvsep , csv input --sep , --header
```
Comment thread
andreasaporito marked this conversation as resolved.
Outdated
Comment thread
andreasaporito marked this conversation as resolved.
Outdated

where input.csv is:

```
function,method,initial,tolerance,max_iterations,g-function
'cos(x)',fixed_point,0.5,1e-5,100,'cos(x)'
```
Comment thread
andreasaporito marked this conversation as resolved.
Outdated

- CLI input, .dat output file called output.dat and moreover a GNU Plot is created from it as output.png. Chords method to solve
the equation x^3-8 starting from the two initial points 1 and 3:

```
$ ./build/ROOT/ROOT/root_cli --wdat output --wgnuplot output cli --function x^3-8 chords --x0 --x1 3
```
Comment thread
andreasaporito marked this conversation as resolved.
Outdated

The installed CLI application can simply be used by:

```
Expand Down
20 changes: 10 additions & 10 deletions ROOT/ROOT/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ std::unique_ptr<ConfigBase> ReaderBase::make_config_from_map(
}

int max_iter = 100;
auto it_max = config_map.find("max_iterations");
auto it_max = config_map.find("max-iterations");
if (it_max != config_map.end()) {
if (!parseInt(it_max->second, max_iter)) {
std::cerr << "\033[31mmake_config_from_map: invalid max_iterations: " << it_max->second << "\033[0m\n";
std::cerr << "\033[31mmake_config_from_map: invalid max-iterations: " << it_max->second << "\033[0m\n";
std::exit(EXIT_FAILURE);
}
}
Expand Down Expand Up @@ -202,14 +202,14 @@ std::unique_ptr<ConfigBase> ReaderBase::make_config_from_map(

case Method::FIXED_POINT: {
auto it_x0 = config_map.find("initial");
auto it_g = config_map.find("function_g");
auto it_g = config_map.find("g-function");
if (it_x0 == config_map.end() || it_g == config_map.end()) {
std::cerr << "\033[31mmake_config_from_map: fixed_point requires initial and function_g\033[0m\n";
std::cerr << "\033[31mmake_config_from_map: fixed_point requires initial and g-function\033[0m\n";
std::exit(EXIT_FAILURE);
}
double initial = 0.0;
auto function_g = FunctionParserBase::parseFunction(it_g->second);
return std::make_unique<FixedPointConfig>(tolerance, max_iter, aitken, function, initial, function_g,
auto g_function = FunctionParserBase::parseFunction(it_g->second);
return std::make_unique<FixedPointConfig>(tolerance, max_iter, aitken, function, initial, g_function,
verbose);
}
} // switch
Expand Down Expand Up @@ -312,8 +312,8 @@ std::unique_ptr<ConfigBase> ReaderCSV::read(CLI::App* app, bool verbose) {
}
} else {
// positional mapping documented here:
std::vector<std::string> posnames = {"method", "tolerance", "max_iterations", "aitken", "function",
"derivative", "interval_a", "interval_b", "function_g", "initial",
std::vector<std::string> posnames = {"method", "tolerance", "max-iterations", "aitken", "function",
"derivative", "interval_a", "interval_b", "function-g", "initial",
"x0", "x1"};
for (size_t i = 0; i < values.size() && i < posnames.size(); ++i) {
config_map[posnames[i]] = values[i];
Expand Down Expand Up @@ -383,7 +383,7 @@ std::unique_ptr<ConfigBase> ReaderCLI::read(CLI::App* app, bool verbose) {
if (verbose) {
std::cout << "ReaderCLI: read configuration\n";
std::cout << " tolerance = " << app->get_option("--tolerance")->as<double>() << "\n";
std::cout << " max_iterations = " << app->get_option("--max-iterations")->as<int>() << "\n";
std::cout << " max-iterations = " << app->get_option("--max-iterations")->as<int>() << "\n";
std::cout << " aitken = " << (app->get_option("--aitken")->as<bool>() ? "true" : "false") << "\n";
std::cout << " function = " << app->get_option("--function")->as<std::string>() << "\n";
std::cout << " verbose = " << (verbose ? "true" : "false") << "\n";
Expand Down Expand Up @@ -423,7 +423,7 @@ std::unique_ptr<ConfigBase> ReaderCLI::read(CLI::App* app, bool verbose) {
app->get_subcommand("fixed_point")->get_option("--g-function")->as<std::string>()),
verbose);
if (verbose) {
std::cout << " g_function = "
std::cout << " g-function = "
<< app->get_subcommand("fixed_point")->get_option("--g-function")->as<std::string>() << "\n";
std::cout << " initial = " << app->get_subcommand("fixed_point")->get_option("--initial")->as<double>()
<< "\n";
Expand Down