Skip to content

Commit

Permalink
Better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cfgnunes committed Mar 2, 2022
1 parent 7166421 commit 4ba62b5
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 76 deletions.
6 changes: 3 additions & 3 deletions differentiation/derivative_backward_difference.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
% All values in 'x' must be equally spaced.
%
% Args:
% x: array containing x values.
% y: array containing y values.
% x: an array containing x values.
% y: an array containing y values.
%
% Returns:
% dy: array containing the first derivative values.
% dy: an array containing the first derivative values.

x_size = size(x, 2);
y_size = size(y, 2);
Expand Down
6 changes: 3 additions & 3 deletions differentiation/derivative_five_point.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
% All values in 'x' must be equally spaced.
%
% Args:
% x: array containing x values.
% y: array containing y values.
% x: an array containing x values.
% y: an array containing y values.
%
% Returns:
% dy: array containing the first derivative values.
% dy: an array containing the first derivative values.

x_size = size(x, 2);
y_size = size(y, 2);
Expand Down
6 changes: 3 additions & 3 deletions differentiation/derivative_three_point.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
% All values in 'x' must be equally spaced.
%
% Args:
% x: array containing x values.
% y: array containing y values.
% x: an array containing x values.
% y: an array containing y values.
%
% Returns:
% dy: array containing the first derivative values.
% dy: an array containing the first derivative values.

x_size = size(x, 2);
y_size = size(y, 2);
Expand Down
4 changes: 2 additions & 2 deletions integration/composite2_simpson.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
% Calculate the integral from 1/3 Simpson's Rule.
%
% Args:
% x: array containing x values.
% y: array containing y values.
% x: an array containing x values.
% y: an array containing y values.
%
% Returns:
% xi: integral value.
Expand Down
6 changes: 3 additions & 3 deletions integration/composite2_trapezoidal.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function [xi] = composite2_trapezoidal(x, y)
% Calculate the integral from Trapezoidal Rule.
% Calculate the integral from the Trapezoidal Rule.
%
% Args:
% x: array containing x values.
% y: array containing y values.
% x: an array containing x values.
% y: an array containing y values.
%
% Returns:
% xi: integral value.
Expand Down
4 changes: 2 additions & 2 deletions integration/composite_simpson.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
%
% Args:
% f: function f(x).
% a: initial point.
% b: end point.
% a: the initial point.
% b: the final point.
% n: number of intervals.
%
% Returns:
Expand Down
6 changes: 3 additions & 3 deletions integration/composite_trapezoidal.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function [xi] = composite_trapezoidal(f, b, a, n)
% Calculate the integral from Trapezoidal Rule.
% Calculate the integral from the Trapezoidal Rule.
%
% Args:
% f: function f(x).
% a: initial point.
% b: end point.
% a: the initial point.
% b: the final point.
% n: number of intervals.
%
% Returns:
Expand Down
6 changes: 3 additions & 3 deletions interpolation/lagrange.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function [y_int] = lagrange(x, y, x_int)
% Interpolates a value using Lagrange polynomial.
% Interpolates a value using the 'Lagrange polynomial'.
%
% Args:
% x: array containing x values.
% y: array containing y values.
% x: an array containing x values.
% y: an array containing y values.
% x_int: value to interpolate.
%
% Returns:
Expand Down
6 changes: 3 additions & 3 deletions interpolation/neville.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function [y_int, q] = neville(x, y, x_int)
% Interpolates a value using Neville polynomial.
% Interpolates a value using the 'Neville polynomial'.
%
% Args:
% x: array containing x values.
% y: array containing y values.
% x: an array containing x values.
% y: an array containing y values.
% x_int: value to interpolate.
%
% Returns:
Expand Down
4 changes: 2 additions & 2 deletions linear_systems/backward_substitution.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
%
% Args:
% upper: upper triangular matrix.
% d: array containing d values.
% d: an array containing d values.
%
% Returns:
% x: solution of linear system.
% x: solution of linear the system.

[n, m] = size(u);

Expand Down
4 changes: 2 additions & 2 deletions linear_systems/forward_substitution.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
%
% Args:
% lower: lower triangular matrix.
% c: array containing c values.
% c: an array containing c values.
%
% Returns:
% x: solution of linear system.
% x: solution of linear the system.

[n, m] = size(l);

Expand Down
6 changes: 3 additions & 3 deletions linear_systems/gauss_elimination_pp.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function [a] = gauss_elimination_pp(a, b)
% Gaussian Elimination with Partial Pivoting.
%
% Calculate the upper triangular matrix from linear system Ax=b (do a row
% Calculate the upper triangular matrix from linear system Ax=b (make a row
% reduction).
%
% Args:
% a: matrix A from system Ax=b.
% b: array containing b values.
% b: an array containing b values.
%
% Returns:
% a: augmented upper triangular matrix.
Expand All @@ -33,7 +33,7 @@

end

% Cheking for nullity of the pivots
% Checking for nullity of the pivots
while p <= n && a(p, i) == 0
p = p + 1;
end
Expand Down
6 changes: 3 additions & 3 deletions linear_systems_iterative/gauss_seidel.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
%
% Args:
% a: matrix A from system Ax=b.
% b: array containing b values.
% x0: initial approximation of solution.
% b: an array containing b values.
% x0: initial approximation of the solution.
% tol: tolerance.
% iter_max: maximum number of iterations.
%
% Returns:
% x: solution of linear system.
% x: solution of linear the system.
% iter: used iterations.

% L and U matrices
Expand Down
6 changes: 3 additions & 3 deletions linear_systems_iterative/jacobi.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
%
% Args:
% a: matrix A from system Ax=b.
% b: array containing b values.
% x0: initial approximation of solution.
% b: an array containing b values.
% x0: initial approximation of the solution.
% tol: tolerance.
% iter_max: maximum number of iterations.
%
% Returns:
% x: solution of linear system.
% x: solution of linear the system.
% iter: used iterations.

% D and M matrices
Expand Down
4 changes: 2 additions & 2 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
% Bisection method (find roots of an equation)
% Pros:
% It is a reliable method with guaranteed convergence;
% It is a simple method that searches for the root employing a
% It is a simple method that searches for the root by employing a
% binary search;
% There is no need to calculate the derivative of the function.
% Cons:
Expand Down Expand Up @@ -58,7 +58,7 @@
% Cons:
% It may diverge if the function is not approximately linear in the
% range containing the root;
% It is necessary to give two points 'a' and 'b' where
% It is necessary to give two points, 'a' and 'b' where
% f(a)-f(b) must be nonzero.
disp('> Run an example "Solutions: Secant method".')
f = @(x) (4 * x^3 + x + cos(x) - 10);
Expand Down
10 changes: 5 additions & 5 deletions ode/euler.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function [vx, vy] = euler(f, a, b, n, ya)
% Calculate the solution of the initial-value problem (IVP).
%
% Solve the IVP from Euler method.
% Solve the IVP from the Euler method.
%
% Args:
% f: function f(x).
% a: initial point.
% b: end point.
% a: the initial point.
% b: the final point.
% n: number of intervals.
% ya: initial value.
%
% Returns:
% vx: array containing x values.
% vy: array containing y values (solution of IVP).
% vx: an array containing x values.
% vy: an array containing y values (solution of IVP).

vx = zeros(1, n + 1);
vy = zeros(1, n + 1);
Expand Down
10 changes: 5 additions & 5 deletions ode/rk4.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function [vx, vy] = rk4(f, a, b, n, ya)
% Calculate the solution of the initial-value problem (IVP).
%
% Solve the IVP from Runge-Kutta (Order Four) method.
% Solve the IVP from the Runge-Kutta (Order Four) method.
%
% Args:
% f: function f(x).
% a: initial point.
% b: end point.
% a: the initial point.
% b: the final point.
% n: number of intervals.
% ya: initial value.
%
% Returns:
% vx: array containing x values.
% vy: array containing y values (solution of IVP).
% vx: an array containing x values.
% vy: an array containing y values (solution of IVP).

vx = zeros(1, n + 1);
vy = zeros(1, n + 1);
Expand Down
12 changes: 6 additions & 6 deletions ode/rk4_system.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
% Solve from Runge-Kutta (Order Four) method.
%
% Args:
% f: array of functions f(x).
% a: initial point.
% b: end point.
% f: an array of functions f(x).
% a: the initial point.
% b: the final point.
% n: number of intervals.
% ya: array of initial values.
% ya: an array of initial values.
%
% Returns:
% vx: array containing x values.
% vy: array containing y values (solution of IVP).
% vx: an array containing x values.
% vy: an array containing y values (solution of IVP).

m = size(f, 1);

Expand Down
10 changes: 5 additions & 5 deletions ode/taylor2.m
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
function [vx, vy] = taylor2(f, df1, a, b, n, ya)
% Calculate the solution of the initial-value problem (IVP).
%
% Solve the IVP from Taylor (Order Two) method.
% Solve the IVP from the Taylor (Order Two) method.
%
% Args:
% f: function f(x).
% df1: 1's derivative of function f(x).
% a: initial point.
% b: end point.
% a: the initial point.
% b: the final point.
% n: number of intervals.
% ya: initial value.
%
% Returns:
% vx: array containing x values.
% vy: array containing y values (solution of IVP).
% vx: an array containing x values.
% vy: an array containing y values (solution of IVP).

vx = zeros(1, n + 1);
vy = zeros(1, n + 1);
Expand Down
10 changes: 5 additions & 5 deletions ode/taylor4.m
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
function [vx, vy] = taylor4(f, df1, df2, df3, a, b, n, ya)
% Calculate the solution of the initial-value problem (IVP).
%
% Solve the IVP from Taylor (Order Four) method.
% Solve the IVP from the Taylor (Order Four) method.
%
% Args:
% f: function f(x).
% df1: 1's derivative of function f(x).
% df2: 2's derivative of function f(x).
% df3: 3's derivative of function f(x).
% a: initial point.
% b: end point.
% a: the initial point.
% b: the final point.
% n: number of intervals.
% ya: initial value.
%
% Returns:
% vx: array containing x values.
% vy: array containing y values (solution of IVP).
% vx: an array containing x values.
% vy: an array containing y values (solution of IVP).

vx = zeros(1, n + 1);
vy = zeros(1, n + 1);
Expand Down
6 changes: 3 additions & 3 deletions polynomials/briot_ruffini.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function [b, rest] = briot_ruffini(root, a)
% Divides a polynomial by another polynomial.
% Divide a polynomial by another polynomial.
%
% The format is: P(x) = Q(x) * (x-root) + rest.
%
% Args:
% a: array containing the coefficients of the input polynomial.
% a: an array containing the coefficients of the input polynomial.
% root: one of the polynomial roots.
%
% Returns:
% b: array containing the coefficients of the output polynomial.
% b: an array containing the coefficients of the output polynomial.
% rest: polynomial division Rest.

n = size(a, 2) - 1;
Expand Down
8 changes: 4 additions & 4 deletions polynomials/newton_divided_difference.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function [f] = newton_divided_difference(x, y)
% Find the coefficients of Newton's divided difference.
%
% Also findthe Newton's polynomial.
% Also, find Newton's polynomial.
%
% Args:
% x: array containing x values.
% y: array containing y values.
% x: an array containing x values.
% y: an array containing y values.
%
% Returns:
% f: array containing Newton's divided difference coefficients.
% f: an array containing Newton's divided difference coefficients.

n = size(x, 2);
q = zeros(n, n - 1);
Expand Down
2 changes: 1 addition & 1 deletion solutions/bisection.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [root, iter, converged] = bisection(f, a, b, tol, iter_max)
% Calculate the root of an equation by Bisection method.
% Calculate the root of an equation by the Bisection method.
%
% Args:
% f: function f(x).
Expand Down
2 changes: 1 addition & 1 deletion solutions/newton.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [root, iter, converged] = newton(f, df, x0, tol, iter_max)
% Calculate the root of an equation by Newton method.
% Calculate the root of an equation by the Newton method.
%
% Args:
% f: function f(x).
Expand Down
Loading

0 comments on commit 4ba62b5

Please sign in to comment.