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 Comments

Jan
Jan on 13 Feb 2011
Please specify the dimensions and type of x and dij and what you want to be summed.
yuen
yuen on 15 Feb 2011
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 on 15 Feb 2011
"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 on 17 Feb 2011
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.

Sign in to comment.

 Accepted Answer

Walter Roberson
Walter Roberson on 12 Feb 2011

1 vote

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

8 Comments

yuen
yuen on 15 Feb 2011
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 on 15 Feb 2011
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 on 15 Feb 2011
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 on 15 Feb 2011
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 on 17 Feb 2011
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 on 17 Feb 2011
also, what do you mean by d?
Walter Roberson
Walter Roberson on 17 Feb 2011
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 on 18 Feb 2011
I had sent to actually equation to your mail box. please check and really thank you a lot.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!