C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
Classes | Functions
exprtk_simple_example_19.cpp File Reference
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string>
#include "exprtk.hpp"
Include dependency graph for exprtk_simple_example_19.cpp:

Go to the source code of this file.

Classes

class  randu< T >
 

Functions

template<typename T >
void vector_randu ()
 
int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 127 of file exprtk_simple_example_19.cpp.

128{
129 vector_randu<double>();
130 return 0;
131}

◆ vector_randu()

template<typename T >
void vector_randu ( )

Definition at line 83 of file exprtk_simple_example_19.cpp.

84{
85 typedef exprtk::symbol_table<T> symbol_table_t;
86 typedef exprtk::expression<T> expression_t;
87 typedef exprtk::parser<T> parser_t;
88
89 const std::string vecrandu_program =
90 " var noise[6] := [0]; "
91 " "
92 " if (randu(noise,0,5) == false) "
93 " { "
94 " println('Failed to generate noise'); "
95 " return [false]; "
96 " }; "
97 " "
98 " var noisy[noise[]] := signal + (noise - 1/2); "
99 " "
100 " for (var i := 0; i < noisy[]; i += 1) "
101 " { "
102 " println('noisy[',i,'] = ', noisy[i]); "
103 " }; "
104 " "
105 " println('avg: ', avg(noisy)); "
106 " ";
107
108 T signal[] = { T(1.1), T(2.2), T(3.3), T(4.4), T(5.5), T(6.6), T(7.7) };
109
112
113 symbol_table_t symbol_table;
114 symbol_table.add_vector ("signal" , signal );
115 symbol_table.add_function("println", println);
116 symbol_table.add_function("randu" , randu );
117
118 expression_t expression;
119 expression.register_symbol_table(symbol_table);
120
121 parser_t parser;
122 parser.compile(vecrandu_program,expression);
123
124 expression.value();
125}

References exprtk::symbol_table< T >::add_function(), exprtk::symbol_table< T >::add_vector(), exprtk::parser< T >::compile(), exprtk::expression< T >::register_symbol_table(), and exprtk::expression< T >::value().

Here is the call graph for this function: