Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/louis-finegan/langrange-interpolation-c-programming-language-gnuplot
Calculate Langrange-Interpolations in the C programming language and visualise them in gnuplot.
https://github.com/louis-finegan/langrange-interpolation-c-programming-language-gnuplot
c-programming-language csv-parser gnu-linux gnuplot lagrange-interpolation lagrange-polynomial-interpolation makefile mathematics numerical-methods shellscript ubuntu
Last synced: about 1 month ago
JSON representation
Calculate Langrange-Interpolations in the C programming language and visualise them in gnuplot.
- Host: GitHub
- URL: https://github.com/louis-finegan/langrange-interpolation-c-programming-language-gnuplot
- Owner: Louis-Finegan
- License: mit
- Created: 2024-05-17T18:53:05.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-20T19:05:07.000Z (8 months ago)
- Last Synced: 2024-10-19T21:16:47.404Z (3 months ago)
- Topics: c-programming-language, csv-parser, gnu-linux, gnuplot, lagrange-interpolation, lagrange-polynomial-interpolation, makefile, mathematics, numerical-methods, shellscript, ubuntu
- Language: C
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lagrange Interpolation
Written in Ubuntu 23.04 LTS. This progam was written for GNU/Linux systems.
## Visualize lagrange polynomials with GNU plot
Implements Langrange-Interpolation in the `C programming language`. Creates complete polynomials from Node Value pairs in csv files, and creates 2 dimensional plots, using `gnuplot`, which are saved as png files.
## Dependences
1. gcc
2. gnuplot## Formulation
Lagrange interpolation is a mathematical method that finds new points $(x,y)$ in between known discrete points $(x_k, y_k)$ for $k \in \mathbb{Z}$. These new points are calculated using a polynomial $P_n(x)$ called the *Lagrange Polynomial*. The maximum value for $k$ is $n$, which is the degree of $P_n(x)$.
The *Lagrange Polynomial* is written in the following form:
$$P_n(x) = y_0L_0(x) + y_1L_1(x) + \dots + y_nL_n(x)$$
Where $L_k(x)$ is called the *Lagrange Basis*, and is written as such
$$L_i(x) = \frac{x - x_0}{x_i - x_0} \dots \frac{x - x_{i-1}}{x_i - x_{i-1}}\frac{x - x_{i+1}}{x_i - x_{i+1}} \dots \frac{x - x_n}{x_i - x_n} $$
For $n$ known points, or node, value pairs, the lagrange basis would be composed of $n$ basis vectors (Lagrange Basis).
## Example
This example takes critical points from a **sine wave**. Using Lagrange Interpolation, an approximation of the complete wave can be constucted.
The data in `data/sine.csv` is format as the following
Nodes
Values
0
0
1.5707
1
3.1416
0
4.7124
-1
6.2832
0
The program can be executed by the following
```
./run.sh [csv_file]
```For this example `csv_file` would be `sine.csv`. If the program ran successfully the following message would appear:
```
Data read successfully
Nodes: Values:
0.00 0.00
1.57 1.00
3.14 0.00
4.71 -1.00
6.28 0.00
Initializing Lagrange Interpolation
Creating plot
Plot saved as 'img/sine.png'
```And the following image is saved to `img` as a `png` file type.
## License
MIT License - see LICENSE for details.