Area under the curve with conditions?

I want to do following tasks,
First generate a time series load data between 550-1000 for one day 30 min interval, so is load(48*1) dataset
then set level_1 = 750 and draw a line on the graph,
then find out the area above this level_1 line and area under seprate level (lets say level_2 = 600) line seprately

 Risposta accettata

Try this:
t = 1:48; % Time Vector
load = randi(1000, 1, 48); % Create Data
level_1 = 750;
level_2 = 600;
above_level_1 = load >= level_1; % Logical Index Vector
area_1 = trapz(t(above_level_1), load(above_level_1)); % Area Under ‘Level_1’
below_level_2 = load <= level_2; % Logical Index Vector
area_2 = trapz(t(below_level_2), load(below_level_2)); % Area Under ‘Level_2’
figure
plot(t, load)
hold on
plot(xlim, [1 1]*level_1)
plot(xlim, [1 1]*level_2)
hold off
grid

10 Commenti

Can we find the min or max area if the Level_2 vary between the range of [600 800], find at which point the area(below the Level_2) is min or max?
with another constraint is that
area_1 - area_2 + K >= 0; % K is constant and lets say K= 800 ( 80% of max load)
I do not understand what you are asking.
You can easily calculate the area under ‘Level_2’ simply by re-defining it to be a different value. What do you intend by ‘min or max’?
With respect to:
area_1 - area_2 + K >= 0;
Do you want to calculate ‘K’, or given a specific value for ‘K’, determine if that statement is true?
I just want to calculate min area (task 2: max area ) if the Level_2 in the range of [600 800] and at which value of Level_2 , area is min and also when area is min, there must be
area_1 - area_2 + 800 >=0 satisfy.
You can probably use fmincon, however I cannot figure out how to set those constraints.
Yes it it further task of my prev que. but dont know how to set constaints and min area ?
It is not obvious to me, either. Since your other Question got several views although no replies, it appears that others also could not solve it.
How can I find the area above for level_1 for each two continuous time stamp like for example in figure(L1 is line of Level_1), find area seprate for each color code simillary for area below level_2. and after that how to find the sum of area for 1,(1+2), (1+2+3),(1+2+3+4),.....and so on strips.......Capture.JPG
Try this:
t = linspace(0, 24, 48); % Time Vector
load = 450*sin(2*pi*t/20)+550; % Create Data
level_1 = 750;
above_level_1 = load >= level_1; % Logical Index Vector
cload = cumtrapz(load(above_level_1)); % Cumulative Integral Of ‘load’
sload = [0 diff(cload)]; % Segmental (30 Min) Integral Of ‘load’
figure
plot(t, load)
hold on
bar(t(above_level_1), sload)
hold off
grid
legend('Load','30-Minute Integral', 'Location','S')
Experiment to get the result you want.
Can i get the area with these conditons at each continous interval.
The problem is that when above_level_1 having only one continuous data(1) then it can not calculate area but it should calculate for that interval at that point.??
I do not understand what you are asking.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by