multiplying a matrix
古いコメントを表示
i have a matrix
A=[3 5 7
5 6 0
5 9 4]
i want to square each element and add along row wise and display
for ex
3^2+5^2+7^2
ans is 89
so i need as
89
71
122
pleas guide
15 件のコメント
Chandra Kurniawan
2012 年 1 月 10 日
3^2+5^2+7^2 = 83, right?
5^2+6^2+0^2 = 61, right?
FIR
2012 年 1 月 10 日
FIR
2012 年 1 月 10 日
Chandra Kurniawan
2012 年 1 月 10 日
what size of q?
FIR
2012 年 1 月 10 日
Andrei Bobrov
2012 年 1 月 10 日
sum(q(:,1:20).^2)
Walter Roberson
2012 年 1 月 10 日
You require summing terms that are individually q^2ir . You cannot raise a matrix (e.g., q is 2 x 99) to a vector power (e.g., r is 1:20)
Walter Roberson
2012 年 1 月 10 日
andrei, notice that both i and r also occur in the exponent.
Chandra Kurniawan
2012 年 1 月 10 日
q = rand(2,20);
r = 1 : 20;
n = 2;
for i = 1 : n
rsl{i} = q(i,:).^2 .* i .* r;
end
Is this, right?
Andrei Bobrov
2012 年 1 月 10 日
so?
i1 = 1:2;
r = 1:20;
out = sum(q.^(2*i1.'*r))
FIR
2012 年 1 月 10 日
Chandra Kurniawan
2012 年 1 月 10 日
Okay. Glad to help you.
Walter Roberson
2012 年 1 月 10 日
andrei, you cannot raise a matrix to a vector. You can raise a matrix to a scalar or a scalar to a matrix.
FIR
2012 年 1 月 10 日
Andrei Bobrov
2012 年 1 月 10 日
i1 = 1:2;
r = 1:20;
out = sum(q.^2.*(i1.'*r))
採用された回答
その他の回答 (1 件)
Andrei Bobrov
2012 年 1 月 10 日
B = sum(A.^2,2);
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!