Jump to content

Module:User:Mr rnddude/Sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr rnddude (talk | contribs) at 06:51, 19 April 2017 (Fix). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- This is my module sandbox.
-- The below is simplistic practice for
-- working out how to write simpler modules.
-- My first foray into modules was overly
-- complex. Successful, but, complex.

local p = {}

g = 9.8 -- Acceleration due to gravity on the surface of the Earth in m/s^2
Me = 5.9722E24 -- Mass of the Earth in kilograms
r = 6371000 -- Radius of the Earth in metres
V = 4/3 * math.pi * (r * r * r) -- Volume of a sphere
-- Density = M / V

function p.Volume_earth(frame)
	-- Volume = 4/3 * pi * (r * r * r)
	return 'Volume of the Earth is ' .. 4/3 * math.pi * (r * r * r) .. 'm^3'
end

local function localVe (Ve)
	-- Local formulation of the above function, used in p.Density_earth(frame)
	return 4/3 * math.pi * (r * r * r) -- output is m^3 (r is in m)
end

function p.Density_earth(frame)
	-- Density = M / V
	local Ve = 4/3 * math.pi * (r * r * r)
	return 'Density of the Earth is ' .. Me / Ve .. 'kg/m^3'
end

-- If you have the average mass of the Earth per unit volume. Logically,
-- it should be possible to work out the mass of an area of the Earth.
-- Given this fact, the core should have a mass of...
function p.Mass_inner_core(frame)
	-- This will result in an incorrect result. The core is far denser then
	-- the Earth as whole. Will make an interesting case study though. Just
	-- general fun doing math and using Lua
	local r = 1220000 -- Earth's core has a radius of 3,485km (about half
	local Ve = 4/3 * math.pi * (r * r * r)
	local rho = 5513.4433755194
	return rho * Ve
end

function p.Volume_of_MIC(frame)
	local r = 1220000
	return 4/3 * math.pi * (r * r * r) -- output is m^3 (r is in m)
end

function p.Volume_of_MIC_to_ME(frame)
	-- Volume of MIC as a percentage of the whole
	local ric = 1220000
	local Vic = 4/3 * math.pi * (ric * ric * ric)
	local Ve = 4/3 * math.pi * (r * r * r)
	return Vic / Ve
end

function p.Proportion_MIC_to_ME(frame)
	-- Function goal; to automatically work out the proportion if the mass of
	-- the inner core of the Earth to the total mass of the Earth.
	local r = 1220000
	local Ve = 4/3 * math.pi * (r * r * r)
	local rho = 5513.4433755194
	return ((rho * Ve) / Me) * 100
end

-- Assume that the solid core is made entirely of iron. It makes sense that
-- denser materials will congregate at the center of a solid mass.
function p.Mass_IC_iron(frame)
	local r = 122000
	local rho = 7974 -- Density of iron in kg/m^3
	local Vi = 4/3 * math.pi * (r * r * r)
	return Vi * rho
end

function p.Proportion_MICi_to_ME(frame)
	local r = 1220000
	local rho = 7974
	local Vi = 4/3 * math.pi * (r * r * r)
	return ((rho * Vi) / Me) * 100
end

return p