# could i get help with this question?

2 Ansichten (letzte 30 Tage)
poppy am 25 Nov. 2022
Bearbeitet: Walter Roberson am 26 Nov. 2022
can someone help me with this?
##### 4 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
poppy am 25 Nov. 2022
Bearbeitet: Walter Roberson am 26 Nov. 2022
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
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.
Walter Roberson am 26 Nov. 2022
Bearbeitet: Walter Roberson am 26 Nov. 2022
See diag and blkdiag
Nothing in the assignment calls for integration.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by