Jump to content

math functions?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
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) ???

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
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
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Do you mean something like this?
#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.

#4
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
I need very simple math expression parser.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users