diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 9846b76..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/IntegralApproximationENG.pdf b/Integral_Approximation_Report_ENG.pdf similarity index 100% rename from IntegralApproximationENG.pdf rename to Integral_Approximation_Report_ENG.pdf diff --git a/Projekt1_Kowalski_Kaniasty_raport.pdf b/Integral_Approximation_Report_PL.pdf similarity index 100% rename from Projekt1_Kowalski_Kaniasty_raport.pdf rename to Integral_Approximation_Report_PL.pdf diff --git a/README.md b/README.md index e93d46d..479a022 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. + +
+ Error of trapezoidal method +

Figure 1: Graph of the dependence of the relative error expressed in (%) on the number of subintervals in integration by the trapezoidal method

+
## Authors - Hubert Kowalski diff --git a/img/trapezoidal_error.png b/img/trapezoidal_error.png new file mode 100644 index 0000000..8c862a9 Binary files /dev/null and b/img/trapezoidal_error.png differ diff --git a/scripts/.DS_Store b/scripts/.DS_Store deleted file mode 100644 index d3c0740..0000000 Binary files a/scripts/.DS_Store and /dev/null differ diff --git a/scripts/errors/kaniastyKowalskiError.m b/scripts/errors/kaniastyKowalskiError.m index 6514602..d44575b 100644 --- a/scripts/errors/kaniastyKowalskiError.m +++ b/scripts/errors/kaniastyKowalskiError.m @@ -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 diff --git a/scripts/tests/plotN.m b/scripts/tests/plotN.m index dd81209..9a24b66 100644 --- a/scripts/tests/plotN.m +++ b/scripts/tests/plotN.m @@ -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 diff --git a/scripts/tests/runTestsTable.m b/scripts/tests/runTestsTable.m index cf113ee..5c3b9ac 100644 --- a/scripts/tests/runTestsTable.m +++ b/scripts/tests/runTestsTable.m @@ -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); @@ -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);