2014-06-08 09:24:53 +00:00
|
|
|
/*
|
|
|
|
**************************************************************
|
|
|
|
* C++ Mathematical Expression Toolkit Library *
|
|
|
|
* *
|
|
|
|
* Simple Example 14 *
|
2024-01-01 00:00:00 +00:00
|
|
|
* Author: Arash Partow (1999-2024) *
|
2023-01-01 02:18:35 +00:00
|
|
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
2014-06-08 09:24:53 +00:00
|
|
|
* *
|
|
|
|
* Copyright notice: *
|
|
|
|
* Free use of the Mathematical Expression Toolkit Library is *
|
|
|
|
* permitted under the guidelines and in accordance with the *
|
2017-02-21 21:44:24 +00:00
|
|
|
* most current version of the MIT License. *
|
2023-01-01 02:18:35 +00:00
|
|
|
* https://www.opensource.org/licenses/MIT *
|
2024-01-01 00:00:00 +00:00
|
|
|
* SPDX-License-Identifier: MIT *
|
2014-06-08 09:24:53 +00:00
|
|
|
* *
|
|
|
|
**************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <string>
|
2020-01-01 00:00:00 +00:00
|
|
|
|
2014-06-08 09:24:53 +00:00
|
|
|
#include "exprtk.hpp"
|
|
|
|
|
|
|
|
|
2014-07-15 13:09:08 +00:00
|
|
|
template <typename T>
|
2014-06-08 09:24:53 +00:00
|
|
|
void stddev_example()
|
|
|
|
{
|
2014-06-10 20:53:29 +00:00
|
|
|
typedef exprtk::expression<T> expression_t;
|
2021-01-01 00:00:00 +00:00
|
|
|
typedef exprtk::parser<T> parser_t;
|
2014-06-08 09:24:53 +00:00
|
|
|
|
2020-01-01 00:00:00 +00:00
|
|
|
const std::string stddev_program =
|
2024-01-01 00:00:00 +00:00
|
|
|
" var x[25] := { "
|
|
|
|
" 1, 2, 3, 4, 5, "
|
|
|
|
" 6, 7, 8, 9, 10, "
|
|
|
|
" 11, 12, 13, 14, 15, "
|
|
|
|
" 16, 17, 18, 19, 20, "
|
|
|
|
" 21, 22, 23, 24, 25 "
|
|
|
|
" }; "
|
|
|
|
" "
|
|
|
|
" sqrt(sum([x - avg(x)]^2) / x[]) ";
|
2014-06-08 09:24:53 +00:00
|
|
|
|
|
|
|
expression_t expression;
|
|
|
|
|
|
|
|
parser_t parser;
|
|
|
|
parser.compile(stddev_program,expression);
|
|
|
|
|
2020-01-01 00:00:00 +00:00
|
|
|
const T stddev = expression.value();
|
2014-06-08 09:24:53 +00:00
|
|
|
|
|
|
|
printf("stddev(1..25) = %10.6f\n",stddev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
stddev_example<double>();
|
|
|
|
return 0;
|
|
|
|
}
|