The syntax for a user prompt is prompt = 'text' rather than what you had.
prompt = 'Please enter number of strips: ';
n = input(prompt);
As far as calculating the values of the function at each point and storing them in a vector goes, Matlab allows you to do this quite easily. First you define a vector with the points you are interested in.
finish = pi/2;
h = finish/n;
points = 0:h:finish;
Then, you can evaluate the function for each element of the vector. The '.^' notation is important, as it indicates you are carrying out the operation element-wise.
Putting it all together, you get something like this:
prompt = 'Please enter number of strips: ';
n = input(prompt);
finish = pi/2;
h = finish/n;
points = 0:h:finish;
v = sin(points).^3;
esno = 0;
osno = 0;
for j = 2:2:n
esno = esno + v(j);
end
for k = 3:2:n-1
osno = osno + v(k);
end
simpval = (h/3)*(v(1) + 4*esno + 2*osno + v(n+1))
Best Answer