S
S
Satiata2015-01-11 12:26:11
C++ / C#
Satiata, 2015-01-11 12:26:11

Move text to variable for use in function?

There is a program for calculating integrals (not the point). I enter various data into different fields and according to a certain algorithm, it should read me the answer.
Well, here it is. It reads the first three values ​​normally, because they are numbers (the first two types are doubles and the third is int).
In the fourth box, I enter an integrable expression. Those. in fact, this is a piece of text, which in a certain place should be inserted into one of the functions and the whole rhyme will go on. Attention to the question: how and where can I write it down? So far it looks like:
x = Convert::ToDouble(intText->Text);
but, of course, it does not work, because it is fundamentally wrong. Because, in fact, climbs to the function where it is used. I used this variable like this.
There is a function that looks like

double f (double x1)
{
return x1;
}

Those. I call it F = f(x), thereby passing a value into it.
But! This, of course, does not happen, because the expression, even the simplest one, is not written to the variable at the very beginning (the program stops execution and the variables starting from this very x are equal to zero)
The general view of the code is as follows:
private: System::Void otvetButton_Click(System::Object^  sender, System::EventArgs^  e) {

         double a, b, h, I, F, x;
         int n;

           a = Convert::ToDouble(aPredelText->Text);
           b = Convert::ToDouble(bPredelText->Text);
           n = Convert::ToInt32(nText->Text);
           x = Convert::ToDouble(intText->Text);

           F = f(x);
           I = Integr(a, b, n);

           otvet->Text = I.ToString("n");

       }

Where f and Integral are functions written in separate files.
Hence the question: how should the variable be counted and in what place so that everything is fine and the algorithm continues to run?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2015-01-11
@Satiata

A good option: You need to compile your sub-integral function, and then dynamically link it with your program:
The same thing, only in profile - take OpenCL. Then all the work of compiling the kernel and linking will be hidden from you, and the calculations can be done on the GPU
Bad option: write your own math function interpreter (using the marshalling yard algorithm). It will be a wild brake.
The third option is to throw your program in the trash and count in Maxima, Maple, Octave and other smart programs. Although it is also slow.
And yes, what kind of bike do you consider the integral? Because it is rare when a self-made integrator can compete with GSL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question