Open HenryWilder opened 11 months ago
It seems a little complicated, but this might be possible?
This might require some more complex input or parsing, but it might be simpler overall.
Simpler, because I think it might be easier to write intermediate functions for.
Something like
interface Equation {
xCoef: number;
yCoef: number;
solution: number;
}
/** @returns Reciprocal of system1 */
const reciprocalEq = (system1: Equation, system2: Equation): Equation => {
const quotient: number = -(system1.xCoef / system2.xCoef);
return {
xCoef: system1.xCoef * quotient,
yCoef: system1.yCoef * quotient,
solution: system1.solution * quotient
};
};
const sumOfEqs = (system1: Equation, system2: Equation): Equation => {
return {
xCoef: system1.xCoef + system2.xCoef,
yCoef: system1.yCoef + system2.yCoef,
solution: system1.solution + system2.solution
};
};
/** @returns Value of y. */
const systemOfEquations = (system1: Equation, system2: Equation): number => {
const reciprocal: Equation = reciprocalEq(system1, system2);
const sum: Equation = sumOfEqs(reciprocal , system2);
const y: number = sum.solution / sum.yCoef;
return y;
};
The calculator (or macro) section should have an option to solve for $n$ variables in a systems of $n$ equations.