read analytical expression in a text file

Hello everybody !

I have built a C++ code last year for my Master's Thesis.
Now, I would like to make this code easier to use for an external user.
The idea is that the external user enters in .txt files the different inputs of the model.
For the .txt files wherein information is just double numbers, there is no problem for me. But, in one of these .txt files, we have to introduce the analytical expression of one my boundary conditions. So for example, I have to read the following expression :

50.*exp(x[i]+y[i])

where x and y are one-dimensionnal arrays in my main code.
So, I would like read this expression and after obtain its value that I'll register in an other variable as a double number.

Sorry for my approximative english... I hope it's quite understandable...

Is there anyone that can helps me about this problem.

Thaks a lot for your explanation!
closed account (j3bk4iN6)
is the expression one of recursion or a nested loop? Are you asking how to explain it in lay-mans terms for a type of help command? what are the arrays derived from would help determine the functions purpose. Are you saying you wanna use the same exp() function to register a different variable type, well that would be solved by using a function template, or function overloading.

template<typename T> T exp( T x, T y)
{}

I guess as I dig deeper into it, I see the problem why not do *exp(*exp(x[i] + y[i]), z) if *exp generates a double number than have z be the second variable.
Last edited on
Hello abilify,

I would like to known how carry out it in practice, so the command lines...

In fact, x[i] with i=0=>50 is known, y[i] with i=0=>30 is known. It doesn't matter...

Suppose that x and y are simple constant double numbers whose the values are given in my main C++ code. So, it has to read the expression written in my .txt file : 50.*exp(x+y) and put this expression in a "double" variable to evaluate the value of the expression knowing x and y...

It's difficult for me to explain my problem in english...

Is it more understandable ?

Thanks...
closed account (j3bk4iN6)
Are you asking how to read the expression from the text file or how create the function like 50.*exp(x,y). When you say double do you mean two variables or the type double.
Last edited on
exp = exponential function... it hasn't to create this function because it already exists using the library math.h.

So, I would like read the expression and store it in a variable of type double...

Do you understand my problem ?
closed account (j3bk4iN6)
mathimatically its x.e+y right.
Last edited on
No because the expression in the .txt file can be modified by the user of my C++ code...
Last edited on
closed account (j3bk4iN6)
Maybe this Q/A clarifies it and will generate more responses.
Ok, thanks a lot for your help !
Topic archived. No new replies allowed.