Optimise a reference that cuts my curve into 2 equal sections
1 view (last 30 days)
Show older comments
Hello,
I am collecting data from excel, then basic idea is that i want to determine a constant value line that cuts my curve into 2 eqaual sections (area above the line and the curve = area under).

The objective is to determine the value of the red line.
0 Comments
Accepted Answer
Matt J
on 12 Feb 2022
Edited: Matt J
on 12 Feb 2022
%t= time, X=consumption, x=unknown midline
tc=t-t(1);
Xc=cumtrapz(t,X);
x=optimvar('x');
sol=solve( optimproblem('Objective',x,'Constraints',Xc-x*tc<=90,'ObjectiveSense','minimize') );
lb=sol.x; %lower bound
sol=solve( optimproblem('Objective',x,'Constraints',10<=Xc-x*tc,'ObjectiveSense','maximize') );
ub=sol.x; %upper bound
if lb>ub
disp 'Problem is infeasible'
else
xunc=trapz(t,X)/(t(end)-t(1)); %unconstrained solution
x=min(max(xunc,lb),ub); %constrained solution
end
More Answers (2)
William Rose
on 12 Feb 2022
If you mean that the area between the red line and the blue curve abve the line equals the area between the red line and the blue curve below the line, then the height of the red line is simply the mean value of the blue line data.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!