Jump to content
  • Advertisement
Sign in to follow this  
MrPoopypants

Evaluating Sigma Notation

This topic is 5058 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
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!