Skip to content

Commit 0e57347

Browse files
authored
Merge pull request #4 from kmolan/refactoring
Refactoring
2 parents 3045f0e + 2ed682d commit 0e57347

36 files changed

+5937
-3095
lines changed

.github/workflows/build-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ jobs:
1919
- uses: actions/checkout@v4
2020
- name: Build
2121
run: cargo build --verbose
22-
- name: Run tests
22+
- name: Run tests default
2323
run: cargo test --verbose
24+
- name: Run tests heap
25+
run: cargo test --features heap --verbose

BENCHMARKS.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
- [1. Single variable Differentiation](#1-single-variable-differentiation)
2+
- [2. Multi variable Differentiation](#2-multi-variable-differentiation)
3+
- [3. Iterative integration methods](#3-iterative-integration-methods)
4+
- [4. Gaussian Quadrature methods](#4-gaussian-quadrature-methods)
5+
6+
## 1. Single variable Differentiation
7+
8+
Derivative | Approximation error | Notes |
9+
-------------------------------------- | ------------------- | ---------------------------------------------- |
10+
$$\mathrm{d}(Sin(x))\over\mathrm{d}x$$ | 1e-12 | Trivial case to showcase accuracy levels |
11+
$$\mathrm{d}(x^2 Sin(x))\over\mathrm{d}x$$ | 1e-10 | Can easily handle product rule with high accuracy |
12+
$$\mathrm{d^2}(x^2 Sin(x))\over\mathrm{d}x^2$$ | 1e-7 | Approximation errors increase with higher order derivatives |
13+
$$\mathrm{d^3}(x^2 Sin(x))\over\mathrm{d}x^3$$ | 7e-4| Approximation errors increase with higher order derivatives |
14+
15+
## 2. Multi variable Differentiation
16+
17+
Derivative | Approximation error | Notes |
18+
-------------------------------------- | ------------------- | ---------------------------------------------- |
19+
$$\mathrm{d^2}(x + y + z)\over\mathrm{d}x\mathrm{d}y$$ | 1e-15 | Trivial case to showcase accuracy levels |
20+
$$\mathrm{d^2}(ySin(x) + xCos(y) + xye^z)\over\mathrm{d}x^2$$ | 1e-7 | Can easily handle complex equations with high accuracy |
21+
$$\mathrm{d^2}(ySin(x) + xCos(y) + xye^z)\over\mathrm{d}x\mathrm{d}y$$ | 2e-6 | Approximation errors increase for mixed derivatives |
22+
$$\mathrm{d^3}(ySin(x) + xCos(y) + xye^z)\over\mathrm{d}x^2\mathrm{d}y$$ | 7e-4| Approximation errors increase with higher order derivatives |
23+
24+
25+
## 3. Iterative integration methods
26+
27+
Overall, it was found that in terms of accuracy, both Booles and Trapezoidal methods give the highest accuracy, but Booles is able to converge faster than trapezoidal, i.e. it needs fewer iterations and takes less compuatational resources. Simpsons method was found lacking in accuracy, and may be deprecated in future due to poor performance.
28+
29+
Booles:
30+
31+
Integrand | Approximation error | Notes |
32+
-------------------------------------- | ------------------- | ------------------------------------------------------- |
33+
$$\int_0^2 2x \mathrm{d}x$$ | 1e-14 | Trivial Integration to showcase accuracy levels |
34+
$$\int_0^1 (2x + yz) \mathrm{d}x$$ | 1e-30 | High accuracy for simple multivariable integrals |
35+
$$\int_0^1\int_0^1\int_0^1 (yz x^2 e^x) \mathrm{d}x\mathrm{d}x\mathrm{d}x$$ | 2e-3 | Can handle integration by parts easily|
36+
$$\int_0^1\int_0^1 (x\over\sqrt{x^2 + y^2}) \mathrm{d}x$$ | 2e-3 | Accuracy falls for more complex equations |
37+
$$\int_0^1\int_0^1 (Sin(x) + ye^z) \mathrm{d}x\mathrm{d}y$$ | 8e-2 | Struggles for overly complex equations |
38+
39+
Simpsons:
40+
41+
Integrand | Approximation error | Notes |
42+
-------------------------------------- | ------------------- | ------------------------------------------------------- |
43+
$$\int_0^2 2x \mathrm{d}x$$ | 5e-3 | |
44+
$$\int_0^1 (2x + yz) \mathrm{d}x$$ | 5e-3 | |
45+
$$\int_0^1\int_0^1\int_0^1 (yz x^2 e^x) \mathrm{d}x\mathrm{d}x\mathrm{d}x$$ | 2e-3 | Can handle integration by parts easily|
46+
$$\int_0^1\int_0^1 (x\over\sqrt{x^2 + y^2}) \mathrm{d}x$$ | 2e-3 | Accuracy falls for more complex equations |
47+
$$\int_0^1\int_0^1 (Sin(x) + ye^z) \mathrm{d}x\mathrm{d}y$$ | 8e-2 | Struggles for overly complex equations |
48+
49+
50+
Trapezoidal:
51+
52+
Integrand | Approximation error | Notes |
53+
-------------------------------------- | ------------------- | ------------------------------------------------------- |
54+
$$\int_0^2 2x \mathrm{d}x$$ | 1e-14 | Trivial Integration to showcase accuracy levels |
55+
$$\int_0^1 (2x + yz) \mathrm{d}x$$ | 1e-30 | High accuracy for simple multivariable integrals |
56+
$$\int_0^1\int_0^1\int_0^1 (yz x^2 e^x) \mathrm{d}x\mathrm{d}x\mathrm{d}x$$ | 4e-4 | Can handle integration by parts|
57+
$$\int_0^1\int_0^1 (x\over\sqrt{x^2 + y^2}) \mathrm{d}x$$ | 2e-1 | Struggles for complex equations |
58+
$$\int_0^1\int_0^1 (Sin(x) + ye^z) \mathrm{d}x\mathrm{d}y$$ | 8e-1 | Struggles for complex equations |
59+
60+
61+
## 4. Gaussian Quadrature methods
62+
63+
With gaussian quadratures, there is no one 'objective' better answer. Each quadrature rule is designed to solve a specific integrand type. For most integrands with finite limits, Gauss-Legendre is the most suitable choice. For infinite limits, Gauss-Hermite or Gauss-Laguerre is a better fit. However, all these models are only suitable for polynomial equations. For non-polynomial equations, their performance falls very fast.
64+
65+
Gauss-Legendre
66+
67+
Integrand | Approximation error | Notes |
68+
-------------------------------------- | ------------------- | ------------------------------------------------------- |
69+
$$\int_0^2 4x^3 - 3x^2 \mathrm{d}x$$ | 1e-14 | Trivial Integration to showcase accuracy levels |
70+
$$\int_0^1 (2x + yz) \mathrm{d}x$$ | 1e-30 | High accuracy for simple multivariable integrals |
71+
$$\int_0^1\int_0^1 (x^3 y + y^3 z) \mathrm{d}x\mathrm{d}y$$ | 1e-30 | Can handle integration by parts easily|
72+
$$\int_{0}^1 (Sin(x) - \sqrt{x})e^{-x} \mathrm{d}x$$ | 1e-2 | Poor performance for non-polynomial integrands |
73+
74+
75+
Gauss-Laguerre
76+
77+
Integrand | Approximation error | Notes |
78+
-------------------------------------- | ------------------- | ------------------------------------------------------- |
79+
$$\int_{0}^\infty x^2 e^{-x} \mathrm{d}x$$ | 1e-30 | Trivial Integration to showcase accuracy levels |
80+
$$\int_{0}^\infty (4x^3 - 3x^2)e^{-x} \mathrm{d}x$$ | 1e-12 | High accuracy for more complicated integrands |
81+
$$\int_{0}^\infty (Sin(x) - \sqrt{x})e^{-x} \mathrm{d}x$$ | 1e-2 | Poor performance for non-polynomial integrands |
82+
83+
Gauss-Hermite
84+
85+
Integrand | Approximation error | Notes |
86+
-------------------------------------- | ------------------- | ------------------------------------------------------- |
87+
$$\int_{-\infty}^\infty x^2 e^{-x^2} \mathrm{d}x$$ | 1e-30 | Trivial Integration to showcase accuracy levels |
88+
$$\int_{-\infty}^\infty (4x^3 - 3x^2)e^{-x^2} \mathrm{d}x$$ | 1e-12 | High accuracy for more complicated integrands |
89+
$$\int_{-\infty}^\infty (Sin(x) - \sqrt{x})e^{-x^2} \mathrm{d}x$$ | 1e-1 | Poor performance for non-polynomial integrands |
90+

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "multicalc"
3-
version = "0.4.1"
3+
version = "0.5.0"
44
authors = ["akathail <[email protected]>"]
55
edition = "2021"
66
description = "Rust scientific computing for single and multi-variable calculus"

0 commit comments

Comments
 (0)