Unsolved Correcting data by equation parameters
-
Hello I have some data in my program and I want correct it.
For example:
x = 1,012;I need command line where I could enter some like this:
x=0.98*x+0.1;
or like this
x=(1.3x+1)^2;with the mathematic sequence of actions
-
Hi,
What do you mean by "command line" ?
-
Maybe QLineEdit it doesn't matter, widget to input String.
-
Are you looking to implement something like SpeedCrunch ?
-
I need something simple. Maybe only y=ax+b;
-
@erytcg
and you want to parse it and execute it ?
There are many examples of a small calculator on the net. its a common
text book task. -
-
any example for calculating without buttons? only input line.
-
@erytcg
The link VRonin gave is without buttons.
Just the pure way to do it. -
It is possible to use varibales names in this?
-
@erytcg
yeah should be as you can just treat the variable as a number and substitute when you calculate the result.
it also support operator precedence but stuff like
x=(1.3x+1)^2;
will require somewhat a more data complex model to handle flawless i think. -
And one more question this algorithm is fast? I have a looot of data and I have to calculate it in real time:D
-
@erytcg
well, it's minimal and makes handling the expressions easier (for the programmer) but since it is sort of a text parser, not that fast but for small expressions its not wildly time consuming. -
Depending on what you need to handle, maybe using something like
https://github.com/ArashPartow/exprtk ? -
Can I use QScriptEngine?
But I have problem
#include <QtScript/qscriptengine.h> #include <QtScript/qscriptvalue.h> QString x = ui->correctDataLine->displayText(); QScriptEngine myEngine; QScriptValue x2 = myEngine.evaluate(x); qDebug() << x2.toNumber(); undefined reference to `_imp___ZN13QScriptEngineC1Ev'
-
@erytcg
do you have
QT += script
in the pro file? -
Ok thanks my bad:(
Do you think can I use this with variables names? -
@erytcg
What do you mean with "variables names" ?
To put inside QScriptEngine or what you wanna do with variables? -
Ah I see where you are aiming :)
Yes you can use it for your use case. Depending on the complexity you need.
http://www.informit.com/articles/article.aspx?p=1405559&seqNum=2
Using script with js to play calculator. -
I have this
And I have variable name: x. I put to QLineEdit 1+x * 3
And script automatically calculate new value of x.
x = 1+x*3