Row Echeleon Form/Forward elimination only

3 ビュー (過去 30 日間)
bdlawr
bdlawr 2017 年 10 月 26 日
回答済み: Aveek Podder 2017 年 11 月 7 日
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

採用された回答

Aveek Podder
Aveek Podder 2017 年 11 月 7 日
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);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by