How to find Matano plane
Maybe I'm missing something but isn't the value for z
just the solution of the equation
(z - xLimits[[1]])*yLimits[[1]] + (xLimits[[2]] - z)*yLimits[[2]] == area
where area
is the total area under the graph, i.e.
area = NIntegrate[GetRLine3[{data}, 3][x], {x, xLimits[[1]], xLimits[[2]]}][[1]]
Therefore, z
is equal to
z = (xLimits[[2]]*yLimits[[2]] - xLimits[[1]]*yLimits[[1]] - area)/
(yLimits[[2]] - yLimits[[1]])
For a start it seems to me that you can use NIntegrate
:
z = step = xLimits[[1]] + (xLimits[[2]] - xLimits[[1]])/2;
While[
{part1, part2} =
Flatten[{
NIntegrate[f - yLimits[[1]], {x, xLimits[[1]], z}],
-NIntegrate[(f - yLimits[[2]]), {x, z, xLimits[[2]]}]
}];
part1 != part2,
If[part1 > part2, step /= 2; z -= step, step /= 2; z += step]
] // Timing
z
{0.14, Null} 10.3795