MATLAB: Code some excel formulas in Matlab, in a smart way

for looploopmulti for loopsmart coding

Hey
I have a quick question, I have this excel ark where there is a column that has the following code:
q1 = 1/2 * x1 * y1
q2 = 1/2 * x2 * y2 + x1 * y1
q3 = 1/2 * x3 * y3 + x2 * y2 + x1 * y1
q4 = 1/2.............
and so on and so on.
How do I program this smart? I've tried to make a for loop, but I can't figure out how the make the 1/2 only stick to the new x-y values and not the others.

Best Answer

This sounds vaguely homework-like so I'm not going to give the answer just a hint. I assume x1, x2, etc. refer to elements of a vector x and similarly for y1, y2, etc. Let xy be x.*y. Take a look at the cumsum function applied to xy. It doesn't get you all the way to your answer, but it gets you most of the way there.