Debug a Wrong Result with a Plot

Compare expected and computed values, locate the first disagreement, test one cause, and verify the repair with numerical and visual evidence.

A plot can reveal where a numerical result departs from an expectation. It cannot tell us why. We still need the source values, a checked reference, and a small calculation that can separate observation from explanation.

The recurring raw table has three observations and two sensors:

Every value should be transformed by the rule:

calibrated = raw × 0.5 + 1.0

The expected table is therefore:

[[ 2.0,  6.0],
 [ 3.0,  8.0],
 [ 4.0, 10.0]]

This visible calculation is our reference. It gives the plot something precise to compare against.

Compare the Reference with the Computed Values

Suppose one branch of the program applies -1.0 instead of +1.0 to sensor 1 at observation 2. The program still runs:

expected sensor 1: [ 6.  8. 10.]
computed sensor 1: [ 6.  6. 10.]
difference: [ 0. -2.  0.]

Plot the expected and computed sensor series on the same axes. The same observation positions, units, and limits keep their coordinates comparable:

Locate one wrong transformed point

The expected and computed series differ only at observation 2. The difference panel connects that visible point to its numerical error.

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

The plot supports one observation: the computed sensor-1 point is 2 °C below the reference at observation 2, while the other displayed points agree. That sentence reports what the evidence shows. It does not yet claim a cause.

Q1. Separate observation from hypothesis

Which sentence is an observation rather than a possible explanation?

Choose one

Select one choice, then check.

HintKeep causes out of the first sentence

Name the position and two values. Words such as “must” and “probably” signal an explanation that still needs a test.

SolutionReport the visible numerical difference

“At observation 2, the computed sensor-1 value is 6 °C while the reference is 8 °C” is an observation. It remains true even if our first explanation is wrong.

Not attempted
Review

Not marked done.

Test a Hypothesis with the Smallest Failing Value

One possible explanation is that the offset sign is wrong in the operation that produced this point. Test that idea with the source value 14.0:

expected: 14.0 × 0.5 + 1.0 = 8.0
computed: 14.0 × 0.5 - 1.0 = 6.0

The small test reproduces the exact two-degree difference. It does not prove that no other defect exists, but it supports this hypothesis and points to one operation to inspect.

The difference table also identifies the first divergence:

[[1 1]]

Array position [1, 1] means the second observation and second sensor because NumPy positions begin at zero. Trace that position backward: plotted point → computed[1, 1] → transformation branch → raw[1, 1]. Stop at the first stage where the computed value differs from its checked reference.

Q2. Locate and test the first divergence

Which small calculation directly tests the suspected offset sign for source value 14.0?

Choose one

Select one choice, then check.

HintKeep only the failing operation

Use the source value 14.0, the multiplier 0.5, and the two possible offset signs.

SolutionCompare the two offset signs by hand

The correct +1.0 rule gives 8.0; the suspected -1.0 rule gives 6.0. This matches the observed difference.

Not attempted
Review

Not marked done.

Repair, Then Verify Twice

Repair the wrong branch by using the same +1.0 offset as the stated transformation:

computed[1, 1] = raw[1, 1] * 0.5 + 1.0

Numerical checks should pass after the repair:

Then rebuild the comparison plot. The expected and computed points should overlap, and the difference should lie on zero. The numerical checks enforce the result on later runs; the plot confirms that the repaired behavior also looks as expected across the complete series.

Do not repair only the picture. Changing a limit, hiding the reference, or removing the unusual point can make the figure look calmer while leaving the wrong value untouched. Repair the first divergent computation, rerun the full pipeline, then repeat both numerical and visual checks.

Q3. Repair and verify the transformed point

Repair transform_point, then verify shape, finite values, and numerical agreement. The displayed plot should show expected and computed points overlapping at all three observations.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintRepair the first divergent operation

Change the return expression to value * 0.5 + 1.0. Keep the numerical checks and comparison plot unchanged.

SolutionUse the stated calibration rule

The repaired sensor series is [6.0, 8.0, 10.0], its difference from the reference is zero, and all three numerical checks pass.

Not attempted
Review

Not marked done.

Use a plot to locate a disagreement, then return to the numbers. State the expectation, compare reference and computed values, record an observation before a hypothesis, reproduce the first divergence with a small test, and repair the earliest wrong operation. Finish with numerical checks and a rebuilt visual comparison.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 3 exercises marked done

Review

Not marked done.