HenryWilder / amitygxmod-calculator

A browser extension designed for Opera GX, made for helping with algebra
1 stars 0 forks source link

System of equations #15

Open HenryWilder opened 11 months ago

HenryWilder commented 11 months ago

The calculator (or macro) section should have an option to solve for $n$ variables in a systems of $n$ equations.

HenryWilder commented 11 months ago

Idea 1

It seems a little complicated, but this might be possible? image image

HenryWilder commented 11 months ago

Idea 2

This might require some more complex input or parsing, but it might be simpler overall. image

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;
};