필터 지우기
필터 지우기

How to complete summation with column vectors?

조회 수: 2 (최근 30일)
Branden Chamness
Branden Chamness 2015년 4월 29일
댓글: Stephen23 2015년 4월 29일
I have the following summation I need to complete. x is a column vector of Nx1 and and u is an Nx1 column vector as well. i_th component is given as below and j_th component is same. My question is firstly, do I sum only jth components since summation bounds are j=1 to N? How is this done in Matlab?
I have the code below but I have been doubting it for the last week as the rest of my code has not converged well.
N=10;
x = ones(N,1)
u=1:N
u=u'
u=(u-.5)/N %given parameter of u
in = @(x) sum((u.*x)./(u + u))

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2015년 4월 29일
편집: Andrei Bobrov 2015년 4월 29일
Let your vectors this:
x = ones(10,1);
u = ((1:10)'-.5)/10;
Solution:
[ui,uj] = ndgrid(u);
out = ui./(ui+uj)*x(:);

Gopalkrishna Bhat
Gopalkrishna Bhat 2015년 4월 29일
try the below code for N=4. Assuming that k is the 2nd column and there are only 4 rows.
sum=0; ui=1; k=1;
for j=1:4 sum=sum+(ui*u(j,k))/(ui+u(j,k)); end
  댓글 수: 1
Stephen23
Stephen23 2015년 4월 29일
Never call a variable sum, as this is the name of an inbuilt function sum. This is a really bad idea, do not do this.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by