Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
File renamed without changes.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Integral Approximation Project

## Overview
This project focuses on the numerical approximation of integrals using Chebyshev polynomials. It implements and compares the Trapezoidal and Simpson's methods for integral approximation.
This project focuses on the numerical approximation of integrals using [Chebyshev polynomials](https://en.wikipedia.org/wiki/Chebyshev_polynomials). It implements and compares the Trapezoidal and Simpson's methods for integral approximation.

## Features
- Implements numerical integration using Trapezoidal and Simpson's methods.
Expand All @@ -10,14 +10,28 @@ This project focuses on the numerical approximation of integrals using Chebyshev

## Usage
1. Add the project folders to the MATLAB search path.
2. Use provided functions (`trapezoidal`, `simpson`, `chebyshev_combination`) for integral calculations.
3. Explore the GUI application (`examplesGUI.mlapp`) for visual demonstration and error analysis.
2. Use functions (`trapezoidal`, `simpson`) for approximate integral calculations of Chebyshev polynomials. In the project we provide `chebyshev_combination` function that represents polynomials in the form of: $$w_n(x) = \sum_{k=0}^n a_kT_k(x)U_k(x)$$ where $T_k$ is a Chebyshev polynomial of the first kind and $U_k$ - of the second kind. To use `chebyshev_combination` with `trapezoidal` (similarly `simpson`) use the following code (**a** - beggining of the integration interval, **b** - end of the integration interval, **N** - number of subintervals in the composite trapezoidal method, **coefficients** - $a_k$ coefficients for the Chebyshev polynomial):
```matlab
result = trapezoidal(a, b, N, @chebyshev_combination, coefficients)
```
3. Use functions (`trapezoidal_general`, `simpson_general`) for approximate integral calculations of any function $y = f(x)$. For example
```matlab
result = trapezoidal_general(a, b, N, @my_function)
```
4. Explore the GUI application `examplesGUI.mlapp` for visual demonstration and comparison of aprroximate results with true integrals.
5. Explore the GUI application `errorsGUI.mlapp` for error visualisations.

## Examples
- Several examples (`chebyshev_example_1`, `chebyshev_example_2`, etc.) are provided to demonstrate the effectiveness of the methods in different scenarios.
- Several examples (`chebyshev_example_1`, `chebyshev_example_2`, etc.) are provided to demonstrate the effectiveness of the methods in different scenarios. See the [report](Integral_Approximation_Report_ENG.pdf) for full description of the examples.

## Error Analysis
- The project includes a detailed analysis of the errors associated with each method, including heat maps and relative error comparisons.
- One of the takeaways is that increasing the number of subintervals (**hyperparameter N**) for both methods decreases the relative error of the approximation.

<div align="center">
<img src="img/trapezoidal_error.png" alt="Error of trapezoidal method" width="500">
<p>Figure 1: Graph of the dependence of the relative error expressed in (%) on the number of subintervals in integration by the trapezoidal method</p>
</div>

## Authors
- Hubert Kowalski
Expand Down
Binary file added img/trapezoidal_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed scripts/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/errors/kaniastyKowalskiError.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
errors = zeros(1, maxN); % Inicjalizacja wektora błędów
for N = 1:maxN % Pętla obliczająca błąd dla każdej liczby przedziałów
approxIntegral = method(a, b, N, @chebyshev_combination, coefficients); % Obliczanie przybliżonej całki
unpenalizedError = abs(trueIntegral - approxIntegral) / trueIntegral; % Obliczanie błędu bez kary
unpenalizedError = abs((trueIntegral - approxIntegral) / trueIntegral); % Obliczanie błędu bez kary
penalty = log(1+N); % Obliczanie kary kwadratowej
errors(N) = unpenalizedError + penalty; % Sumowanie błędu i kary
end
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/plotN.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
simpsonIntegral = simpson(a, b, i, @chebyshev_combination, currentCoefficients);

% Obliczenie błędów względnych
errors_s(j, i) = abs(trueIntegral - simpsonIntegral) / trueIntegral;
errors_t(j, i) = abs(trueIntegral - trapezoidalIntegral) / trueIntegral;
errors_s(j, i) = abs((trueIntegral - simpsonIntegral) / trueIntegral);
errors_t(j, i) = abs((trueIntegral - trapezoidalIntegral) / trueIntegral);
end
end
end
7 changes: 6 additions & 1 deletion scripts/tests/runTestsTable.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
% Skrypt testujący
% Skrypt generuje tabelę zawierającą prawdziwe wartości całki oraz całki
% wyznaczone numerycznie za pomocą metody Simpsona i trapezów dla 12
% przykładowych funkcji.

examples = cell(12,1);

examples{1} = struct('a', -2, 'b', 10, 'N', 50, 'Func', @chebyshev_example_1);
Expand All @@ -10,7 +15,7 @@
examples{8} = struct('a', -1, 'b', 1, 'N', 50, 'Func', @chebyshev_example_8);
examples{9} = struct('a', -5, 'b', 5, 'N', 50, 'Func', @chebyshev_example_9);
examples{10} = struct('a', -0.7, 'b', 0, 'N', 50, 'Func', @chebyshev_example_10);
examples{11} = struct('a', -1, 'b', -0.5, 'N', 50, 'Func', @example_11);s
examples{11} = struct('a', -1, 'b', -0.5, 'N', 50, 'Func', @example_11);
examples{12} = struct('a', -10, 'b', 10, 'N', 100, 'Func', @example_12);


Expand Down