What you see. A 20 x 12 grid field with smooth natural variation in soil water capacity (85-165 mm) and soil mineral nitrogen. One simulated day passes per tick. Change a control and the whole season restarts.
W(t+1) = W + rain + irrigation x efficiency - ETa, with drainage when W exceeds the capacity. ETa = ETm x min(1, W / (0.5 capacity)) and ETm = ET0 x Kc. Irrigation efficiency is 0.55 for flood and 0.90 for drip (typical orders of magnitude); of the water that does not reach the root zone, 60% is assumed to percolate below it (carrying nitrate) and 40% is lost to evaporation and runoff.Ya/Ym = 1 - Ky (1 - ETa/ETm) with Ky = 1.25 for a maize-like crop, multiplied by a nitrogen response 1 - exp(-U/70) (Mitscherlich shape, normalised so U = 210 kg N/ha is full demand). Ym = 11 t/ha.N (1 - exp(-D / (0.9 capacity))) to leaching for each drainage event D. Splitting doses and placing less N on already-rich zones (variable rate, mean-preserving) cut the amount sitting in the soil when heavy rain arrives. A cover crop is modelled as a flat 30% cut in leaching (illustrative).Checks shown in the page. Water and nitrogen mass-balance closure (supply = uses + storage, catching bookkeeping errors) and the FAO-33 relation evaluated by hand at 80% ET. The right-hand plot reruns the entire season for 16 fertiliser rates in the background to draw the diminishing-returns curve.
Simplifications. No temperature, pests, runoff, volatilisation, phosphorus, soil carbon changes or multi-year rotation; daily rainfall is a fixed pseudo-random pattern scaled to the chosen season total.