Answered by:
Algorithm to calculate the value of a function f (x)
Question

Answers

For use with LDMath.Evaluate(2) you'll have to transform your syntax (eg. ^ operator, log) to JScript or C# (2).
And in the function string replace your variable eg. 'x' with ' "+ x + " '.
x = 3.14
str = "Math.Pow("+ x +" + 1, 3 + Math.Pow(Math.Log10("+ x +"), 2))" ' base 10 lg
TextWindow.WriteLine("f(x) = "+ str)
TextWindow.WriteLine("Eval f("+ x +") = "+ LDMath.Evaluate(str))
TextWindow.WriteLine("Eval2 f("+ x +") = "+ LDMath.Evaluate2(str))
TextWindow.WriteLine("")PS: Update
x = 3.14
fx = "Math.Pow(x + 1, 3 + Math.Pow(Math.Log10(x), 2))" ' base 10 lg
TextWindow.WriteLine("f(x) = "+ fx)
str = LDText.Replace(fx, "x", x)
TextWindow.WriteLine("f("+ x +") = "+ str)
TextWindow.WriteLine("")
TextWindow.WriteLine("Eval: f("+ x +") = "+ LDMath.Evaluate(str))
TextWindow.WriteLine("Eval2: f("+ x +") = "+ LDMath.Evaluate2(str))
TextWindow.WriteLine("")Edit:
* For base 10 logarithm 'log' use Math.Log10
* For base e logarithm 'ln' use Math.Log
in the expression string, Math class
 Proposed as answer by Nonki TakahashiModerator Wednesday, August 9, 2017 6:17 AM
 Edited by Pappa LapubEditor Friday, August 11, 2017 12:09 PM
 Marked as answer by Nonki TakahashiModerator Saturday, August 19, 2017 10:24 AM

In clumsy english:
Parsing is what happens in the samples (from LitDev and NaochanON) linked from here Calculation of the value in a variable
To evaluate a math. expression like "2 + 3" you parse through that string with eg. Text commands, find and pick out all the numers (2, 3) , operators (+, , /, *. ^, %) , brackets (, ) , ev. function names (log, ln, tan etc), break it into pieces, recombine them to calculate the result step by step in correct math. priority like ^, *, /, %, +,  from the inner to outer level. Order_of_operations (Wiki)
Better read here: Parsing (Wiki)
Math.Pow is the command for the '^operator' in C# and/or JScript (like Math.Power in SB)
 Proposed as answer by Nonki TakahashiModerator Wednesday, August 9, 2017 6:23 AM
 Marked as answer by Nonki TakahashiModerator Saturday, August 19, 2017 10:24 AM
All replies

I think you have to write those few lines yourself, e.g
x=3.14 lg=Math.Log(x) exp=3+lg*lg answer= Math.Power(x+1,exp)
If you need to do this for more functions, you can try to write a parser to do this ;)
EDIT: look at the formula calculator in https://social.msdn.microsoft.com/Forums/enUS/cb8c8e01dd264260822fb9fa4fbd67a6/calculatorusingformula?forum=smallbasic for ways to do this.
Jan [ WhTurner ] The Netherlands
 Edited by WhTurner33Editor Tuesday, August 8, 2017 1:14 PM
 Proposed as answer by Nonki TakahashiModerator Wednesday, August 9, 2017 6:17 AM

For use with LDMath.Evaluate(2) you'll have to transform your syntax (eg. ^ operator, log) to JScript or C# (2).
And in the function string replace your variable eg. 'x' with ' "+ x + " '.
x = 3.14
str = "Math.Pow("+ x +" + 1, 3 + Math.Pow(Math.Log10("+ x +"), 2))" ' base 10 lg
TextWindow.WriteLine("f(x) = "+ str)
TextWindow.WriteLine("Eval f("+ x +") = "+ LDMath.Evaluate(str))
TextWindow.WriteLine("Eval2 f("+ x +") = "+ LDMath.Evaluate2(str))
TextWindow.WriteLine("")PS: Update
x = 3.14
fx = "Math.Pow(x + 1, 3 + Math.Pow(Math.Log10(x), 2))" ' base 10 lg
TextWindow.WriteLine("f(x) = "+ fx)
str = LDText.Replace(fx, "x", x)
TextWindow.WriteLine("f("+ x +") = "+ str)
TextWindow.WriteLine("")
TextWindow.WriteLine("Eval: f("+ x +") = "+ LDMath.Evaluate(str))
TextWindow.WriteLine("Eval2: f("+ x +") = "+ LDMath.Evaluate2(str))
TextWindow.WriteLine("")Edit:
* For base 10 logarithm 'log' use Math.Log10
* For base e logarithm 'ln' use Math.Log
in the expression string, Math class
 Proposed as answer by Nonki TakahashiModerator Wednesday, August 9, 2017 6:17 AM
 Edited by Pappa LapubEditor Friday, August 11, 2017 12:09 PM
 Marked as answer by Nonki TakahashiModerator Saturday, August 19, 2017 10:24 AM


In clumsy english:
Parsing is what happens in the samples (from LitDev and NaochanON) linked from here Calculation of the value in a variable
To evaluate a math. expression like "2 + 3" you parse through that string with eg. Text commands, find and pick out all the numers (2, 3) , operators (+, , /, *. ^, %) , brackets (, ) , ev. function names (log, ln, tan etc), break it into pieces, recombine them to calculate the result step by step in correct math. priority like ^, *, /, %, +,  from the inner to outer level. Order_of_operations (Wiki)
Better read here: Parsing (Wiki)
Math.Pow is the command for the '^operator' in C# and/or JScript (like Math.Power in SB)
 Proposed as answer by Nonki TakahashiModerator Wednesday, August 9, 2017 6:23 AM
 Marked as answer by Nonki TakahashiModerator Saturday, August 19, 2017 10:24 AM

Excuse ignorance.
What is it:
 Parser
 Math.Pow
Hello BluStars, I've written an article about Parser.
Nonki Takahashi