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
Best Answer