Page 273 - Applied Numerical Methods Using MATLAB
P. 273
262 NUMERICAL DIFFERENTIATION/ INTEGRATION
function INTf = smpsns_fxy(f,x,c,d,N)
.. .. .. .. .. .. .. .. .. .. ..
sum_odd = f(x,y(2)); sum_even = 0;
for n = 4:2:N
sum_odd = sum_odd + f(x,y(n)); sum_even = sum_even + f(x,y(n - 1));
end
INTf = (f(x,y(1)) + f(x,y(N + 1)) + 4*sum_odd + 2*sum_even)*h/3;
.. .. .. .. .. .. .. .. .. .. ..
(cf) This problem illustrates that we must be provident to use the vector operation,
especially in defining a MATLAB function.
5.16 Volume of a Cone
Likewise in Section 5.10, modify the program “nm510.m” sothatituses
the routines “int2s()”and “dblquad()” to compute the volume of a cone
that has a unit circle as its base side and a unit height, and run it to obtain
the values of the volume up to four digits below the decimal point.)