Originally Posted by

**scclebos** Hello I'm doing a simplified model of a bouncing ball and I am having trouble getting my function DISTANCE to output values for a range of 0:N. I can make it output a single correct value, but not values of 0:N-1...0:0 etc. I have been stuck on this for HOURS. If someone could offer some input on this that would be spectacular.

My functions are defined as: H0=Initial Height, R=Rebound coefficient, and N=NUmber of bounces. Function HEIGHT finds the height after N bounces, and DISTANCE finds the total vertcial distance. I use (5, .4, [0:7]) to test.

function [HNN]=HEIGHT(H0, R, N)

HNN=H0.*R.^N;

function [TVD]=DISTANCE(H0, R, N)

[HNN]=HEIGHT(H0, R, N);

INITIAL=H0;

FINAL=HNN(length(HNN));

MIDDLE=HNN(1,2: (length(HNN)-1));

TVD=FINAL+INITIAL+sum(MIDDLE*2);

Try:

Code:

function HNN=HEIGHT(H0, R, N)
HNN=H0.*R.^N;
function TVD=DISTANCE(H0, R, N)
[HNN]=HEIGHT(H0, R, N);
INITIAL=H0;
FINAL=HNN(length(HNN));
MIDDLE=HNN(2: (length(HNN)-1));
TVD=FINAL+INITIAL+2*sum(MIDDLE);