How to use mathematical expression in string format as a function

Hello everybody!

I'm writing program solving differential equations. I'd like to have an option of
inserting my equation through standard input. I define an equation by
the code:

1
2
3
4
5
void equation( const state_type &x , state_type &dxdt , const double t )
{
    dxdt[0]=x[1];
    dxdt[1]=-3./t*x[1];
}


How to convert string "-3./t*x[1]" or "sin(x[1]*t)/t+tanh(x)" to something which I can use in my "void equation" function. Is there any library which can that easily for me?
Last edited on
1. Get a library to do it for you (unlikely your choice but still)
2. Parse the string:
Get a book on parsing
Google Parsing


Hope it helps
Parsing can be an ugly process, and kind of frustrating. I think regex, which is C+11, might help with this. Don't quote me, I know very little about regex
Topic archived. No new replies allowed.