SolverTest.frink

Download or view SolverTest.frink in plain text format


// This program tests the Solver class.
use Solver.frink

symbolicMode[true]
showApproximations[false]

// Derive the altitude for geosynchronous orbit.
s = new Solver[[a === v^2/r,
                a === omega^2 r,
                omega === 2 pi f,
                T === 1/f,
                F === m a,
                F === G m1 m2 / d^2,
                m1 === m,
                d === r,
                T === 1 day,
                m2 === earthmass],
               ["G","pi", "earthmass", "day"]]

//s.dump[]
//s.draw[]
s.initialize[]
//s.draw[]
//println[s.getEquationNode[0].getSolutions["v"]]
//println[s.getEquationNode[0].getSolutions["a"]]
//s.dump[]
//sols = s.solveAll[]
//println["All:"]
//println[join["\n", sols]]
args = [["T", 1 day], ["m2", earthmass]]
sols = s.solveForSymbolic["d", args]
println["Symbolic:"]
println[join["\n", sols]]
println[]
//s.draw[]
println["Geosynch distance:"]
sols = s.solveFor["d", args]
println[join["\n", sols]]
println[]
args = [["m2", earthmass], ["T", 1 day]]
//sols = println[join["\n",s.solveFor["d", []]]]
//s.draw[]
println[]



// Physical system // Suppose the stone is thrown at an angle of 35.0° below
// the horizontal from the same building (h = 50.0 m) as in the example above.
// If it strikes the ground 60.8 m away, find the following. (Hint: For part
// (a), use the equation for the x-displacement to eliminate v0t from the
// equation for the y-displacement.)
// (a) the time of flight
// (b) the initial speed
// (c) the speed and angle of the velocity vector with respect to the
//    horizontal
phys = new Solver[[vx === v0 cos[35 degrees],
                   vy0 === v0 sin[35 degrees],
                   y === h0 - 1/2 g t^2 - vy0 t,
                   x === vx t,
                   x === 60.8 m,
                   g === 9.8 m/s^2,
                   h0 === 50 m,
                   y === 0 m],
                  ["degrees", "m", "gravity", "s"]]
//phys.dump[]
//phys.draw[]
sols = phys.solveFor["t", []]
println[]
println["Solutions for t:"]
println[join["\n", sols]]
println[]

println["Solutions for v0:"]
sols = phys.solveFor["v0", []]
println[join["\n", sols]]
println[]
//phys.draw[]
println[]

sols = phys.solveAll[]
println["All:"]
println[join["\n", sols]]


phys.interact[]


// Simultaneous equation test.
//t = new Solver[[3a - 2b + c === 3,  4a + b - 3c === 10,  a + 6b - 2c === 5]]
t = new Solver[[3a - 2b + c === 3,  4a + b - 3c === 10, a + 6b - 2c === 5]]
//t.draw[]
//t.dump[]
println[join["\n",t.solveAll[]]]
//t.draw[]
//t.dump[]
println[]


// Simultaneous equation test2
ss = new Solver[[a^2 + b^2 === 50, a + b === 10],[]]
ss.draw[]
//ss.dump[]
println[join["\n",ss.solveAll[]]]
println[]
println["Solutions for a: " + ss.solveFor["a", []]]
println["Solutions for b: " + ss.solveFor["b", []]]
println[]


println[]
lol = new Solver[[a + 2b + 2c === -1, a + 2b === -1, a + b - c === 0]]
println[join["\n",lol.solveAll[]]]


println[]
lol2 = new Solver[[1.1a + 2.2b + 2.2c === -1.1, a + 2b + 99.9c === -1, a + b - c === 0]]
println[join["\n",lol2.solveAll[]]]


println[]
lol3 = new Solver[[1.1a + 3.3b + 2.2c === -2.2, a + 3b + 0.9c === -2, a + b - c === 0]]
println[join["\n",lol3.solveAll[]]]


Download or view SolverTest.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 20217 days, 23 hours, 37 minutes ago.