MATLAB: How to write a function that uses the function I have to plot A and V versus a for 0.25 <= a <= 4 inches.

MATLAB

function [V, A] = calc(a)
if (a > 4)
if (a < 0.25)
V = 1/4 * pi * ((a+(a+2)) * ((a+2)-a) ^ 2);
A = pi ^ 2 * ((a+2) ^ 2 - a ^ 2);

Best Answer

function [V,A] = calc(n)
a = linspace(0.25,4,n);
V = 1/4 .* pi .* ((a+(a+2)) .* ((a+2)-a) .^ 2);
A = pi ^ 2 .* ((a+2) .^ 2 - a .^ 2);
plot(a,V,a,A);
The input, n, is the number of subdivisions to use along 0.25 to 4. Or to be more correct, n is the total number of points to use in the plot, including the two end-points.