Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

QUESTION: How would I go about generating a d block diagonal system for d = [ 5,10,15....50] and solve each system by integrating the two functions above.

1 visualización (últimos 30 días)
FIRST Function for Gauss elimination:
function [x, A, b] = GE(A, b)
%-------------------------------------------------------------------------%
%GaussE: Function which performs Gauss Elimination, pivoting if required.
%INPUTS
% A = Input A matrix
% b = Input b vector
%OUTPUTS
% A = The forward eliminated coefficient matrix
% b = The forward eliminated b vector
% x = The final solution vector x
%-------------------------------------------------------------------------%
n = length(A);
%-------------------------------------------------------------------------%
% FORWARD ELIMINATION START:
%-------------------------------------------------------------------------%
for i = 1:(n-1) % Pivot row index (stop at 2nd last row)
%-------------------------------------------------------------------------%
% < INSERT PARTIAL PIVOTING CODE HERE >
%-------------------------------------------------------------------------%
for k = (i+1):n % Skips the pivot element and indexes what is BELOW it in the SAME COLUMN as the pivot element.
factor = ( A(k,i) / A(i,i) ); % Calculates the row factor for current row
for j = 1:n % Column index
A(k,j) = A(k,j) - factor*A(i,j); % Row subtraction, element-by-element
end
b(k) = b(k) - factor*b(i); % Updates b
end
end
%-------------------------------------------------------------------------%
% FORWARD ELIMINATION END
%-------------------------------------------------------------------------%
%-------------------------------------------------------------------------%
% BACKWARDS SUBSTITUTION START:
%-------------------------------------------------------------------------%
x = zeros(n,1);
x(n) = b(n) / A(n,n); % Compute x(n) immediately
for i = (n-1):(-1):(1) % Row index, starting at the 2nd last row and working backwards
summ = b(i);
for j = (i+1):n % Before solving for x(i), need to subtract all terms to the RIGHT of the current pivot element (if any).
summ = summ - A(i,j)*x(j);
end
x(i) = summ/A(i,i); % Divide final 'sum' by the pivot element
x
end
%-------------------------------------------------------------------------%
% BACKWARDS SUBSTITUTION END
%-------------------------------------------------------------------------%
end
Second function:
function [x]=BlockDiagonalSolver(A,b)
n=length(A);
d=sqrt(length(A));
x=zeros(n,1);
for i= 1:d
start_row=((i-1)*d+1);
end_row=(i*d);
h=start_row:end_row;
A_solve=A(h,h);
b_solve=b(h);
[A_1,b_1,x(h)]= GaussE(A_solve,b_solve);
end

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by