proc iml;
start tr(x,y); * create function called tr;
N = nrow(x);
dx = x[2:N] - x[1:N-1];
ymean = (y[2:N] + y[1:N-1]) / 2;
return(dx` * ymean );
finish tr;
x = do(-2,5,0.01);
print "Integral of a over x is" ( tr(x,0#x+1) ); *Answer is 7;
I keep receiving the (execution) invalid subscript or subscript out of range. How do I solve this problem and get the correct answer? I've tried taking out the -1 in x[1:N-1]; and y[1:N-1], but it gives me the wrong answer. Is it because I need to assume equally spaced intervals? If so, how would I do that. Trapezoidal equation: (x-x0)*(y+y0)/2 or (xi - xi-1) * (yi + yi-1) / 2.