diff --git a/ADM2-H-ODE-Solver/AB2_next_step.m b/ADM2-H-ODE-Solver/AB2_next_step.m index c4c3d88..fef7566 100644 --- a/ADM2-H-ODE-Solver/AB2_next_step.m +++ b/ADM2-H-ODE-Solver/AB2_next_step.m @@ -1,2 +1,2 @@ function next_step = AB2_next_step(f, D, x, y, A, B, h) -next_step = y(1, :) + (h/2)*(3*D(2,:) - 1*D(1, :)); % predykcja \ No newline at end of file +next_step = y(1, :) + (h/2)*(3*D(2,:) - 1*D(1, :)); // prediction diff --git a/ADM2-H-ODE-Solver/M_corr_step.m b/ADM2-H-ODE-Solver/M_corr_step.m index d7abb1f..42da1e8 100644 --- a/ADM2-H-ODE-Solver/M_corr_step.m +++ b/ADM2-H-ODE-Solver/M_corr_step.m @@ -1,7 +1,7 @@ function corr_step = M_corr_step(f, D, x, y, A, B, h, Corr_N) % x = x(i+1), y = y(i:i+1, :) corr_step = y(2, :); -for c = 1:Corr_N % Zastosowanie korekcji Corr_N razy +for c = 1:Corr_N % Applying correction Corr_N times DD = f(x, y(2, :), A, B); corr_step = y(1, :) + (h/2)*(DD + D(2, :)); end diff --git a/ADM2-H-ODE-Solver/efficiency_test/time_test_abm.m b/ADM2-H-ODE-Solver/efficiency_test/time_test_abm.m index 8c1a2be..9f105fc 100644 --- a/ADM2-H-ODE-Solver/efficiency_test/time_test_abm.m +++ b/ADM2-H-ODE-Solver/efficiency_test/time_test_abm.m @@ -6,7 +6,7 @@ tp = 1; corr_first = 0; -for i = 1:tp % Obliczenie pierwszych wartości metodą Heuna +for i = 1:tp % Calculation of initial values using Heun's method D(2, :) = f(x, y(i, :), A, B); y(i+1, :) = heun_next_step(@f, D, x(i), y(i, :), A, B, h); if (i > 1) @@ -18,10 +18,10 @@ i = 2; time = 0; while(time < time_max) tic; - D(2, :) = f(x(i), y(i, :), A, B); % obliczanie pochodnych + D(2, :) = f(x(i), y(i, :), A, B); % Calculation of derivatives y(i+1, :) = AB2_next_step(@f, D, x(i), y(i, :), A, B, h); y(i+1, :) = M_corr_step(@f, D, x(i+1), y(i:i+1, :), A, B, h, Corr_N); - D(1, :) = D(2, :); % Zapamiętanie poprzednich wartości + D(1, :) = D(2, :); // Saving previous values tmp_time = toc; time = time + tmp_time; i = i+1; end steps = i; \ No newline at end of file diff --git a/ADM2-H-ODE-Solver/f.m b/ADM2-H-ODE-Solver/f.m index 38a1e64..416682e 100644 --- a/ADM2-H-ODE-Solver/f.m +++ b/ADM2-H-ODE-Solver/f.m @@ -1,28 +1,28 @@ function D = f(x, y, A, B) -% f - Oblicza pochodne funkcji y w punkcie x +% f - Computes the derivatives of the function y at point x % -% Funkcja oblicza wartości pochodnych funkcji y w punkcie x, wykorzystując -% metodę Adamsa-Bashfortha-Moultona. Zwraca wektor pochodnych, gdzie każdy -% element odpowiada kolejnym pochodnym funkcji y. +% This function calculates the values of the derivatives of the function y at point x +% using the Adams-Bashforth-Moulton method. It returns a vector of derivatives, where +% each element corresponds to the successive derivatives of the function y. % -% Wejście: -% x - Wartość zmiennej niezależnej dla obliczanych pochodnych. -% y - Wektor wartości y i jej pochodnych do rzędu m-1, w postaci +% Input: +% x - The value of the independent variable for which the derivatives are computed. +% y - Vector of values of y and its derivatives up to order m-1, in the form % [y, y', y'', ..., y^{(m-1)}]. -% A - Tablica komórkowa funkcji a_0, a_1, ..., a_{m-1} w postaci +% A - Cell array of functions a_0, a_1, ..., a_{m-1} in the form % {@a0, @a1, ..., @am-1}. -% B - Uchwyt do funkcji b, reprezentujący prawą stronę równania -% różniczkowego, przyjmujący x i y. +% B - Function handle for the right-hand side of the differential equation, +% taking x and y as arguments. % -% Wyjście: -% D - Wektor pochodnych y w x. Zawiera pochodne do rzędu m, gdzie -% y^{m} jest obliczane z równania: y^{(m)} = (-a_0 y - ... - +% Output: +% D - Vector of derivatives of y at x. It contains derivatives up to order m, +% where y^{m} is calculated from the equation: y^{(m)} = (-a_0 y - ... - % a_{m-1} y^{(m-1)} + B) / a_m. % -% Uwagi: -% Wartości pochodnych y', ..., y^{(m-1)} są przekazywane jako elementy -% y. Pochodna y^{(m)} jest obliczana z równania różniczkowego oraz -% funkcji a_i i B. +% Notes: +% The values of derivatives y', ..., y^{(m-1)} are passed as elements of y. +% The derivative y^{(m)} is calculated from the differential equation and +% the functions a_i and B. D = zeros(size(y)); D(1:end-1) = y(2:end); diff --git a/AdaptiveRomberg-1D-Integration/my_error.m b/AdaptiveRomberg-1D-Integration/my_error.m index 5c90b1f..760e67a 100644 --- a/AdaptiveRomberg-1D-Integration/my_error.m +++ b/AdaptiveRomberg-1D-Integration/my_error.m @@ -1,2 +1,2 @@ -function y = my_error(wiersz_gora,wiersz_dol) - y = abs(wiersz_gora-wiersz_dol)/max(1,abs(wiersz_dol)); \ No newline at end of file +function y = my_error(upper_row, lower_row) + y = abs(upper_row - lower_row) / max(1, abs(lower_row)); diff --git a/AdaptiveRomberg-1D-Integration/smartRM.m b/AdaptiveRomberg-1D-Integration/smartRM.m index 32102b7..26a9e9d 100644 --- a/AdaptiveRomberg-1D-Integration/smartRM.m +++ b/AdaptiveRomberg-1D-Integration/smartRM.m @@ -1,29 +1,29 @@ -function [Q, err, n_wierszy, wiersz_dol] = smartRM(g, a, b, tol, M0, Kmin, Kmax) - % Autor: Łukasz Kryczka - % Funkcja licząca całkę z funkcji g, na przedziale a,b, z tolerancją - % błedu tol, w adaptacyjny sposób od M0 przedziałów z minimalnie - % Kmin krokami ekstrapolacji i maksymalnie Kmax krokami ekstrapolacji. +function [Q, err, num_rows, bottom_row] = smartRM(g, a, b, tol, M0, Kmin, Kmax) + % Author: Łukasz Kryczka + % Function to calculate the integral of function g, on the interval a,b, with error tolerance tol, + % using an adaptive approach with M0 intervals, with a minimum of Kmin extrapolation steps + % and a maximum of Kmax extrapolation steps. - H = (b-a)/(M0+1); % liczymy zlozona calke trapezow dla M0+1 przedzialow - wiersz_gora = H*(sum(g(a+H:H:b-H))+(g(a)+g(b))/2); + H = (b-a)/(M0+1); % calculate composite trapezoidal integral for M0+1 intervals + top_row = H*(sum(g(a+H:H:b-H))+(g(a)+g(b))/2); - err = tol+1; % inicjalizujemy poczatkowa wartosc bledu - n_wierszy=2; % zaczynamy ekstrapolacje od 2 wiersza - while (err > tol || n_wierszy-1 <= Kmin) && n_wierszy-1 < Kmax+1 - % liczymy pierwsze wartosci nowego wiersza T(i,0) - wiersz_dol = zeros(1,n_wierszy); - H = (b-a)/((M0+1)*2^(n_wierszy-1)); - wiersz_dol(1) = H*(sum(g(a+H:H:b-H))+(g(a)+g(b))/2); + err = tol+1; % initialize the initial error value + num_rows = 2; % start extrapolation from the 2nd row + while (err > tol || num_rows-1 <= Kmin) && num_rows-1 < Kmax+1 + % calculate the first values of the new row T(i,0) + bottom_row = zeros(1,num_rows); + H = (b-a)/((M0+1)*2^(num_rows-1)); + bottom_row(1) = H*(sum(g(a+H:H:b-H))+(g(a)+g(b))/2); - % ekstrapolujemy kolejne wartosci T(i,k) - for k = 2:n_wierszy - wiersz_dol(k) = (4^(k-1)*wiersz_dol(k-1) ... - -wiersz_gora(k-1))/(4^(k-1)-1); + % extrapolate the next values T(i,k) + for k = 2:num_rows + bottom_row(k) = (4^(k-1)*bottom_row(k-1) ... + -top_row(k-1))/(4^(k-1)-1); end - % liczymy blad i aktualizujemy wartosci algorytmu - err = my_error(wiersz_gora(end),wiersz_dol(end)); - wiersz_gora = wiersz_dol; - n_wierszy = 1 + n_wierszy; + % calculate the error and update the algorithm values + err = my_error(top_row(end),bottom_row(end)); + top_row = bottom_row; + num_rows = 1 + num_rows; end - Q = wiersz_dol(end); % najdokladniejsza wartosc to ostatnia z wiersza - n_wierszy = n_wierszy-2; % ilosc ekstrapolacji to n_wierszy-2 \ No newline at end of file + Q = bottom_row(end); % the most accurate value is the last one in the row + num_rows = num_rows-2; % the number of extrapolations is num_rows-2 diff --git a/Barycentric-Lagrange-Interpolation/baryc.m b/Barycentric-Lagrange-Interpolation/baryc.m index aee0154..dee90bd 100644 --- a/Barycentric-Lagrange-Interpolation/baryc.m +++ b/Barycentric-Lagrange-Interpolation/baryc.m @@ -1,22 +1,22 @@ -function wagi = baryc(wezly) - % Autor: Łukasz Kryczka - % Funkcja licząca wagi dla postaci barycentrycznej interpolacji - % Lagrange'a +function weights = baryc(nodes) + % Author: Łukasz Kryczka + % Function to calculate weights for barycentric Lagrange interpolation - wagi = zeros(size(wezly)); - if iscolumn(wezly) - wezly=wezly'; + weights = zeros(size(nodes)); + if iscolumn(nodes) + nodes = nodes'; end j = 0; - for xj = wezly - wspolczynnik = 1; - for xi = wezly + for xj = nodes + coefficient = 1; + for xi = nodes if (xj == xi) continue end - wspolczynnik = wspolczynnik * (xj - xi); + coefficient = coefficient * (xj - xi); end j = j + 1; - wagi(j) = 1 ./ wspolczynnik; - end \ No newline at end of file + weights(j) = 1 ./ coefficient; + end +} diff --git a/Barycentric-Lagrange-Interpolation/ipbval.m b/Barycentric-Lagrange-Interpolation/ipbval.m index 91229a4..2c67e0a 100644 --- a/Barycentric-Lagrange-Interpolation/ipbval.m +++ b/Barycentric-Lagrange-Interpolation/ipbval.m @@ -1,19 +1,19 @@ -function Y = ipbval(X, wezly, wagi, wartosci) - % Autor: Łukasz Kryczka - % Funkcja licząca wartość wielomianu interpolacyjnego Lagrang'a w - % postaci barycentrycznej dla wektora X +function Y = ipbval(X, nodes, weights, values) + % Author: Łukasz Kryczka + % Function to calculate the value of the Lagrange interpolation polynomial + % in barycentric form for the vector X gj = 0; gj_f_xj = 0; - for j = 1:length(wagi) - gj = gj + wagi(j) ./ (X-wezly(j)); - gj_f_xj = gj_f_xj + wagi(j) * wartosci(j) ./ (X-wezly(j)); + for j = 1:length(weights) + gj = gj + weights(j) ./ (X-nodes(j)); + gj_f_xj = gj_f_xj + weights(j) * values(j) ./ (X-nodes(j)); end Y = gj_f_xj ./ gj; - % x rowne wezla zamieniamy na ich oryginalne wartosci - for i = find(ismember(X, wezly)) - Y(i) = wartosci(wezly == X(i)); + % Replace X equal to a node with its original value + for i = find(ismember(X, nodes)) + Y(i) = values(nodes == X(i)); end end \ No newline at end of file diff --git a/Barycentric-Lagrange-Interpolation/wykwi.m b/Barycentric-Lagrange-Interpolation/wykwi.m index 49350d4..1ccd470 100644 --- a/Barycentric-Lagrange-Interpolation/wykwi.m +++ b/Barycentric-Lagrange-Interpolation/wykwi.m @@ -1,20 +1,20 @@ function wykwi(g,a,b,n) - % Autor: Łukasz Kryczka - % Funckja generująca wykresy dla wskaźnika na funkcję g, na przedziale - % od a do b, dla n+1 węzłów. + % Author: Łukasz Kryczka + % Function generating plots for the function indicator g, on the interval + % from a to b, for n+1 nodes. - % wygenerowanie wezlow czebyszewa na przedziale od a do b + % Generating Chebyshev nodes on the interval from a to b i = 0:n; - wezly = (a + b) / 2 - ( (b-a)/2 ) .* cos( (2 .* i + 1)... + nodes = (a + b) / 2 - ( (b-a)/2 ) .* cos( (2 .* i + 1)... .* pi ./ (2 * n + 2) ); X = linspace(a,b,2000000); - % wykres funkcji + % Plotting the function plot(X, g(X), color="b") hold on - % wykres interpolacji funkcji - plot(X, ipbval(X, wezly, baryc(wezly), g(wezly) ), color="r"); - % wezly zaznaczone na zielono - scatter(wezly, g(wezly), 'filled', 'green') + % Plotting the interpolation of the function + plot(X, ipbval(X, nodes, baryc(nodes), g(nodes) ), color="r"); + % Nodes marked in green + scatter(nodes, g(nodes), 'filled', 'green') hold off end \ No newline at end of file diff --git a/Gauss-Legendre-2D-Integration/get_composite_nodes.m b/Gauss-Legendre-2D-Integration/get_composite_nodes.m index 972918d..cdfa50b 100644 --- a/Gauss-Legendre-2D-Integration/get_composite_nodes.m +++ b/Gauss-Legendre-2D-Integration/get_composite_nodes.m @@ -1,31 +1,31 @@ function composite_nodes = get_composite_nodes(a, b, n) -% get_composite_nodes oblicza wektor przeskalowanych węzłów dla 3-punktowej -% kwadratury Gaussa-Legendre'a dla złożonej kwadratury na przedziale [a, b] +% get_composite_nodes calculates the vector of scaled nodes for a 3-point +% Gauss-Legendre composite quadrature on the interval [a, b] % -% Wejście: -% a, b - granice przedziału całkowania, gdzie a < b, a i b rzeczywiste -% n - liczba podprzedziałów, na które przedział [a, b] jest dzielony -% liczba naturalna +% Input: +% a, b - integration limits, where a < b, a and b are real numbers +% n - number of subintervals to divide the interval [a, b] into, +% a natural number % -% Wyjście: -% composite_nodes - macierz węzłów kwadratury Gaussa-Legendre'a -% Każda kolumna zawiera współczynniki dla odpowiedniego podprzedziału +% Output: +% composite_nodes - matrix of Gauss-Legendre quadrature nodes +% Each column contains the coefficients for the corresponding subinterval % -% Opis: -% Funkcja get_composite_nodes działa przeskalowując i przesuwając -% standardowe węzły kwadratury na każdy z n równych podprzedziałów -% przedziału [a, b]. Wykorzystuje standardowe węzły 3-punktowej kwadratury -% Gaussa-Legendre'a, skaluje je do rozmiaru każdego podprzedziału, -% a następnie przesuwa do odpowiedniej lokalizacji. +% Description: +% The get_composite_nodes function scales and shifts the standard quadrature +% nodes for each of the n equal subintervals of the interval [a, b]. +% It uses the standard nodes of a 3-point Gauss-Legendre quadrature, +% scales them to the size of each subinterval, +% and then shifts them to the appropriate location. single_nodes=[-7.7459666924148337704e-01; 0.0000000000000000000e+00; 7.7459666924148337704e-01]; interval = (b-a)/(n); -% Stworzenie wektora bazowego do skalowania i przesunięć +% Create a base vector for scaling and shifting base = (a+interval/2):interval:b; -% Powielenie single_nodes, aby pasowały do długości base +% Replicate single_nodes to match the length of base nodes_replicated = repmat(single_nodes,1,length(base)); -% Skalowanie i przesunięcie single_nodes +% Scale and shift single_nodes composite_nodes = (interval/2)*nodes_replicated+base; end \ No newline at end of file diff --git a/Gauss-Legendre-2D-Integration/test_error/test_error.m b/Gauss-Legendre-2D-Integration/test_error/test_error.m index fd91b3d..acf171d 100644 --- a/Gauss-Legendre-2D-Integration/test_error/test_error.m +++ b/Gauss-Legendre-2D-Integration/test_error/test_error.m @@ -1,38 +1,38 @@ function test_error() pause -fprintf('Test dla wielomianu stopnia 6 - Start\n'); +fprintf('Test for a polynomial of degree 6 - Start\n'); -% Definiowanie przedziału i liczby podprzedziałów +% Defining the interval and number of subintervals a = -1; b = 1; c = -1; d = 1; n = 1; m = 1; -fprintf(['Testowanie dla przedziałów [%d, %d] i [%d, %d] z liczbą ' ... - 'podprzedziałów n = %d, m = %d.\n'], a, b, c, d, n, m); +fprintf(['Testing for intervals [%d, %d] and [%d, %d] with number ' ... + 'of subintervals n = %d, m = %d.\n'], a, b, c, d, n, m); -% Funkcja szóstego stopnia +% Sixth degree function f = @(x, y) 1.2*x.^6 - y.^6 + 0.8*x.^5.*y; fprintf('f(x, y) = 1.2*x.^6 - y.^6 + 0.8*x.^5.*y\n'); -% Oczekiwana wartość całki +% Expected integral value expected_value = 4/35; -fprintf('Oczekiwana wartość całki dla funkcji rzędu 6: %.2f\n', expected_value); -fprintf('Metoda oparta na 3 węzłach, więc błąd powinien być substancjalny\n') +fprintf('Expected integral value for a degree 6 function: %.2f\n', expected_value); +fprintf('Method based on 3 nodes, so the error should be substantial\n') % (d-c)d1 + (b-a)d2 (c1 + d2) / m^6 % (d-c)d1 + (b-a)d2 (c1 + d2) / 2^6 % d1 = c1/m^2n % d2 = d1/n^2n -% Przybliżona wartość całki obliczona przez funkcję -approx_value = P1Z30_LKR_CDIGL(f, a, b, c, d, n, m); -fprintf('Przybliżona wartość całki: %.2f\n', approx_value); -% Błąd bezwzględny +% Approximate integral value calculated by the function +approx_value = double_integral_gauss_legendre(f, a, b, c, d, n, m); +fprintf('Approximate integral value: %.2f\n', approx_value); +% Absolute error error = abs(approx_value - expected_value); error_old = error; -fprintf('Błąd bezwzględny: %.2e\n', error); +fprintf('Absolute error: %.2e\n', error); n = 2; m = 2; approx_value = P1Z30_LKR_CDIGL(f, a, b, c, d, n, m); -fprintf('Przybliżona wartość całki: %.2f\n', approx_value); +fprintf('Approximate integral value: %.2f\n', approx_value); -% Błąd bezwzględny +% Absolute error error = abs(approx_value - expected_value); -fprintf('Błąd bezwzględny: %.2e\n', error); +fprintf('Absolute error: %.2e\n', error); fprintf('is it equal %d %d\n', error, error_old/(2^6)) diff --git a/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_composite_nodes_basic.m b/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_composite_nodes_basic.m index e20d9dd..f2a0592 100644 --- a/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_composite_nodes_basic.m +++ b/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_composite_nodes_basic.m @@ -1,29 +1,29 @@ function test_composite_nodes_basic() pause -disp('Test: Podstawowa funkcjonalność - Start'); +disp('Test: Basic functionality - Start'); -% Definiowanie przedziału i liczby podprzedziałów +% Defining the interval and number of subintervals a = 0; b = 3; n = 3; -disp(['Testowanie dla przedziału [', num2str(a), ', ', num2str(b), ... - '] z liczbą podprzedziałów n = ', num2str(n)]); +disp(['Testing for the interval [', num2str(a), ', ', num2str(b), ... + '] with the number of subintervals n = ', num2str(n)]); -% Oczekiwany wynik obliczony ręcznie +% Expected result calculated manually expected_output = [1 1]; -fprintf('Oczekiwany wynik:\n'); +fprintf('Expected result:\n'); disp(expected_output); fprintf('\n'); -% Pobieranie rzeczywistego wyniku z funkcji +% Getting the actual result from the function actual_output = get_composite_nodes(a, b, n); -fprintf('Rzeczywisty wynik:\n'); +fprintf('Actual result:\n'); disp(actual_output); fprintf('\n'); -% Sprawdzenie, czy rzeczywisty wynik zgadza się z oczekiwanym -% Tolerancja jest ustawiona, aby uwzględnić błędy arytmetyki zmiennoprzecinkowej +% Checking if the actual result matches the expected result +% Tolerance is set to account for floating-point arithmetic errors difference = abs(actual_output - expected_output); -fprintf('Różnica: ['); +fprintf('Difference: ['); fprintf(' %.2e ', difference); fprintf(']\n'); -fprintf('Test: Podstawowa funkcjonalność - Koniec\n'); +fprintf('Test: Basic functionality - End\n'); end \ No newline at end of file diff --git a/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_large_number_of_sub_intervals.m b/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_large_number_of_sub_intervals.m index 8e67c01..3841a1f 100644 --- a/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_large_number_of_sub_intervals.m +++ b/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_large_number_of_sub_intervals.m @@ -1,31 +1,31 @@ -% Test 3: Duża liczba podprzedziałów +% Test 3: Large number of sub-intervals function test_large_number_of_sub_intervals() pause -fprintf('Test: Duża liczba podprzedziałów - Start\n'); +fprintf('Test: Large number of sub-intervals - Start\n'); -% Definiowanie przedziału i ustawienie dużej liczby podprzedziałów +% Defining the interval and setting a large number of sub-intervals a = 0; b = 1; n = 1000; -fprintf('Testowanie dla przedziału [%d, %d] z liczbą podprzedziałów n = %d.\n', a, b, n); +fprintf('Testing for the interval [%d, %d] with number of sub-intervals n = %d.\n', a, b, n); -% Pobieranie wyniku z funkcji +% Getting the result from the function actual_output = get_composite_nodes(a, b, n); -fprintf('Sprawdzanie rozmiaru wyniku:\n'); +fprintf('Checking the size of the output:\n'); -% Sprawdzenie, czy funkcja zwraca wynik o odpowiedniej wielkości +% Checking if the function returns the result of the correct size expected_size = [3, n]; actual_size = size(actual_output); -fprintf('Oczekiwany rozmiar: [%d %d]\n', expected_size); -fprintf('Rzeczywisty rozmiar: [%d %d]\n', actual_size); +fprintf('Expected size: [%d %d]\n', expected_size); +fprintf('Actual size: [%d %d]\n', actual_size); assert(all(actual_size == expected_size)); -fprintf('Sprawdzanie zakresu wartości węzłów:\n'); -fprintf('(Powinny nie przekraczać zakresu [%d %d])\n', a, b); -fprintf('Ewalujemy nnz(actual_output(:, :) >= a & actual_output(:, :) <= b\n') -fprintf("Wartość oczekiwana \n") +fprintf('Checking the range of node values:\n'); +fprintf('(Should not exceed the range [%d %d])\n', a, b); +fprintf('Evaluating nnz(actual_output(:, :) >= a & actual_output(:, :) <= b\n') +fprintf("Expected value \n") disp(3000) -fprintf("Wartość rzeczywista\n") +fprintf("Actual value\n") disp(nnz(actual_output(:, :) >= a & actual_output(:, :) <= b)) -fprintf('Test: Duża liczba podprzedziałów - Koniec\n'); +fprintf('Test: Large number of sub-intervals - End\n'); end \ No newline at end of file diff --git a/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_single_subinterval.m b/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_single_subinterval.m index 669293d..2606f80 100644 --- a/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_single_subinterval.m +++ b/Gauss-Legendre-2D-Integration/tests_composite_nodes/test_single_subinterval.m @@ -1,24 +1,24 @@ function test_single_subinterval() pause -fprintf('Test: Przypadek skrajny z jednym podprzedziałem - Start\n'); -% Definiowanie przedziału i ustawienie liczby podprzedziałów na 1 +fprintf('Test: Extreme case with a single subinterval - Start\n'); +% Defining the interval and setting the number of subintervals to 1 a = -1; b = 1; n = 1; -fprintf('Testowanie dla przedziału [%d, %d] z jednym podprzedziałem.\n', a, b); +fprintf('Testing for the interval [%d, %d] with a single subinterval.\n', a, b); -% Oczekiwany wynik +% Expected output expected_output = [-7.7459666924148337704e-01; 0.0000000000000000000e+00; 7.7459666924148337704e-01]; -fprintf('Oczekiwany wynik to standardowe węzły Gaussa-Legendra:\n'); +fprintf('The expected output is the standard Gauss-Legendre nodes:\n'); fprintf('[%.4f; %.4f; %.4f]\n', expected_output); -% Pobieranie rzeczywistego wyniku z funkcji +% Getting the actual output from the function actual_output = get_composite_nodes(a, b, n); -fprintf('Rzeczywisty wynik:\n'); +fprintf('The actual output is:\n'); fprintf('[%.4f; %.4f; %.4f]\n', actual_output); -% Sprawdzenie, czy rzeczywisty wynik zgadza się z oczekiwanym +% Checking if the actual output matches the expected output assert(all(abs(actual_output - expected_output) < 1e-10)); -fprintf('Test: Przypadek skrajny z jednym podprzedziałem - Koniec\n'); +fprintf('Test: Extreme case with a single subinterval - End\n'); end \ No newline at end of file diff --git a/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/euclidean_norm.m b/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/euclidean_norm.m index dc323fb..7082767 100644 --- a/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/euclidean_norm.m +++ b/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/euclidean_norm.m @@ -1,6 +1,6 @@ function y = euclidean_norm(v) -% Autor: Łukasz Kryczka -% funkcja liczaca normę euklidesową wektora +% Author: Łukasz Kryczka +% Function to calculate the Euclidean norm of a vector y = 0; for i = 1:length(v) diff --git a/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/invpowmult.m b/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/invpowmult.m index ba45796..e03beef 100644 --- a/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/invpowmult.m +++ b/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/invpowmult.m @@ -1,9 +1,9 @@ function y = invpowmult(A,k,x) -% Autor: Łukasz Kryczka -% Funkcja licząca przybliżoną wartość x w równianiu A^(-k) * x -% poprzez rozwiązanie równania A^(-k) * x = b <==> A^(k) * b = x -% dla wartości b. -% AAb = x <==> Ay = x, Ab = y, itd... +% Author: Łukasz Kryczka +% Function to calculate the approximate value of x in the equation A^(-k) * x +% by solving the equation A^(-k) * x = b <==> A^(k) * b = x +% for the value of b. +% AAb = x <==> Ay = x, Ab = y, etc... y = x; A = A'; for i = 1:k diff --git a/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/iterative_solver.m b/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/iterative_solver.m index 88580d4..5776fa7 100644 --- a/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/iterative_solver.m +++ b/Matrix-Inverse-to-power-of-K-using-Gauss-Seidl/iterative_solver.m @@ -4,14 +4,14 @@ % y = zeros(1,length(b)); -diag = zeros(1,length(b)); +diagonal = zeros(1,length(b)); b = b(:)'; % Set diagonal values to zero to satisfy the condition j!=i in y*A(i,:)' for i = 1:length(A) - diag(i) = A(i,i); + diagonal(i) = A(i,i); A(i,i) = 0; end -y = b./diag; +y = b./diagonal; % In MATLAB, operations on columns (rather than on rows) are faster in loops due to how matlab caches data % Iterate until desired accuracy is achieved TRESHOLD = eps*length(A); @@ -19,7 +19,7 @@ while(error > TRESHOLD) || error==-1 old_y = y; for i = 1:length(b) - y(i) = ( b(i) - y*A(:,i)) / diag(i); + y(i) = ( b(i) - y*A(:,i)) / diagonal(i); end error = euclidean_norm(y - old_y); end \ No newline at end of file