Click here to Skip to main content
Licence CPOL
First Posted 25 Dec 2006
Views 31,357
Downloads 728
Bookmarked 36 times

Generic Mathematical Expression Framework

By | 2 Jun 2007 | Article
A Generic Mathematical Expression Framework for solving complex equations, and performing common operations on them, such as Integration, Differentiation, etc.
Sample Image - GMEF.jpg

Introduction

The ExpressionFramework namespace consists of four classes and four delegates.

  • Expression (An object representation of a parseable mathematical expression)
  • Operator (An object representation of a binary/unary operator)
  • Variable (An object representation of mathematical variables)
  • OperatorLibrary (A Key-Value collection of built-in operators. You can add yours too.)
  • Two delegates for calculation on operators (each for binary & unary)
  • Two delegates for string representation of operators with their operands

Operands might be an Expression, a Variable or a Double.

Basically, Expression is a collection of many of the above mentioned operands in a meaningful sequence.

Example Code

using System;
using ExpressionFramework;

namespace TestExpressionFramework
{
    class Program
    {
	static void Main(string[] args)
	{
	    Expression ex1 = new Expression("4*(1+x)^(1/2)"); //Answer = 12 for x=8
	    ex1.FindVariable("x").Value = 8;
	    Console.WriteLine(ex1.Calculate());
	    Expression ex2 = new Expression("(x*3)+(x^8)");   //Answer = 262 for x=2
	    ex2.FindVariable("x").Value = 2;
	    Console.WriteLine(ex2.Calculate());
	}
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Syed Hassaan Ahmed

Web Developer

Pakistan Pakistan

Member

Hi
 
I am Syed Hassaan Ahmed
Love programming & do it for fun
Developed some applications in C, C++, Java & C#
Keen to work on .Net these days

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalvery well [modified] Pinmembergajatko4:14 13 Jun '07  
GeneralSmall note [modified] Pinmembergajatko4:28 13 Jun '07  
GeneralRe: Small note PinmemberSyed Hassaan Ahmed7:40 13 Jun '07  
GeneralRe: Small note PinmemberSyed Hassaan Ahmed8:01 13 Jun '07  
GeneralRe: Small note Pinmembergajatko10:06 13 Jun '07  
GeneralA Small Bug PinmemberHina Qasim3:48 1 Jun '07  
GeneralRe: A Small Bug PinmemberSyed Hassaan Ahmed23:07 2 Jun '07  
GeneralHave you looked at other options Pinmemberavanwieren2:50 4 Jan '07  
GeneralRe: Have you looked at other options PinmemberSyed Hassaan Ahmed8:02 4 Jan '07  
GeneralRe: Have you looked at other options Pinmemberavanwieren8:14 4 Jan '07  
Generalsquare root of a complex number incorrect PinmemberChris J Saunders21:22 3 Jan '07  
GeneralRe: square root of a complex number incorrect PinmemberSyed Hassaan Ahmed7:55 4 Jan '07  
GeneralRe: square root of a complex number incorrect PinmemberChris J Saunders12:53 4 Jan '07  
GeneralRe: square root of a complex number incorrect PinmemberSyed Hassaan Ahmed17:54 4 Jan '07  
GeneralRe: square root of a complex number incorrect PinmemberChris J Saunders20:14 4 Jan '07  
GeneralVery Useful PinmemberYoong Hor Meng5:04 1 Jan '07  
GeneralRe: Very Useful PinmemberSyed Hassaan Ahmed21:37 1 Jan '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 3 Jun 2007
Article Copyright 2006 by Syed Hassaan Ahmed
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid