Sign in to follow this  

Evaluating Sigma Notation

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this