Download or view systemSolver3.frink in plain text format
// This program solves systems of equations.
use allTransforms.frink
class System
{
/* An array of equations, parsed to expressions. These use the
=== operator to separate the sides of the equations. */
var equations
/** A set of symbols that we're *not* going to solve for, for example,
constants, user-supplied knowns, etc. */
var ignoreSymbols = new set
new[equationList, ignoreSet=[]] :=
{
// TODO: Maybe parse strings or assignments into === equations?
equations = equationList
for ignore = ignoreSet
addIgnoreSymbols[ignoreSet]
}
/** Adds the symbols in the set (or array) to the set of ignoreSymbols. */
addIgnoreSymbols[ignoreSet] :=
{
for sym = ignoreSet
ignoreSymbols.put[makeSymbol[sym]]
}
/** Turns a string or a symbol into a symbol. */
makeSymbol[sym] :=
{
if type[s] == "Symbol"
return s
else
return constructExpression["Symbol", [s]]
}
dump[] :=
{
println["Equations:"]
for i = 0 to length[equations]-1
{
println["$i\t" + equations@i]
}
println[]
}
}
Download or view systemSolver3.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, eliasen@mindspring.com