MatLab - Cody Solutions Assume the variable r is already defined in your workspa
ID: 3662340 • Letter: M
Question
MatLab - Cody Solutions
Assume the variable r is already defined in your workspace. An instance of this is shown in Fig. 1. The value of r might be different than 5. But don't redefine or initialize r. Workspace value Name Figure 1: Variable r already exists in the workspace Write an expression for the circumference of a circle with its radius as r. Assign it to Cc. This part is done for you Write an expression for the area of a circle with its radius as r. Assign it to AC. Write an expression for the area of a sphere with its radius as r. Assign it to As Write an expression for the avolume of a sphere with its radius as r. Assign it to Vs. For all of the above expressions use the in-built MATLAB variable pi when necessary for the mathematical constant TExplanation / Answer
function area = cir_ar(r)
area = pi*r*r;
end
function area = spr_ar(r)
area = 4*cir_ar(r);
end
function vol = spr_vol(r)
rat = 4.0/3.0;
vol = rat*pi*r*r*r;
end