Reversing the cumtrapz function

7 Ansichten (letzte 30 Tage)
Noush
Noush am 9 Jan. 2022
Bearbeitet: Torsten am 12 Jan. 2022
Hi, I have created integral values in a table with the cumtrapz function. The cumtrapz values represent the capacity of a battery. Now, I'd like to reverse it, in order to find the power values of the battery, and plot those on a graph. So probably I need differentiate the values so that I get the y-values I need to plot it. What is the funciton for that? My table looks like this, as you can see, the first column are datetime values. Column 6 and 7 are the cumtrapz values that I want to differentiate over the first column:
  6 Kommentare
Noush
Noush am 12 Jan. 2022
Yes of course, here is the complete code:
And also I'm not sure I asked my question correctly, so to clarify:
KGesamt is the battery capacity that I have found. I now would like to find the power values for the loading and unloading processes, which entails differentiating KGesamt over the times, when the colum 2 is bigger than 0 and seperately for when column 3 is bigger than zero. Thats the issue, bc I don't know how to seperately differentiate!
q1 = Tabelle{:,1} - Grundlast(:,C) - AL.Leistung_Gesamt; %q1 ist der Ladewert, der sich aus den Leistungsflussgraphen ergibt
w1 = Tabelle{:,1} - Grundlast(:,C) > 0 | Tabelle{:,1} - AL.Leistung_Gesamt > 0; %w1 ist ein Vektor mit einer eins, wenn die Ladebedingung erfüllt ist
%und eine null, wenn sie nicht erfüllt wird
idx1 = find(w1); %idx1 ist ein Vektor mit den indexwerten von w1
y1 = zeros(168,1); %y1 ist zunächst als null Vektor definiert
y1(idx1) = q1(w1); %y1 wird aufgefüllt mit den Leistungswerten des Graphen an den Stellen,
%an denen die Bedingung w1 1 ist
y1(y1 > 600) = 600; %Begrenzt die maximale Ladeleistung auf 600kW (Batteriebegrenzung)
y1(y1 <= 0) = 0; %Spezifiziert, dass nur positive y Werte dargestellt werden sollen (Ladeprozess)
%Unloading Process
q2 = Grundlast(:,C) + AL.Leistung_Gesamt - Tabelle{:,1}; %q2 ist der Entladewert, der sich aus dem Leistungsflussgraphen ergibt
w2 = Grundlast(:,C) - Tabelle{:,1} > 0 | AL.Leistung_Gesamt - Tabelle{:,1} > 0; %w2 ist ein Vektor mit einer eins, wenn die Ladebedingung erfüllt ist
%und eine null, wenn sie nicht erfüllt wird
idx2 = find(w2); %idx2 ist ein Vektor mit den indexwerten von w1
y2 = zeros(168,1); %y2 ist zunächst als null Vektor definiert
y2(idx2) = - q2(w2); %y2 wird aufgefüllt mit den negativen Leistungswerten des Graphen an den Stellen,
%an denen die Bedingung w2 1 ist
y2(y2 < -750) = -750; %Begrenzt die maximale Entladeleistung auf 750kW (Batteriebegrenzung)
y2(y2 >= 0) = 0; %Spezifiziert, dass nur negative y Werte dargestellt werden sollen (Entladeprozess)
varNames2 = {'Datum_und_Zeit','Ladeleistung','Entladeleistung','Ausgelegte_Ladeleistung','Ausgelegte_Entladeleistung','Ausgelegte_Ladekapazitaet','Ausgelegte_Entladekapazitaet'}; %Headings of the table
BigTable = table(dt,y1,y2,zeros(168,1),zeros(168,1),zeros(168,1),zeros(168,1),'VariableNames',varNames2);
%plots
figure(2)%loading curve
subplot(3,1,1)
area(BigTable.Datum_und_Zeit,BigTable.Ladeleistung)
ylim([-100 1000]);
title("Ladeprozess")
subplot(3,1,2)%unloading curves
area(BigTable.Datum_und_Zeit,BigTable.Entladeleistung)
ylim([-1000 1000]);
title("Entladeprozess")
%Zeitvariablen umgerechnet als double
dn1 = datenum(BigTable{1:24,1});
dn2 = datenum(BigTable{25:48,1});
dn3 = datenum(BigTable{49:72,1});
dn4 = datenum(BigTable{73:96,1});
dn5 = datenum(BigTable{97:120,1});
dn6 = datenum(BigTable{121:144,1});
dn7 = datenum(BigTable{145:168,1});
dn8 = datenum(BigTable{:,1})-datenum(BigTable{1,1});
%Integrale der 7 Tage für den Ladeprozess
A1 = cumtrapz(dn1,BigTable{1:24,2});
A2 = cumtrapz(dn2,BigTable{25:48,2});
A3 = cumtrapz(dn3,BigTable{49:72,2});
A4 = cumtrapz(dn4,BigTable{73:96,2});
A5 = cumtrapz(dn5,BigTable{97:120,2});
A6 = cumtrapz(dn6,BigTable{121:144,2});
A7 = cumtrapz(dn7,BigTable{145:168,2});
%Integrale der 7 Tage für den Entladeprozess
A8 = - cumtrapz(dn1,BigTable{1:24,3});
A9 = - cumtrapz(dn2,BigTable{25:48,3});
A10 = - cumtrapz(dn3,BigTable{49:72,3});
A11 = - cumtrapz(dn4,BigTable{73:96,3});
A12 = - cumtrapz(dn5,BigTable{97:120,3});
A13 = - cumtrapz(dn6,BigTable{121:144,3});
A14 = - cumtrapz(dn7,BigTable{145:168,3});
KLaden = [A1 A2 A3 A4 A5 A6 A7];
KEntladen = [A8 A9 A10 A11 A12 A13 A14];
KLaden = min(KLaden, 3040); %Begrenzt die Kapazität der Ladung auf 3040 kWh
KEntladen = min(KEntladen, KLaden); %Spezifiziert, dass nur soviel entladen werden kann, wie geladen wurde
KGesamt = max(max(KLaden)*3*1.1); %Ladevorgang ist ohnehin die größere Zahl, da Entladevorgang daran angepasst wurde
Noush
Noush am 12 Jan. 2022
I tried to do this just now:
%Differentiation
Y3 = repmat(KGesamt,24,1);
AA1 = gradient(BigTable{1:24,1},Y3);
It gave me only infinity values.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt J
Matt J am 12 Jan. 2022
Bearbeitet: Matt J am 12 Jan. 2022
One way, using func2mat from,
x=rand(1,10)
x = 1×10
0.3476 0.7709 0.3411 0.2683 0.3744 0.3818 0.3278 0.4990 0.5167 0.6496
y=cumtrapz(x);
A=func2mat(@cumtrapz, ones(size(x)), 'doSparse', 0 );
A(1)=1;
y(1)=x(1);
x_recovered=y/A'
x_recovered = 1×10
0.3476 0.7709 0.3411 0.2683 0.3744 0.3818 0.3278 0.4990 0.5167 0.6496

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by