Row Echeleon Form/Forward elimination only

3 views (last 30 days)
I am having trouble coding something that will just give me the matrix in row echelon form. I put asterisks around the line that isnt working and the error given is "Subscripted assignment dimension mismatch". I am not sure how to fix it. Below is also the PDF with a test case.
function [A_new, b_new] = forward_elimination(A, b)
%FORWARD_ELIMINATION - Performs forward elimination to put A into unit
% upper triangular form.
% A - original matrix of Ax = b
% b - original vector of Ax = b
% A_new - unit upper triangular A formed using Gaussian Elimination
% b_new - the vector b associated with the transformed A
% Default output
% A_new = A;
% b_new = b;
%********************************** TODO ********************************
% Perform Gaussian Elimination to evaluate turn A into a unit upper
% triangular matrix
[rowA,colA]=size(A);
[rowb,colb]=size(b);
if det(A)==0
disp('Error')
A_new=zeros(rowA,colA);
b_new=zeros(rowb,colb);
elseif A==zeros(rowA,colA)
disp('Error')
A_new=zeros(rowA,colA);
b_new=zeros(rowb,colb);
else
sysarray=[A b];
row1=sysarray(1,:);
element1=A(1,1);
rrow1=(row1/element1);
array2=[rrow1;sysarray(2:end,:)];
for i=1:(numel(b)-1)
*array3(i)=array2(i+1,:)-array2(i,:).*array2(i+1,i+1);*
end
n_array2=array3;
for j=1:(rowA-1)
newArray=n_array2(j,:)/n_array2(j,j);
end
A_new=newArray(:,end-1);
b_new=newArray(:,end);
end
end

Accepted Answer

Aveek Podder
Aveek Podder on 7 Nov 2017
Hi,
You are accessing the element of array3 by using linear indexing and you trying to fill it with a row vector. So you are getting a dimension mismatch error.
This issue can be solved by replacing the line within asterisks with the line given below.
array3(i,:) = array2(i+1,:) - array2(i,:).*array2(i+1,i+1);

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!