# Evaluating Sigma Notation

This topic is 5150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

As an interesting project for tonight, I thought I'd write a program to experiment using sigma notation to find the area under a curve. The problem I've run into now is evaluating the summand(the formula, for example: .1*x^2). If the user enters the summand as a string, how do I then break it down into calculatable parts? If i have the string ['0']['.']['1']['*']['(']['x']['^']['2'][')'], how do I evaluate it so I can plug dx in for x in my main for loop? I hope you all can understand my question, thanks.
#include <iostream.h>

#define dx 0.00001

double Sigma ( double , double , double );

int main(){
double lower, upper;
char summand [50];

cout << "Enter Lower Limit: ";
cin >> lower;
cout << "Enter Upper Limit: ";
cin >> upper;
cout << "Enter Summand (Variable must be x): ";
cin >> index;

//Sigma( lower, upper, summand );

return 0;
}

double Sigma( double lower, double upper, char summand [] ){
//evauluate summand

//find summation
for ( int x = lower , x <= upper , x += dx ){

}

return 0;
}



##### Share on other sites

First of all, you need a lexical analyzer to convert your string into a series of tokens such as NUMBER, TIMES, LPAREN, IDENTIFIER, etc...

Then you need a parser to conver the tokens into a syntax tree. Evaluating the formula would consist of walking the tree in infix order and substituting values whenever you hit a IDENTIIFIER tree node.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632995
• Total Posts
3009774
• ### Who's Online (See full list)

There are no registered users currently online

×