Fzero: finding optimal integration limit between to areas

Given are measured datapoints, concentration vs time (t_0 to t_end). I do not have the exact function.
I'd like to find the specific time t_opt, where the area under the function (calculated using trapz) from t_0 to t_opt is equal to the area above the function from t_opt to t_end. Hopefully the drawing attached explains this more clearly.
My unsuccesful attempt is attached. Would really appreciate some help.

 Accepted Answer

Without your data, this is just an hypothetical approach.
At least for a first approximation, I would use cumtrapz, not trapz. The part between ‘t0’ and ‘t_opt’ is simply the cumtrapz(t,c) result. The entire area under ‘c_max’ (the unlabeled upper asymptote) is ‘c_max*(te-t0)’, so the area between your curve and ‘c_max’ would appear to be ‘c_max*(te-t0)-cumtrapz(t,c)’. Equating these, with a bit of algebra, suggests my approach.
See if this works:
c_int = cumtrapz(t,c);
t_opt = interp1(c_int, t, c_max*(te-t0)/2, 'linear');
Note This is obviously UNTESTED CODE.

More Answers (1)

Thanks for the help. Didn't work exactly but the function cumtrapz helped me figure it out.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!