Skip to content

ggolish/DefiniteIntegralApproximator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of Contents

  1. Overview
  2. Highlights
    1. Extendable Equation Parser
    2. Flexible Mesh Size
    3. N-Dimensional Integrals
  3. Usage
    1. Input
      1. Supported Operators
      2. Supported Functions
    2. Build
    3. Command Line Arguments
    4. Default Behavior
    5. run_tests.sh

Overview

A program for approximating definite integrals, written for MATH 613 - Applied Linear Algebra course at Indiana State University. The program uses Simpson's one-third rule for the approximation:

equation

This program uses the extended form of Simpson's rule for approximating n-dimensional integrals.

Highlights

The following are some implementation details that are of note.

Extendable Equation Parser

The program contains a custom tokenizer (scanner.c) and parser (parser.c) that converts an infix input equation to an abstract syntax tree (ast.c). Representing the equation as an AST allows for computing the equation on many values efficiently. It is also a simple matter to extend the scanner and parser to handle new operators and functions.

Flexible Mesh Size

The program uses an adaptive approach for choosing the mesh size. Starting at a low value, the mesh size is doubled until the approximation converges to within four decimal places (simpson.c). The mesh size is part of the output of the program.

N-Dimensional Integrals

The program was built from the ground up to accomadate n-dimensional integrals. The program accepts as input the integral dimension and then a list of integral specifications that consist of the start and end of the integral, as well as the variable the integral should be performed on (args.c, simpson.c). See the Usage section for more details.

Usage

Input

The program accepts as input an infix equation that can contain numbers, functions, one-character variables, and operators.

Supported Operators

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)
  • ^ (exponentiation)
  • ( (open parenthesis)
  • ) (closing paranthesis)

Supported Functions

  • sin (sine)
  • cos (cosine)
  • tan (tangent)
  • ln (natrual logarithm)
  • sqrt (square root)

Build

To build the project, run the following command in the root directory of the project:

make integrate

This command produces the target executable integrate.

Command Line Arguments

  • -n : Specifies the integral dimension as .
  • -p : Specifies the list of integral specifications. A colon (:) separated list of comma (,) separated specifications e.g. 0,3,x:0,3,y specifies a double integral in which the variable x (the outer integral) is integrates over the range [0, 3] and variable y (the inner integral) is integrated over the range [0, 3].
  • -e : Specifies the equation to integrate.

Default Behavior

If no command line arguments are given, the program will expect the user to first input the integral specification, then the equation. One or the other may be passed as command line arguments, while the other is read from stdin. For example,

./integrate 
0 3.14 x
sin(x)

is the stdin way of specifying (\int_0^\pi \sin(x) dx). The command line way would be:

./integrate -n 1 -p `0,3.14,x' -e `sin(x)'

run_tests.sh

Run the interactive program run_tests.sh to perform some test examples using the program. The test examples are as follows:

  • equation
  • equation
  • equation
  • equation
  • equation

About

Calculates n-dimensional definite integrals using Simpson's Rule.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors