Write a function that will receive the radius r of a sphere. It will calculate and return the volume of the sphere (4/3π r3 )
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:10| Question number:4.10
All Answers
total answers (1)
spherecalcs.m
function [vol, varargout] = spherecalcs(r)
% Calculates and returns the volume of a sphere
% and possibly also the surface area
% Format of call: spherecalcs(radius)
% Returns volume of sphere, and if two output
% arguments are expected, also the surface area
vol = 4/3*pi*r^3;
if nargout == 2
varargout{1} = 4*pi*r^2;
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer