Cramer’s Method Calculator
Enter the coefficients of the equations
function showBasic() {
document.getElementById("basicCalculator").style.display = 'block';
document.getElementById("advancedCalculator").style.display = 'none';
}
function showAdvanced() {
document.getElementById("advancedCalculator").style.display = 'block';
document.getElementById("basicCalculator").style.display = 'none';
}
function calculate() {
if (document.getElementById("basicCalculator").style.display !== 'none') {
const a11 = parseFloat(document.getElementById("a11").value);
const a12 = parseFloat(document.getElementById("a12").value);
const b1 = parseFloat(document.getElementById("b1").value);
const a21 = parseFloat(document.getElementById("a21").value);
const a22 = parseFloat(document.getElementById("a22").value);
const b2 = parseFloat(document.getElementById("b2").value);
if (!isNaN(a11) && !isNaN(a12) && !isNaN(b1) && !isNaN(a21) && !isNaN(a22) && !isNaN(b2)) {
const det = a11 * a22 - a12 * a21;
const x = (b1 * a22 - b2 * a12) / det;
const y = (a11 * b2 - a21 * b1) / det;
document.getElementById("solution2x2").value = `x = ${x.toFixed(2)}, y = ${y.toFixed(2)}`;
} else {
alert("Please fill in all fields to calculate the solution.");
}
} else {
const a11 = parseFloat(document.getElementById("a11_3").value);
const a12 = parseFloat(document.getElementById("a12_3").value);
const a13 = parseFloat(document.getElementById("a13").value);
const b1 = parseFloat(document.getElementById("b1_3").value);
const a21 = parseFloat(document.getElementById("a21_3").value);
const a22 = parseFloat(document.getElementById("a22_3").value);
const a23 = parseFloat(document.getElementById("a23").value);
const b2 = parseFloat(document.getElementById("b2_3").value);
const a31 = parseFloat(document.getElementById("a31").value);
const a32 = parseFloat(document.getElementById("a32").value);
const a33 = parseFloat(document.getElementById("a33").value);
const b3 = parseFloat(document.getElementById("b3").value);
if (!isNaN(a11) && !isNaN(a12) && !isNaN(a13) && !isNa