EvalEquation

This function can be used to evaluate an (list of) equation(s) written as string (char-array). It is based on the Shunting-yard algorithm
ダウンロード: 126
更新 2018/8/13

ライセンスの表示

This function can be used to evaluate an equation written as string (char-array).
The basis of the function is the Shunting yard algorithm, as in the C#
example of: https://rosettacode.org/wiki/Parsing/Shunting-yard_algorithm

The shunting-yard algorithm is a method for parsing mathematical expressions
specified in infix notation to postfix notation.


Example

result = EvalEquation( '1+2/(2*3)');
disp(result)
1.3333

or with variables,

result = EvalEquation( 'y+x/(2*3)','x',2,'y',3);
disp(result)
3.3333

Supported operators: ^ * / + - ( ) > < == >= <=
Supported functions: sqrt abs sin cos tan asin acos atan exp sign round floor ceil
max(a,b) min(a,b)
Supported constants: pi
************************************************************************************************************************************

This function EvalEquationScript can be used to evaluate a list of equations
and finaly return one of the variables as result

result = EvalEquationScript(script, output_variable_name, variable1, value1, variable2, value2,....)

Example,

script = cell(5,1);
script{1}='a=1';
script{2}='b=a*2';
script{3}='%Calculate max of a,b time x';
script{4}='x=x+a';
script{5}='c=max(a,b)*x';

result = EvalEquationScript(script,'c','x',3);

引用

Dirk-Jan Kroon (2024). EvalEquation (https://www.mathworks.com/matlabcentral/fileexchange/68458-evalequation), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2018a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersString Parsing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.0.7

Fixed bug in parsing a number like -1.e-31

1.0.6

Added text

1.0.5

Added the missing file..

1.0.4

Added multi-line support in EvalEquationScript

1.0.3

Now explicit support of arrays as value of an input variable.
Also made compatible with Matlab Coder

1.0.2

Support for more operators and functions

1.0.1

Added supported functions: sqrt abs sin cos tan asin acos atan exp

1.0.0