Optimise a reference that cuts my curve into 2 equal sections

1 回表示 (過去 30 日間)
fadi awar
fadi awar 2022 年 2 月 12 日
編集済み: Matt J 2022 年 2 月 12 日
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.

採用された回答

Matt J
Matt J 2022 年 2 月 12 日
編集済み: Matt J 2022 年 2 月 12 日
%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
  3 件のコメント
Matt J
Matt J 2022 年 2 月 12 日
編集済み: Matt J 2022 年 2 月 12 日
You probably need to upgrade your Matlab version.
If you cannot upgrade, you can try my revised version.
fadi awar
fadi awar 2022 年 2 月 12 日
Yeah, this one worked.
Thank you for your help!

サインインしてコメントする。

その他の回答 (2 件)

William Rose
William Rose 2022 年 2 月 12 日
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.
  5 件のコメント
dpb
dpb 2022 年 2 月 12 日
Attach the data as a .mat file.
Just looking at the graph, I'd venture it isn't possible to meet the constraints that the integral of the area be <95 when the magnitudes of the integrand are in the thousands. Just by a very crude approximation of the leftmost area (brown?) as roughly a rectangle of height ~(2800-1800) and a duration of 12, the integral would be roughly 1000*12 --> 12,000. Unless there's a very small scaling factor to be applied, it "just ain't a-gonna' happen".
fadi awar
fadi awar 2022 年 2 月 12 日
Kindly find attached the files.
I am to get the result according to my limits even if in this case of chosen data it wont matter a lot.
But Future wise I will be chaniging the data.
Thank you

サインインしてコメントする。


Catalytic
Catalytic 2022 年 2 月 12 日
編集済み: Catalytic 2022 年 2 月 12 日
midline = trapz(x,y)/(max(x)-min(x))

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by