Using trapz for integrating with nonuniform spacing

Hello,
I am trying to compute the loss of an inductor by using data points for time and flux data from simulation. The simulation result for time has non-uniform spacing so I am using trapz to integrate instead of using sum since dtime is varying. However, the result I get when using trapz is significantly small and not close to the expected value.
Case 1: sum - take the average value of the time steps and do the integration using sum - result is close to expected value
Ploss = (dtime/T) * ki * Bptp^(b-a)*sum( (abs(dBdt)).^a );
Case2: dtime in this case is the time step between each data point so I am trying to integrate using each time step
Ploss=(ki * Bptp^(b-a))/T*(trapz(dtime,(abs(dBdt)).^a,1))
What could I be doing wrong in case 2? I believe that case 2 is a better approach since it uses the actual time step data instead of taking the average.
Thank you.

Answers (1)

Torsten
Torsten on 15 Nov 2022
Edited: Torsten on 15 Nov 2022
You mustn't use "dtime" in the call to "trapz", but the actual time vector t for which the simulation gave you the corresponding vector dBdt as result.

Asked:

on 15 Nov 2022

Commented:

on 17 Nov 2022

Community Treasure Hunt

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

Start Hunting!