hemispheres.frink

View or download hemispheres.frink in plain text format

// Demonstration and test of solving systems of equations.

use systemSolver2.frink
symbolicMode[true]
showApproximations[false]

// These are the equations for a sphere, in no particular order.  Frink will
// rearrange and solve as necessary.
sphere = new System[[volume === 4/3 pi radius^3,
                     diameter === 2 radius,
                     circumference === pi diameter,
                     mass === density volume],
                    ["pi"]]

// Print out all the solutions for all variables.  This is just showing off.
println["All solutions:"]
println[join["\n", sphere.solveAll[]]]


// Print out all the symbolic solutions for mass.  This is also showing off.
println[]
println["Symbolic solutions for mass:"]
println[join["\n", sphere.solveFor["mass"]]]


// These are our knowns
args = [["circumference", 11*2 in], ["density", 0.9 g/cm^3]]


// Solve for mass, just keeping the real-valued solutions.
println[]
println["Numeric solution:"]
println[select[eval[sphere.solveForValues["mass",args]], {|x| !isComplex[x]}]->"pounds"]


View or download hemispheres.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 17596 days, 22 hours, 2 minutes ago.