Help me with this code.

function k = SPK1(w1,v,m,n)
w=transpose(w1);
for i1= 1:n
p1=0;
q1=0;
r2=0;
for j1=1:m
% summation of upper numerator portion
p1= p1+ w(i1,j1)* v(j1);
end
for i2=1:n
for j2=1:m
% upper denumerator poriton
q1=q1+w(i2,j2);
end
end
%the upper portion of equation
r1 = p1/q1;
for i3= 1: n
p2=0;
q2=0;
for j3=1: m
% summation of lower numerator portion
p2= p2+ w(i3,j3)* v(j3);
end
for i4=1:n
for j4=1:m
% lower denumerator poriton
q2=q2+w(i4,j4);
end
end
%the lower portion of equation
r2 = r2+ p2/q2;
end
%the final value
k(i1)=r1/r2;
end
end
-------------------------------------------------------------------------------
Is the coding correct and logical for this equation? if not, kindly suggest me.
thanks.

댓글 수: 5

Rik
Rik 2020년 6월 27일
I don't immediately notice anything strange (although I didn't check in detail).
Why aren't using the sum function? That would make it easier to read and probably a bit faster.
MD Rokibujjaman Sabuj
MD Rokibujjaman Sabuj 2020년 6월 27일
How can i use the sum function for my problems? Can you share a bit more?
Rik
Rik 2020년 6월 27일
would become
sum(w(1:n,j))
Note that for element-wise multiplication and division you need .* and ./.
MD Rokibujjaman Sabuj
MD Rokibujjaman Sabuj 2020년 6월 27일
편집: MD Rokibujjaman Sabuj 2020년 6월 27일
Thanks.
How to write the Wij when no sum?
Where, i=4, j=10
Like this, w(1:4,10) ?
Rik
Rik 2020년 6월 27일
Just normal indexing:
i=4;j=10;
w(i,j)

답변 (0개)

이 질문은 마감되었습니다.

태그

질문:

2020년 6월 27일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by