Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/skhelladi/eq_edit

EQ_EDIT is a simple C++ code that evaluate a mathematical expression with variables and some standard mathematical functions given as a string.
https://github.com/skhelladi/eq_edit

equation-evaluator mathematics

Last synced: 5 days ago
JSON representation

EQ_EDIT is a simple C++ code that evaluate a mathematical expression with variables and some standard mathematical functions given as a string.

Awesome Lists containing this project

README

        

# EQ_EDIT - A C++ Equation Evaluator

EQ_EDIT is a simple C++ code that evaluate a mathematical expression with variables and some standard mathematical functions given as a string. The variables and functions used in the equation are defined and their values are passed to the function that evaluates the equation. The code is presented in a single header file `EQ_EDIT.hpp` which contains the `EQ_EDIT` class.

The code allows the following mathematical operators to be used in the equation:
- `+` - Addition
- `-` - Subtraction
- `*` - Multiplication
- `/` - Division
- `^` - Power
- `()` - Parentheses

the following mathematical functions to be used in the equation:
- `abs` - Absolute value
- `int` - Integer part
- `frac` - Fractional part
- `rond` - Round
- `log` - Logarithm (base 10)
- `ln` - Natural logarithm
- `exp` - Exponential
- `sin` - Sine
- `cos` - Cosine
- `tan` - Tangent
- `sh` - Hyperbolic sine
- `ch` - Hyperbolic cosine
- `th` - Hyperbolic tangent
- `asin` - Arcsine
- `acos` - Arccosine
- `atan` - Arctangent
- `ash` - Hyperbolic arcsine
- `ach` - Hyperbolic arccosine
- `ath` - Hyperbolic arctangent

and the following mathematical constants to be used in the equation:
- `pi` - π number
- `e` - Euler's number

It is possible to add new functions and constants to the code by modifying the `EQ_EDIT.hpp` file.

## How it Works
The application uses the `EQ_EDIT` class to evaluate mathematical equations. The variables used in the equation are defined and their values are passed to the `Value` method of the `func_eq` object. This method evaluates the equation and returns the calculated value.
Another way to use the code is to define the variables and the equation using the `setVar` and `setEquation` methods of the `EQ_EDIT` class. The `getValue` method of the `func_eq` object, without any arguments, is then called to evaluate the equation.

## How to Use the Code
To use the code, you need to include the `EQ_EDIT.hpp` header file in your code. You can then create an instance of the `EQ_EDIT` class and use it to evaluate mathematical equations. See the code examples below for more details.

## Code example
### Example 1
A first example is presented in the `example1.cpp` file.
```cpp
#include
#include "EQ_EDIT.hpp"
using namespace std;
int main()
{
EQ_EDIT func_eq;
double x = 10;
double beta = 1.5;
string equation = "-(x^2/2)+20+2*beta+alpha";
double value = func_eq.getValue(true,equation,{{"x",x},{"beta",beta},{"alpha",0.5}});
cout<<"----------------------------------"<
#include "EQ_EDIT.hpp"
using namespace std;
int main()
{
EQ_EDIT func_eq;
double x = 10;
double beta = 1.5;
func_eq.setVar({{"x",x},{"beta",beta},{"alpha",M_PI/4}});
func_eq.setEquation("-(x^2/2)+20+2*beta+sin(alpha)");
double value = func_eq.getValue();
cout<<"----------------------------------"<