Q:

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 )

0

 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 ). If the function call expects two output arguments, the function will also return the surface area of the sphere (4 π r2 ).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now