"What does cumtrapz do?"
cumtrapz(y, x) performs cumulative numerical integration using the trapezoidal rule. It calculates the cumulative area under the curve y(x) from the start up to each point. If your power is in kilowatts (kW) and time is in hours, then:
- cumtrapz(time, power) gives you energy in kWh (kilowatt-hours)
- This is because ∫P(t)dt = Energy, and the units work out: kW × hours = kWh
"Which means I dont understand cumtrapz correctly"
There are actually several problems here:
- Second plot: Power × Time - This is NOT energy! This would have units of kW×h², which is meaningless physically. If you're multiplying power by the time vector element-wise, you're getting something that grows much faster than energy should.
- Third plot: cumtrapz(Power) × Time - This is also wrong: you are taking the cumulative integral of power (which gives energy), then multiplying by time again, giving you units of kWh×h = kWh².
Try plotting just cumtrapz(time, power) to see the actual energy consumption. I will demonstrate with some fake data (this would be much easier if you uploaded some sample data):
P = min(120, max(90+(140-90)*(1-T/8500), 90+(140-90)*(T-9500)/8500));