Hello,
How can I convert math an string to math function for example
f(x)=cos(x)+sin(x)+x^2+x^1
and also log(x) ???
3 replies to this topic
#1
Posted 09 March 2011 - 07:09 AM
|
|
|
#2
Posted 09 March 2011 - 01:28 PM
Let me get this straight - you want to take a string as input and evaluate it to some floating-point number? If that's the case, you're going to need to use regular expressions and string parsing. If you have no experience with that, I suggest you find some alternative method.
sudo rm -rf /
#3
Posted 09 March 2011 - 05:29 PM
Do you mean something like this?
If you do mean evaluating, tokenizing would be the way to go rather than language parsing (regular expression sets)
#include <stdio.h>
#include <math.h>
double f1(double);
int main(void) {
printf("%lf", f1(2.43));
}
double f1(double x) {
//cos(x)+sin(x)+x^2+x^1
return
cos(x) + sin(x) + pow(x, 2) + pow(x, 1);
}
If you do mean evaluating, tokenizing would be the way to go rather than language parsing (regular expression sets)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#4
Posted 09 March 2011 - 07:12 PM
I need very simple math expression parser.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









