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
Chandra Kurniawan 2012년 1월 10일
3^2+5^2+7^2 = 83, right?
5^2+6^2+0^2 = 61, right?
FIR
FIR 2012년 1월 10일
s chandra u r right
FIR
FIR 2012년 1월 10일
chandra can u tell how to calculate this
summation i=1 to n q^2ir ,where n=2
r=1:20
q is a matrix
Chandra Kurniawan
Chandra Kurniawan 2012년 1월 10일
what size of q?
FIR
FIR 2012년 1월 10일
size of q is 2x20
Andrei Bobrov
Andrei Bobrov 2012년 1월 10일
sum(q(:,1:20).^2)
Walter Roberson
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
Walter Roberson 2012년 1월 10일
andrei, notice that both i and r also occur in the exponent.
Chandra Kurniawan
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
Andrei Bobrov 2012년 1월 10일
so?
i1 = 1:2;
r = 1:20;
out = sum(q.^(2*i1.'*r))
FIR
FIR 2012년 1월 10일
thanks chandra
Chandra Kurniawan
Chandra Kurniawan 2012년 1월 10일
Okay. Glad to help you.
Walter Roberson
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
FIR 2012년 1월 10일
chandra can u tell how to process this am struch here for long
http://www.sendspace.com/file/scymbl
Andrei Bobrov
Andrei Bobrov 2012년 1월 10일
i1 = 1:2;
r = 1:20;
out = sum(q.^2.*(i1.'*r))

댓글을 달려면 로그인하십시오.

 채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2012년 1월 10일

0 개 추천

A=[3 5 7;
5 6 0;
5 9 4];
for x = 1 : 3
B(x,:) = sum(A(x,:).^2);
end
B

추가 답변 (1개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by