Skip to content

Commit

Permalink
Translate the comments to english
Browse files Browse the repository at this point in the history
  • Loading branch information
kryczkal committed Mar 3, 2024
1 parent 2369001 commit d0cc891
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 162 deletions.
2 changes: 1 addition & 1 deletion ADM2-H-ODE-Solver/AB2_next_step.m
Original file line number Diff line number Diff line change
@@ -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
next_step = y(1, :) + (h/2)*(3*D(2,:) - 1*D(1, :)); // prediction
2 changes: 1 addition & 1 deletion ADM2-H-ODE-Solver/M_corr_step.m
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions ADM2-H-ODE-Solver/efficiency_test/time_test_abm.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
34 changes: 17 additions & 17 deletions ADM2-H-ODE-Solver/f.m
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions AdaptiveRomberg-1D-Integration/my_error.m
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
function y = my_error(wiersz_gora,wiersz_dol)
y = abs(wiersz_gora-wiersz_dol)/max(1,abs(wiersz_dol));
function y = my_error(upper_row, lower_row)
y = abs(upper_row - lower_row) / max(1, abs(lower_row));
48 changes: 24 additions & 24 deletions AdaptiveRomberg-1D-Integration/smartRM.m
Original file line number Diff line number Diff line change
@@ -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
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
26 changes: 13 additions & 13 deletions Barycentric-Lagrange-Interpolation/baryc.m
Original file line number Diff line number Diff line change
@@ -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
weights(j) = 1 ./ coefficient;
end
}
20 changes: 10 additions & 10 deletions Barycentric-Lagrange-Interpolation/ipbval.m
Original file line number Diff line number Diff line change
@@ -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
20 changes: 10 additions & 10 deletions Barycentric-Lagrange-Interpolation/wykwi.m
Original file line number Diff line number Diff line change
@@ -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
36 changes: 18 additions & 18 deletions Gauss-Legendre-2D-Integration/get_composite_nodes.m
Original file line number Diff line number Diff line change
@@ -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
32 changes: 16 additions & 16 deletions Gauss-Legendre-2D-Integration/test_error/test_error.m
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit d0cc891

Please # to comment.