Row Echeleon Form/Forward elimination only
3 ビュー (過去 30 日間)
古いコメントを表示
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168795/image.png)
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!