Okay so I'm doing numerical integration using the trapezoid rule. I wrote the m file as such:
function y = trap(f,a,b,N)
h= (b-a)/N; y=0;
for i=1: N-1
x=(a+i*h);y=y+eval(f);
end
y=2*y; x=a; y=y+eval(f); x=b; y=y+eval(f);
y= (h/2)*y;
It says that the value assigned to x might be unused and I don't know why. If someone could tell me what I am doing wrong that would be awesome.
You need to pass $x$ into the function $f$ for evaluation; MATLAB is giving you the "X may not be used" warning because $x$ is changing in every loop without ever being passed into $f$
I have made a couple changes to the code (for readability, changing eval to feval...)