Summation

If I want to plot a function with summation, what should I do? The function is like
y = (1/0.5*x*(x-1))*summation(dij)

4 个评论

Jan
Jan 2011-2-13
Please specify the dimensions and type of x and dij and what you want to be summed.
yuen
yuen 2011-2-15
i only know i and j is the distance between two nodes, d(ij) is defined as the distance of the nodes. I would like to find the sumation of d(ij)and only know that i>j. then , from the above equaton, how can i get the plot function. thanks for your help!!!plz!!
Jan
Jan 2011-2-15
"i and j is the distance"? And "d(ij)" is the distance also? What exactly does "d(ij)" mean? You know that i>j - but you do not explain what i and j are. With this limited information it is impossible to create a meaningful answer.
yuen
yuen 2011-2-17
sorry for making misunderstanding...in fact, i and j means two nodes, their distance is defined as d. Can you help me how to plot the function? thanks a lot.

请先登录,再进行评论。

 采纳的回答

Walter Roberson
Walter Roberson 2011-2-12

1 个投票

sum() does summation.
I cannot tell from from example exactly what you are trying to sum.

8 个评论

yuen
yuen 2011-2-15
only use sum? how about the defination i need to define? for i and j? they are distance, and i use d to replace.
You haven't been at all clear about what i and j should be for this purpose, but this might be what you need:
y = (1/0.5*x.*(x-1)) .* sum( reshape(bsxfun(@gt,(1:size(d,1)).', 1:size(d,2)) .* d,[],1))
yuen
yuen 2011-2-15
what do you mean by sum( reshape(bsxfun(@gt,(1:size(d,1)).', 1:size(d,2)) .* d,[],1))?
is it a function?
bsxfun() is a matlab operation. In this context it is used to construct a lower-diagonal triangle of 1's and 0's, as your specification that all you know is that i>j could be interpreted as meaning you want the lower triangle of the matrix. Multiplying the triangle of 1's and 0's element-wise by d masks out the diagonal and upper triangle, leaving 0's and the values in the lower triangle. reshape() is then used to turn that 2D matrix in to a vector, and sum() then totals those values.
It can be done without the reshape by using sum(sum(bsxfun(@gt,(1:size(d,1)).', 1:size(d,2)) .* d))
yuen
yuen 2011-2-17
sorry, i still don't understand what it mean, when i try to plot the function, it still has errors, what should i do?
yuen
yuen 2011-2-17
also, what do you mean by d?
You referenced dij and you said something about i > j. That implied to me that you have a matrix named "d" with subscripts "i" and "j".
We need your code and any error messages you are encountering in order to take this any further.
yuen
yuen 2011-2-18
I had sent to actually equation to your mail box. please check and really thank you a lot.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Performance and Memory 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by