1. As you know, the volume of a hollow sphere is determined by, *(ro - r where r
ID: 3349660 • 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
function v=volume_sphere(r)
while (length(r)~=2)
disp('error:not appropriate inputs');
r=input('enter appropriate inputs');
end
r0=r(1);
ri=r(2);
if (r(1)<r(2))
r0=r(2);
ri=r(1);
end
v=(4*pi/3).*((r0^3)-(ri^3));
end
>> volume_sphere([2 1])
ans =
29.3215
>> volume_sphere([1 2])
ans =
29.3215
>> volume_sphere([1 2 3])
error:not appropriate inputs
enter appropriate inputs[1 2]
ans =
29.3215
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.