could i get help with this question?

can someone help me with this?

4 Comments

This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
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.
See diag and blkdiag
Nothing in the assignment calls for integration.

Sign in to comment.

Answers (0)

Products

Release

R2021b

Tags

Asked:

on 25 Nov 2022

Edited:

on 26 Nov 2022

Community Treasure Hunt

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

Start Hunting!