A Powerful Function Parser

.

The inspiration to write this code was to have an easy-to-use parser for functions given as string. You have a string like

"cos(x)-7*x/(1+x)"
and you want to compute some values, maybe for displaying the graph of the function. You can write code like this:

CFunction<long double>* fkt = 
  CFunction<long double>::Parse("cos(x)-7*x/(1+x)");

long double y = fkt->Execute(1.5);

There are lots of definitions in the background, but the result is easy and fast! There is a one-time pasing step to construct the function tree, and function evaluations are only calls of standard math functions like sin, +, *, sqrt. When you want to know details about the implementaion, you should look into the source code. It would be too complex to describe the parsing algorithm here.

Downloads

Download demo source - 50 Kb
Download demo application - 32 Kb


Comments

  • Can I Take Shilajit Capsules To Cure Erectile Dysfunction?

    Posted by afoeffifielm on 06/21/2013 02:12am

    Natural Impotence Cure- Naturally Curing Your Erectile Dysfunction Can Help To Conserve Your Life? If you opt for discretion, you can fill the prescription at a reliable on-line pharmacy [url=http://rxhealth.pw ] countries where you can buy viagra over the counter [/url] see far more Lifelike Cures for Erectile Dysfunction Explained

    Reply
  • Just OK

    Posted by Legacy on 01/14/2004 12:00am

    Originally posted by: Gerhalt

    very ok!

    Reply
  • Very good, but ...

    Posted by Legacy on 10/16/2003 12:00am

    Originally posted by: Alexander Magola

    My english is not good, but i want to say that this code is very good. I like idea of this author, but this code is not very fast. My own similar code is faster three times more than it. Although, my code is not fastest. ;)
    Best regards.

    Reply
  • How about adding new functions to this as plug-ins

    Posted by Legacy on 07/03/2003 12:00am

    Originally posted by: Harshdeep Singh

    Great Job
    I was thinking about giving option of adding new functions as plug-ins (dll?)
    That would make it cooler.
    And I would love to see an explanation of the code.
    Harshdeep

    Reply
  • Vergleich Fl�chenberechnungen

    Posted by Legacy on 03/15/2003 12:00am

    Originally posted by: Oswald Ruckriegel

    Zun�chst: ein Spitzenprogramm. Meine Gratulation
    Habe es in mein Programm (VC++5.0) eingebaut.
    Stelle fest: am genauesten rechnet
    1. Mittelpunktsregel
    2. Integration mit Trapezregel
    3. Simpson ( hier Abweichungen von 1) bis zu 10 %.
    Beispiel: sin(x)/x ( f�r x= 0 bis x = 3)
    nur 1) berechnet richtig, 2) und 3) keine Berechnung m�glich.

    Warum ?

    Reply
  • The console app closes immediately

    Posted by Legacy on 11/13/2002 12:00am

    Originally posted by: The Big Cat

    Hi there may not be a bug in the program but when i type the
    
    f(x)=_ in the console demo application then
    when i enter x and then press enter the console application closes .
    how am i to verify the results?Maybe the code should be
    modified to ask another f(x) at the end so the window wouldn't close and the user can test another function.
    You could just put in a prompt ,say 'Quit Y?N ?'..
    Otherwise good ,i've gotto see the code..

    Reply
  • Error using sqrt

    Posted by Legacy on 09/04/2002 12:00am

    Originally posted by: Holger

    There is an error in the GetDerivate() Method of the class CSqrt1Function. The "1/2" expression becomes 0. For correct behaviour replace it with "1.0/2.0" or with "0.5" (see code below).
    
    

    Thanks for this great piece of code.

    Regards, Holger.


    template <class T>
    class CSqrt1Function : public CFunction<T>
    {
    ...
    virtual CFunction<T>* GetDerivate() const {return new CDivL0Function<T>(1/2, new CSqrt1Function<T>);};
    };

    Reply
  • Found an error

    Posted by Legacy on 08/20/2002 12:00am

    Originally posted by: Lee


    The expression: x^2+3x-5

    was parsed to: x^2+3-5

    Reply
  • few

    Posted by Legacy on 07/10/2002 12:00am

    Originally posted by: few

    So fucking cool thing!

    Reply
  • A Powerful Function Parser

    Posted by Legacy on 04/10/2002 12:00am

    Originally posted by: Nikhil

    Impressive....but comments are not clear
    and extensive....Comments in English would be a definite help!!!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

  • On-demand Event Event Date: February 12, 2015 The evolution of systems engineering with the SysML modeling language has resulted in improved requirements specification, better architectural definition, and better hand-off to downstream engineering. Agile methods have proven successful in the software domain, but how can these methods be applied to systems engineering? Check out this webcast and join Bruce Powel Douglass, author of Real-Time Agility, as he discusses how agile methods have had a tremendous …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date