C++ Mathematical Expression Toolkit (ExprTk)
release
Toggle main menu visibility
Loading...
Searching...
No Matches
exprtk
exprtk_simple_example_03.cpp
Go to the documentation of this file.
1
/*
2
**************************************************************
3
* C++ Mathematical Expression Toolkit Library *
4
* *
5
* Simple Example 03 *
6
* Author: Arash Partow (1999-2025) *
7
* URL: https://www.partow.net/programming/exprtk/index.html *
8
* *
9
* Copyright notice: *
10
* Free use of the Mathematical Expression Toolkit Library is *
11
* permitted under the guidelines and in accordance with the *
12
* most current version of the MIT License. *
13
* https://www.opensource.org/licenses/MIT *
14
* SPDX-License-Identifier: MIT *
15
* *
16
**************************************************************
17
*/
18
19
20
#include <cstdio>
21
#include <string>
22
23
#include "
exprtk.hpp
"
24
25
26
template
<
typename
T>
27
void
polynomial
()
28
{
29
typedef
exprtk::symbol_table<T>
symbol_table_t;
30
typedef
exprtk::expression<T>
expression_t;
31
typedef
exprtk::parser<T>
parser_t;
32
33
const
std::string expression_string =
34
"25x^5 - 35x^4 - 15x^3 + 40x^2 - 15x + 1"
;
35
36
const
T r0 = T(0);
37
const
T r1 = T(1);
38
T x = T(0);
39
40
symbol_table_t symbol_table;
41
symbol_table.add_variable(
"x"
,x);
42
43
expression_t expression;
44
expression.register_symbol_table(symbol_table);
45
46
parser_t parser;
47
parser.compile(expression_string,expression);
48
49
const
T
delta
= T(1.0 / 100.0);
50
51
for
(x = r0; x <= r1; x +=
delta
)
52
{
53
printf(
"%19.15f\t%19.15f\n"
, x, expression.value());
54
}
55
}
56
57
int
main
()
58
{
59
polynomial<double>
();
60
return
0;
61
}
exprtk::expression
Definition
exprtk.hpp:21832
exprtk::parser
Definition
exprtk.hpp:22525
exprtk::symbol_table
Definition
exprtk.hpp:20090
exprtk.hpp
delta
static const double delta
Definition
exprtk_pgo.cpp:32
polynomial
void polynomial()
Definition
exprtk_simple_example_03.cpp:27
main
int main()
Definition
exprtk_simple_example_03.cpp:57
Generated by
1.17.0