could i get help with this question?

조회 수: 1 (최근 30일)
poppy
poppy 2022년 11월 25일
편집: Walter Roberson 2022년 11월 26일
can someone help me with this?
  댓글 수: 4
poppy
poppy 2022년 11월 25일
편집: Walter Roberson 2022년 11월 26일
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
Walter Roberson 2022년 11월 26일
편집: Walter Roberson 2022년 11월 26일
See diag and blkdiag
Nothing in the assignment calls for integration.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by