I see that you want to know how to define your input matrices and vectors based on your expression. Follow these steps to do so:
1.) Define your parameters like “beta”, “M” and “alpha”.
2.) For defining your matrices and vectors, you need to first define their sizes. I took some example values, you can modify it according to your data.
n = 10; % Example size
D = eye(n); % Example D matrix as an identity matrix
f_r = ones(n, 1); % Example vector
g_r = ones(n, 1); % Example vector
h_r = ones(n, 1); % Example vector
P_r = ones(n, 1); % Example vector
eta = linspace(0, 1, n)'; % Example eta values
3.) Then construct your matrix “A1” and vector “B1” as given in your provided expression.
4.) Define your initial guess vectors, that will provide starting points for the iterative method we are using.
5.) Lastly define your SOR function. Here’s a simple implementation of how I did it.
function [x, iter] = sor(A, b, omega, x0, tol, max_iter)
if nargin < 6
max_iter = 1000;
end
if nargin < 5
tol = 1e-5;
end
n = length(b);
x = x0;
for iter = 1:max_iter
x_new = x;
for i = 1:n
sum1 = A(i, 1:i-1) * x_new(1:i-1);
sum2 = A(i, i+1:n) * x(i+1:n);
x_new(i) = (1 - omega) * x(i) + (omega / A(i, i)) * (b(i) - sum1 - sum2);
end
if norm(x_new - x, inf) < tol
x = x_new;
return;
end
x = x_new;
end
end
% Example usage
omega = 1.25; % Relaxation factor
x0 = zeros(n, 1); % Initial guess
[solution, iterations] = sor(A1, B1, omega, x0);
disp('Solution:');
disp(solution);
disp('Iterations:');
disp(iterations);
I followed these steps and using my example data I got this result:

The output suggests that the solution vector is a constant vector with the same value for each element, and it took 10 iterations to converge.
You make sure to adjust the size of “n”, and the vectors “f_r”, “g_r”, “h_r” and “p_r” according to your specific problem context.
You can refer to these documentation links for more help:
Matrix Operations- https://www.mathworks.com/help/releases/R2021a/matlab/math/basic-matrix-operations.html
Array vs Matrix Operations - https://www.mathworks.com/help/releases/R2021a/matlab/matlab_prog/array-vs-matrix-operations.html
Successive Over-Relaxation: