Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. As you know, the volume of a hollow sphere is determined by, *(ro - r where r

ID: 3349670 • Letter: 1

Question

1. As you know, the volume of a hollow sphere is determined by, *(ro - r where r is the inner radius and ro is the outer radius. When creating computer code it is important to calculate correct results and be user friendly! You will write a MATLAB function accepting the radii in any order. The code will assign the larger dimension to the outer radius and the smaller dimension to the inner radius Invalid numerical input should inform the user of the error and request the user to input a new appropriate value.

Explanation / Answer

Matlab function:

function V = volumeofhollowsphere(r)
if r(1)<0 || r(2)<0
error('invalid numerical input');
else
if r(1)>r(2)
r0 = r(1);
ri = r(2);
else
r0 = r(2);
ri = r(1);
end
V = 4*pi*((r0^3)-(ri^3))/3;
end
end

command window log: