Explanation:
Specific gravity of gold = G = 19.3
We know that the specific gravity of gold is given by
G = ρg/ρw
Where ρg is the density of gold and ρw is density of water which is 1000 kg/m³
Now we can find out the density of gold
ρg = G*ρw
ρg = 19.3*1000
ρg = 19300 kg/m³
We also know that density and mass are related as
density = mass/volume
ρg = m/V
where volume of cube is given by
V = s³
Where s is the length of each side
ρg = m/s³
s³ = m/ρg
s = ∛(m/ρg) meters
To convert from meters to inches multiply by 39.37
s = ∛(m/ρg)*39.37 inches
Finally we get the relation of mass and length of side of a gold cube.
Matlab Code:
density = 19300;
% get input from the user that is mass of gold in kg
mass= input('Please input mass of gold in kg\n');
% check if the user has entered valid mass if it is less than or equal to zero then display error
if (mass<=0)
fprintf('Error: Wrong input! please try again');
else
% If the mass is valid then calculate the length of side of the cube
s = (mass/density);
% nthroot() is used to calculate the cube root
s = nthroot(s,3);
% to convert from meters to inches
s = s*39.37;
% finally display the length with 2 decimal points accuracy
fprintf('The length of side of the gold cube is: %.2f inches\n', s);
end
Output:
Please input mass of gold in kg
-2
Error: Wrong input! please try again
Please input mass of gold in kg
0.4
The length of side of the gold cube is: 1.08 inches