// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Solve a nonlinear equation by bisection // Not compiled or tested in-world // Setup: Put in a spare prim you own. Touch to solve on the interval zero to three. Adapt equation() and the bracket together. // Stop / restore: Disable or remove the script. It only reports to its owner and does not change prim properties. Reset clears its temporary state. // Notes: Bisection requires a continuous function and opposite signs at the bracket endpoints. Iteration count is capped at thirty. // License: see LICENSE in this distribution. // Original Incoprea example. MIT. Owner-only calculation; no scene changes. float equation(float x) { return x*x*x+x-10.0; } default { touch_start(integer detectedCount) { if (llDetectedKey(0) != llGetOwner()) return; float low=0.0; float high=3.0; float fLow=equation(low); float fHigh=equation(high); if (fLow*fHigh>0.0) { llOwnerSay("Bracket does not straddle a root."); return; } integer i; for (i=0; i<30; ++i) { float middle=(low+high)*0.5; float fMiddle=equation(middle); if (fLow*fMiddle<=0.0) high=middle; else { low=middle; fLow=fMiddle; } } float result=(low+high)*0.5; llOwnerSay("Root approximately "+(string)result+"; residual="+(string)equation(result)); } changed(integer change) { if (change & CHANGED_OWNER) llResetScript(); } }