Intergral calculation for data vector

6 visualizaciones (últimos 30 días)
Raoann
Raoann el 8 de Mayo de 2019
Editada: Raoann el 13 de Sept. de 2019
Hello,
I need to calculate the toatal energy of solar system and I have the solar power as 43200x1 double. I tried to use trapz and trapezodial method but I get only NAN as the answer. Can somone please guid me how to solve this problem?
So thankful for your help.
%% Iput data from a system:
B_V=B_V_12*12;
Inv_C_Amp=Inv_C_12_5*12.5;
Sol_C_Amp=Solar_C_12_5*12.5;
Enr_T_MWh=Energy_tot_0_5*0.5;
Enr_K_MWh=Energy_kiosk_0_5*0.5;
Enr_sch_MWh=Energy_school_0_5*0.5;
%% Calculate the rest of needed data by using the input data:
Bat_C=Inv_C_Amp-Sol_C_Amp;
Sol_P_W=Sol_C_Amp.*B_V;
Inv_P_W=Inv_C_Amp.*B_V;
% Efficiency= Total power out/Power into inverter
Eff=((Enr_T_MWh)./(Inv_P_W*1000000))*100;
Sol_Energy = trapz(t,Sol_P_W );
%% store Time duration for winter period where the lower temp in July.
t1=datetime(2018,07,01,2,1,0);
t2=datetime(2018,07,31,2,0,0);
t=t1:minutes(1):t2;
%% Plot the result of the data:
figure(1)
subplot(2,2,1)
plot(t,B_V,'r')
title('Battery voltage');
xlabel('Time');
ylabel('Volt');
subplot(2,2,2)
plot(t,Bat_C,'r')
title('Battery current');
xlabel('Time');
ylabel('A');
subplot(2,2,3)
plot(t,Inv_C_Amp,'b')
title('Inverter current');
xlabel('Time');
ylabel('A');
subplot(2,2,4)
plot(t,Sol_C_Amp,'g')
title('Solar current');
xlabel('Time');
ylabel('A');
%Figures for the plower data
figure(2)
subplot(2,1,1)
plot(t,Sol_P_W,'r')
title('Solar power');
xlabel('Time');
ylabel('Watt');
subplot(2,1,2)
plot(t,Inv_P_W,'b')
title('Inverter power');
xlabel('Time');
ylabel('Watt');
figure(3)
subplot(3,1,1)
plot(t,Enr_T_MWh,'b')
title('Total energy provided');
xlabel('Time');
ylabel('MWh');
subplot(3,1,2)
plot(t,Enr_K_MWh,'r')
title('Energy provided to kiosk');
xlabel('Time');
ylabel('MWh');
subplot(3,1,3)
plot(t,Enr_sch_MWh,'r')
title('Energy provided to school');
xlabel('Time');
ylabel('MWh');
figure(4)
plot(t,Eff,'r')
title('Inverter efficiency');
xlabel('Time');
ylabel('%');
%Energy calculation
%
% Sol_Energy = trapz(Sol_P_W );
% Sol_Energy= cumtrapz(Sol_P_W)
%
  3 comentarios
Abm
Abm el 8 de Mayo de 2019
Thank you for responding. No, I don’t have any NAN value in the (Sol_P_W) vector.
Erivelton Gualter
Erivelton Gualter el 8 de Mayo de 2019
Can you share the Sol_P_W data?

Iniciar sesión para comentar.

Respuesta aceptada

Rik
Rik el 8 de Mayo de 2019
You define your t vector only after you use it in trapz. But more importantly, your figure looks like you don't mean an integration, but a cumulative sum. In that case you can use the cumsum function to create that plot.
If that is not what you mean, please attach your variables in a mat file.
  2 comentarios
Raoann
Raoann el 8 de Mayo de 2019
thank you, Can you please explain how should I write the cumsum function?
Rik
Rik el 8 de Mayo de 2019
Did you read the documentation? I'm not sure how I should explain it differently, but I'll try anyway.
Suppose you have a much smaller solar output vector and a time vector:
%small example with some jagged peaks
sun=[0 0 1 5 20 20 4 0 0 1 0 5 50 100 100 1 0];
time=linspace(0,30,numel(sun));
Then you can make a plot like you showed in your comment:
sun=[0 0 1 5 20 20 4 0 0 1 0 5 50 100 100 1 0];
time=linspace(0,30,numel(sun));
total_power=cumsum(sun);
figure(1),clf(1)%only use clf during debugging
subplot(2,1,1)
plot(time,sun,'r')
title('Solar power')
subplot(2,1,2)
plot(time,total_power,'r')
title('Total solar energy')
ylim(ylim.*[1 1.1])%extend upper limit a bit

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by