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

Please do with Matlab , These problems are separate program but related together

ID: 3744007 • Letter: P

Question

Please do with Matlab , These problems are separate program but related together Write a function that calculates the mass of a hollow sphere. The function takes three arguments for the inside and outside diameters (in em) and density (in g/cm') and returns the mass of the sphere in grams. Name your function massHollowSphere.m Add comments to your function and save it. In the command prompt try the following commands to test your function: >> massHollowSthere (1, 1.2, 10); SsmassHollowsphere( 20, 22, 30); >>help massHollowSphere e>

Explanation / Answer

First Answer:

clear all;
clc;

function mass = massHollowSphere(r, R, d)

%This function calculates mass of a hallow sphere

%Taking inner radius, outer radius and density as input

mass = (d*4*pi/3)*(R^3 - r^3)/8;

end

massHollowSphere(1, 1.2, 10)

massHollowSphere(20, 22, 30)

help massHollowSphere

Second Answer:

clear all;
clc;

function mass = massHollowSphere(r, R, d)

%This function calculates mass of a hallow sphere

%Taking inner radius, outer radius and density as input

mass = (d*4*pi/3)*(R^3 - r^3)/8;

end

r = input("Enter inner radius: ");

R = input("Enter outer radius: ");

d = input("Enter density: ");

fprintf("Mass is %f ", massHollowSphere(r, R, d))