フィルターのクリア

Finding the norm of a matrix using for-loops and conditional statements

3 ビュー (過去 30 日間)
Chris
Chris 2013 年 11 月 24 日
回答済み: Chris 2013 年 11 月 25 日
Alright, so I'm having a bit of trouble with an example for MATLAB. I'm trying to find the conditional number of any square matrix, which normally isn't too difficult. However, instead of using the norm function to find the norm of the matrix, I am to use loops and conditional statements. I'm not completely sure where to start.
I know how to find the norm on paper - I take the absolute value of each number of the matrix, then add up the columns. The largest number, then, is the norm of the matrix. How might I translate that over into MATLAB?
EDIT: This is how what I've gotten thus far. The sums make sense, but I don't know how to edit it so that it'll work for any square matrix.
A= [2 3 4; 4 7 6; -11 85 9;];
invA= inv(A);
mn=size(A);
n=length(A);
for i=1:1:n-2
for j=1:1:n-2
sum_1=abs(A(i,1)) + abs(A((i+1),1) + abs(A((i+2),1)))
sum_2=abs(A(i,2)) + abs(A((i+1),2)) + abs(A((i+2),2))
sum_3=abs(A(i,3)) + abs(A((i+1),3)) + abs(A((i+2),3))
end
end
  3 件のコメント
Chris
Chris 2013 年 11 月 24 日
I'm supposed to use loops and conditional statements - I can't use max/cond/sum/similar commands.
Matt J
Matt J 2013 年 11 月 24 日
編集済み: Matt J 2013 年 11 月 24 日
I know how to find the norm on paper - I take the absolute value of each number of the matrix, then add up the columns.
That is the L1 norm, not the more standard L2 norm.

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

採用された回答

Matt J
Matt J 2013 年 11 月 24 日
編集済み: Matt J 2013 年 11 月 24 日
Hint:
B=abs(A);
accum=0;
for i=1:size(B,1)
accum=accum+B(i,:);
end
  2 件のコメント
Chris
Chris 2013 年 11 月 24 日
That makes sense, I appreciate it. What does the : signify in the B(i,:); portion?
Chris
Chris 2013 年 11 月 24 日
Nevermind, figured what the : was.

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

その他の回答 (1 件)

Chris
Chris 2013 年 11 月 25 日
I greatly appreciate that little hint you gave me - that little nudge in the right direction was just what I needed.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by