Skip to content

Simulation to compute area under a function between bounds.

License

Notifications You must be signed in to change notification settings

Potato-Development/sim-line-area

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sim-line-area

Converging area under a generic function between an upper and lower bound.

image

Introduction

The program finds the area under (or over) a generic function, $f(x)$ and $a, b$ as the upper and lower bounds to find $S$. It uses $n$ slices of length $b-a$; increasing $n$ will increase the accuracy of $s$ as it converges to the real area. This leaves $n$ rectangles which overestimate $S$, each

$$f(a + \frac{b}{n} k)$$

high, and

$$\frac{b-a}{n}$$

wide, where $k$ (1..=n) represents which rectangle.

This leaves us with

$$ \sum_{k=1}^{n} f\left(a + \frac{b}{n} k\right) \cdot \frac{b}{n} $$

to find the total area, which evaluates to

$$ \sum_{k=1}^{n} \left((a + \frac{b}{n} k)m + c\right)\cdot \frac{b}{n} $$

for $y = mx + c$.

Installation

Prebuilt binaries for Linux amd64, Linux aarch64 and Windows 64-bit are provided in releases. If anyone can cross-compile for MacOS, that would be greatly appreciated; I build and compile on a Raspberry Pi. If none of the binaries support your architecture, the binaries don't work, or you want to build from source, then clone the repo for the source code. The code is a single source file at:

/path/to/linear-line-area/src/main.cpp

It should compile with any toolchain without warnings. If you want to use my custom Makefile, you can find it in the project folder /path/to/linear-line-area/Makefile. Targets all, clean, and then individual targets for your architecture should be available. You may have to create the target folder yourself, please read the code carefully.