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

MATLAB script would help Write a user-defined MATLAB function that will receive

ID: 2249825 • Letter: M

Question

MATLAB script would help

Write a user-defined MATLAB function that will receive the radius (r) and height (h) of a cylinder and will return its surface area and volume. For function name and arguments, use Do the sanity check to make sure that inputs are positive numbers. Then use 2 subfunctions, called cylarea and cylvol, to calculate the surface area and volume of the cylinder S cylarea(r.h) V - cylvol(th) Repeat the procedure, but this time write an anonymous MATLAB function that will receive the radius (r) and height (h) of a cylinder as inputs and will return a 2X1 vector as output which contains its surface area and volume. You don't need to do any sanity check

Explanation / Answer

cylcalcs.m

function [S V] = cylcalcs(r,h)
if r>=0 && h>=0
S = cylarea(r,h);
V = cylvol(r,h);
else
error('invalid radius or volume of cylinder');
end
end

cylvol.m

function V = cylvol(r,h);
V = (pi*r*r*h);
end

cylarea.m

function S = cylarea(r,h);
S = (2*pi*r*r) +(2*pi*r*h);
end

%anonymous function

cylanonym.m

function out = cylanonym(r,h)

S = (2*pi*r*r) +(2*pi*r*h);
V = (pi*r*r*h);
out = [S;V];
end

output:

>> [S V] = cylcalcs(-5,2)