A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
The formula cannot work as written because:
[calculation using mid]
is only a placeholder. It must be replaced with the actual calculation currently used in E11, but using mid instead of D9.
Also, the original REDUCE formula does not update the low and high boundaries during each iteration.
A working binary-search pattern would look like this:
=LET(
target,E10,
iterations,50,
bounds,
REDUCE(
HSTACK(0,1000),
SEQUENCE(iterations),
LAMBDA(b,_,
LET(
low,INDEX(b,1,1),
high,INDEX(b,1,2),
mid,(low+high)/2,
result,YOUR_CALCULATION_USING_MID,
IF(
result>target,
HSTACK(low,mid),
HSTACK(mid,high)
)
)
)
),
AVERAGE(bounds)
)
The important part is:
result,YOUR_CALCULATION_USING_MID
You must replace that with the formula currently used in E11, replacing every reference to D9 with mid.
For example, if E11 currently contains:
=SUMPRODUCT(E19:E616/(1+D9)^A19:A616)
then inside the formula you would use:
result,SUMPRODUCT(E19:E616/(1+mid)^A19:A616)
There is one more important assumption: binary search only works if the result changes consistently in one direction as D9 increases. If E11 decreases when D9 increases, the comparison may need to be reversed:
IF(result>target,HSTACK(mid,high),HSTACK(low,mid))
instead of the version above.
So please post the exact formula currently in E11. Once we have that formula, we can replace the placeholder and give you a complete formula that you can paste directly into Excel.
If this answer was helpful, please consider marking it as helpful or accepting it as the answer.