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.
Walter Roberson
Walter Roberson 2011 年 2 月 15 日
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?
Walter Roberson
Walter Roberson 2011 年 2 月 15 日
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?
Walter Roberson
Walter Roberson 2011 年 2 月 17 日
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 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by