https://github.com/lovasoa/lagrange-cpp
Lagrange interpolation polynomials in C++11
https://github.com/lovasoa/lagrange-cpp
Last synced: 7 months ago
JSON representation
Lagrange interpolation polynomials in C++11
- Host: GitHub
- URL: https://github.com/lovasoa/lagrange-cpp
- Owner: lovasoa
- License: apache-2.0
- Created: 2016-09-28T11:37:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-03-01T07:24:41.000Z (almost 8 years ago)
- Last Synced: 2025-04-04T21:01:38.281Z (9 months ago)
- Language: C++
- Size: 6.84 KB
- Stars: 10
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lagrange-cpp
Lagrange interpolation polynomials in C++11
## Usage
Let's create a polynomial function that passes through the points (0,0) (2,4) (10,100).
#### Compile the files
```sh
$ make
```
#### Create a file that contains the point coordinates
Une point per line. X and Y coordinates are separated by a space.
```sh
$ cat > points.txt
0 0
2 4
10 100
```
#### Generate the polynomial coefficients
Let's write the coefficients to a file named `polynom.txt`.
```sh
$ ./coeffs < points.txt > polynomial.txt
$ cat polynomial.txt
0
0
1
```
We can see that the generated polynomial function is `f : x -> 0 + 0*x + 1*x^2`. This is the square function, as expected.
#### Evaluate the resulting function
Let's evaluate the function between 0 and 10.
```sh
$ seq 0 10 | ./poly_exec polynomial.txt
0
1
4
9
16
25
36
49
64
81
100
```