Reversing the cumtrapz function
Show older comments
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 Comments
Mathieu NOE
on 9 Jan 2022
hello
seems like your time increment is constant and equal to 1 hour
it shouldn't be too much complicated to compute the derivatives using either diff or gradient (in conjunction with dt = 1 hour)
Noush
on 12 Jan 2022
Mathieu NOE
on 12 Jan 2022
can you share your data ?
What is the power value of the battery at the initial time ?
Once you have fixed this value (say y(1)), you get the values for later times recursively:
y(i+1) = 2*Y(i)-y(1)-2*sum_{j=1}^{i} y(j)
This follows directly from how the capacity values Y are computed from the power values y with "cumtrapz":
Y(1) = (y(1)+y(2))/2
Y(2) = (y(1)+y(2))/2 + (y(2)+y(3))/2 = y(1)/2 + y(2)+ y(3)/2
...
Noush
on 12 Jan 2022
Noush
on 12 Jan 2022
Answers (1)
One way, using func2mat from,
x=rand(1,10)
y=cumtrapz(x);
A=func2mat(@cumtrapz, ones(size(x)), 'doSparse', 0 );
A(1)=1;
y(1)=x(1);
x_recovered=y/A'
Categories
Find more on Power and Energy Systems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!