フィルターのクリア

problem with back-substitution code

46 ビュー (過去 30 日間)
Sienna Phillips
Sienna Phillips 2020 年 8 月 20 日
コメント済み: Shaima Al-Shalwi 2022 年 9 月 5 日
I want to make an algorithm for back substitution and am testing it on some U and some b. when I call the function though it says U is not defined. Can anyone see where I have made an error? I am very new to MATLAB!
%--INPUTS------------------------------------------------------------------
%
% U - upper triangular matrix
% b - column vector
%
%--OUTPUT------------------------------------------------------------------
%
% b - solution x of Ux=b, stored in b
%
function b=myBackwardSubstitution(U,b)
d=size(U,1);
U=[1 2 3; 4 5 6; 7 8 9];
b=[1;2;3];
for i=1:d
for j=i+1:d
b(i)=b(i)-L(i,j)*b(j);
end
b(i)=b(i)/L(i,i);
end

採用された回答

Alan Stevens
Alan Stevens 2020 年 8 月 20 日
Define U and b outside function to which you pass them.
Define L.
%--INPUTS------------------------------------------------------------------
%
% U - upper triangular matrix
% b - column vector
%
%--OUTPUT------------------------------------------------------------------
%
% b - solution x of Ux=b, stored in b
%
% Define U and b outside of function.
U=[1 2 3; 4 5 6; 7 8 9];
b=[1;2;3];
% Call function
b = myBackwardSubstitution(U,b);
function b=myBackwardSubstitution(U,b)
d=size(U,1);
for i=1:d
for j=i+1:d
% You haven't defined L
b(i)=b(i)-L(i,j)*b(j);
end
b(i)=b(i)/L(i,i);
end
end
  1 件のコメント
Shaima Al-Shalwi
Shaima Al-Shalwi 2022 年 9 月 5 日
What does L represent in the code?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by