Polynomial Calibration Explorer
Try Leave the five reference pairs in place and move Test Raw Reading (°C) from 40.0. Then change Raw 3 (°C) from 52.1 and compare the fit and residual table.
Observe Test Raw Reading (°C) starts at 40.0, with its corrected value shown below the fitted formula. Moving the test reading changes that result; editing a calibration pair also changes the coefficients and residuals.
Explain The five pairs determine a least-squares quadratic from raw to reference values; Test Raw Reading (°C) is substituted into that polynomial to produce the corrected reading.
Calculate calibration fit
Reset
Technical boundaries. The fit assumes all five pairs carry equal weight and always uses a quadratic, with controls limited to 0-100 degrees C. A determinant threshold rejects a singular fit; the residuals come from the fitting points rather than independent validation data.
Polynomial Calibration Explorer
When a straight line leaves curved errors, a richer model may help. The size of a coefficient alone does not establish whether the response is linear. Small errors at the points used for a fit do not prove accuracy elsewhere. Test the result at separate reference points.
Enter 3–5 calibration points (reference vs raw) and see how a quadratic polynomial fits the data. Adjust individual points to observe how nonlinearity affects the correction curve.
viewof mp_r1 = Inputs. range ([0 , 100 ], {value : 0 , step : 0.5 , label : "Reference 1 (°C)" })
viewof mp_m1 = Inputs. range ([0 , 100 ], {value : 1.8 , step : 0.1 , label : "Raw 1 (°C)" })
viewof mp_r2 = Inputs. range ([0 , 100 ], {value : 25 , step : 0.5 , label : "Reference 2 (°C)" })
viewof mp_m2 = Inputs. range ([0 , 100 ], {value : 26.5 , step : 0.1 , label : "Raw 2 (°C)" })
viewof mp_r3 = Inputs. range ([0 , 100 ], {value : 50 , step : 0.5 , label : "Reference 3 (°C)" })
viewof mp_m3 = Inputs. range ([0 , 100 ], {value : 52.1 , step : 0.1 , label : "Raw 3 (°C)" })
viewof mp_r4 = Inputs. range ([0 , 100 ], {value : 75 , step : 0.5 , label : "Reference 4 (°C)" })
viewof mp_m4 = Inputs. range ([0 , 100 ], {value : 77.8 , step : 0.1 , label : "Raw 4 (°C)" })
viewof mp_r5 = Inputs. range ([0 , 100 ], {value : 100 , step : 0.5 , label : "Reference 5 (°C)" })
viewof mp_m5 = Inputs. range ([0 , 100 ], {value : 98.5 , step : 0.1 , label : "Raw 5 (°C)" })
viewof mp_test_raw = Inputs. range ([0 , 100 ], {value : 40.0 , step : 0.1 , label : "Test Raw Reading (°C)" })
mp_points = [
{r : mp_r1, m : mp_m1},
{r : mp_r2, m : mp_m2},
{r : mp_r3, m : mp_m3},
{r : mp_r4, m : mp_m4},
{r : mp_r5, m : mp_m5}
]
mp_n = mp_points. length
mp_sum_x = mp_points. reduce ((s, p) => s + p. m , 0 )
mp_sum_x2 = mp_points. reduce ((s, p) => s + p. m * p. m , 0 )
mp_sum_x3 = mp_points. reduce ((s, p) => s + p. m * p. m * p. m , 0 )
mp_sum_x4 = mp_points. reduce ((s, p) => s + p. m * p. m * p. m * p. m , 0 )
mp_sum_y = mp_points. reduce ((s, p) => s + p. r , 0 )
mp_sum_xy = mp_points. reduce ((s, p) => s + p. m * p. r , 0 )
mp_sum_x2y = mp_points. reduce ((s, p) => s + p. m * p. m * p. r , 0 )
mp_det_main = mp_n * (mp_sum_x2 * mp_sum_x4 - mp_sum_x3 * mp_sum_x3)
- mp_sum_x * (mp_sum_x * mp_sum_x4 - mp_sum_x3 * mp_sum_x2)
+ mp_sum_x2 * (mp_sum_x * mp_sum_x3 - mp_sum_x2 * mp_sum_x2)
mp_det_a = mp_sum_y * (mp_sum_x2 * mp_sum_x4 - mp_sum_x3 * mp_sum_x3)
- mp_sum_x * (mp_sum_xy * mp_sum_x4 - mp_sum_x2y * mp_sum_x3)
+ mp_sum_x2 * (mp_sum_xy * mp_sum_x3 - mp_sum_x2y * mp_sum_x2)
mp_det_b = mp_n * (mp_sum_xy * mp_sum_x4 - mp_sum_x2y * mp_sum_x3)
- mp_sum_y * (mp_sum_x * mp_sum_x4 - mp_sum_x3 * mp_sum_x2)
+ mp_sum_x2 * (mp_sum_x * mp_sum_x2y - mp_sum_xy * mp_sum_x2)
mp_det_c = mp_n * (mp_sum_x2 * mp_sum_x2y - mp_sum_xy * mp_sum_x3)
- mp_sum_x * (mp_sum_x * mp_sum_x2y - mp_sum_xy * mp_sum_x2)
+ mp_sum_y * (mp_sum_x * mp_sum_x3 - mp_sum_x2 * mp_sum_x2)
mp_valid = Math . abs (mp_det_main) > 1e-10
mp_c0 = mp_valid ? mp_det_a / mp_det_main : 0
mp_c1 = mp_valid ? mp_det_b / mp_det_main : 1
mp_c2 = mp_valid ? mp_det_c / mp_det_main : 0
mp_corrected_test = mp_c2 * mp_test_raw * mp_test_raw + mp_c1 * mp_test_raw + mp_c0
mp_residuals = mp_points. map (p => {
const fitted = mp_c2 * p. m * p. m + mp_c1 * p. m + mp_c0;
return {ref : p. r , raw : p. m , fitted : fitted, error : Math . abs (fitted - p. r )};
})
mp_max_error = Math . max (... mp_residuals. map (r => r. error ))
mp_nonlinearity = Math . abs (mp_c2)
html `<div style="background: var(--bs-light, #f8f9fa); padding: 1rem; border-radius: 8px; border-left: 4px solid #9B59B6; margin-top: 0.5rem;">
<h4 style="color: #2C3E50; margin-top: 0;">Quadratic Polynomial Fit</h4>
${ mp_valid ? html `
<p><strong>Formula:</strong> corrected = ${ mp_c2. toFixed (6 )} × raw² + ${ mp_c1. toFixed (4 )} × raw + ( ${ mp_c0. toFixed (4 )} )</p>
<p><strong>Nonlinearity coefficient (a):</strong> ${ mp_c2. toFixed (6 )} ${ mp_nonlinearity < 0.0001 ? html `<span style="color: #16A085;">— Nearly linear! Two-point calibration would suffice.</span>` : html `<span style="color: #E67E22;">— Significant nonlinearity detected.</span>` } </p>
<hr style="margin: 0.5rem 0;">
<p><strong>Test result:</strong> Raw ${ mp_test_raw. toFixed (1 )} °C → Corrected <strong> ${ mp_corrected_test. toFixed (2 )} °C</strong></p>
<div style="margin-top: 0.5rem;">
<p style="color: #3498DB; margin-bottom: 0;"><strong>Residuals at calibration points</strong></p>
<table style="width: 100%; margin-top: 0.5rem; border-collapse: collapse; font-size: 0.9em;">
<tr style="background: #2C3E50; color: white;"><th style="padding: 4px 8px;">Raw</th><th style="padding: 4px 8px;">Reference</th><th style="padding: 4px 8px;">Fitted</th><th style="padding: 4px 8px;">Error</th></tr>
${ mp_residuals. map (r => html `<tr style="border-bottom: 1px solid #ddd;">
<td style="padding: 4px 8px;"> ${ r. raw . toFixed (1 )} </td>
<td style="padding: 4px 8px;"> ${ r. ref . toFixed (1 )} </td>
<td style="padding: 4px 8px;"> ${ r. fitted . toFixed (2 )} </td>
<td style="padding: 4px 8px; color: ${ r. error > 0.5 ? '#E74C3C' : '#16A085' } ;"> ${ r. error . toFixed (3 )} °C</td>
</tr>` )}
</table>
<p style="margin-top: 0.5rem;"><strong>Max residual error:</strong> ${ mp_max_error. toFixed (3 )} °C ${ mp_max_error > 0.5 ? html `<span style="color: #E74C3C;">— Consider adding more calibration points</span>` : html `<span style="color: #16A085;">— Good fit</span>` } </p>
</div>
` : html `<p style="color: #E74C3C;"><strong>Error:</strong> Cannot compute polynomial fit. Ensure calibration points have distinct raw values.</p>` }
</div>`
Back to the chapter