As the title said, this is a project i will be working on now that i finished my university finals.
Basically its an integrator. The user inputs the function he wants to integrate on a specific interval. the program gives him the result ( done a lot before i know but i never said i was inventing something )
Progress so far :
Basically nothing, all i did is create an integrator that reads from the user 2 values ( the interval ) and calculates the value of exp(x) on that interval.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <math.h>
#include "conio.h"
using namespace std;
const double n=1000000;
double f(double x)
{
return ( exp(x) );
}
int main(){
char answ;
double j;
double a,b;
double g=0;
cout<<"Enter integration limits 'a' and 'b': \n";
cin>>a;
cin>>b;
for(j=1;j<=n;j++)
{
g=g+( f(a+(b-a)/n*j) * (b-a)/n );
}
cout<<"The integral's value over ["<<a<<";"<<b<<"] is: "<<g;
getch();
return 0;
}
PS : I code in Visual studio 2010 ultimate ( which justifies the headers ... )
It is basic knowledge in integration, the integral is the sum of the area of the divided parts under the function
This is what this code does basically.
That is basically step 1 of the project, what to do next :
1) make it general .. able to calculate any integral over any area .. basically just instead of the " f " function :
double f(double x)
{
return ( exp(x) );
}
I have to make a function able to analyse user input and transform it to code readable by the compiler so that it could work.
2) Provide a representation of the function
3) Go out of the box ( biggest part of the project actually ), letting the program to calculate non limited integrals, giving the primitive function in terms of the variable x ( or any user inputted variable ) .... and represent it in a graph
4) Go mobile !
I intend to turn this thing when its done into a mobile application ( if it is possible ) .... When all this is done.. it'll be time to learn how to do a graphical interface ...
So basically that's the plan. Now, since i will be working on this step by step, any help on step 1 will be greatly appreciated.
The thing first is to create a function that reads the user input and create a " return " with the function itself with the appropriate variables and constants. I am sure it is possible but i have no leads to search how it can be done.
I thought about this of course, create a string x; user inputs " cos ( 2 x + 5 ) * x ^ 2 " for example, the program scans it and instead of :
double f(double x)
{
return ( exp(x) );}
It should become :
return ( cos ( 2 * x + 5 ) * x * x );
How? I do not know ... Any ideas ?