C++ Mathematical Expression Toolkit (ExprTk)
release
Toggle main menu visibility
Loading...
Searching...
No Matches
exprtk
exprtk_simple_example_06.cpp
Go to the documentation of this file.
1
/*
2
**************************************************************
3
* C++ Mathematical Expression Toolkit Library *
4
* *
5
* Simple Example 06 *
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
vector_function
()
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
" for (var i := 0; i < min(x[], y[], z[]); i += 1) "
35
" { "
36
" z[i] := 3sin(x[i]) + 2log(y[i]); "
37
" } "
;
38
39
T x[] = { T(1.1), T(2.2), T(3.3), T(4.4), T(5.5) };
40
T y[] = { T(1.1), T(2.2), T(3.3), T(4.4), T(5.5) };
41
T z[] = { T(0.0), T(0.0), T(0.0), T(0.0), T(0.0) };
42
43
symbol_table_t symbol_table;
44
symbol_table.add_vector(
"x"
,x);
45
symbol_table.add_vector(
"y"
,y);
46
symbol_table.add_vector(
"z"
,z);
47
48
expression_t expression;
49
expression.register_symbol_table(symbol_table);
50
51
parser_t parser;
52
parser.
compile
(expression_string,expression);
53
54
expression.value();
55
}
56
57
int
main
()
58
{
59
vector_function<double>
();
60
return
0;
61
}
exprtk::expression
Definition
exprtk.hpp:21832
exprtk::parser
Definition
exprtk.hpp:22525
exprtk::parser::compile
bool compile(const std::string &expression_string, expression< T > &expr)
Definition
exprtk.hpp:24826
exprtk::symbol_table
Definition
exprtk.hpp:20090
exprtk.hpp
vector_function
void vector_function()
Definition
exprtk_simple_example_06.cpp:27
main
int main()
Definition
exprtk_simple_example_06.cpp:57
Generated by
1.17.0