How do can I change an input variable for get a different answer each time a loop runs?

This is my loop:
for Day = 1:365
Io = Isc*(1+(0.034*cos(2*pi*(Day/365.25))));
SolarDeclination = deg2rad(DeclinationAngle * sin(deg2rad(360/365)*(Day + var_2)));
SolarDeclinationDeg = rad2deg(SolarDeclination);
HoursAngle = acos(-tan(deg2rad(Latitude))*tan(SolarDeclination));
AltitudeAngle = asin((sin(SolarDeclination)*(sin(deg2rad(Latitude))))+(cos(SolarDeclination)*cos(deg2rad(15*1)))*cos(deg2rad(Latitude)));
AltitudeAngleDeg = rad2deg(AltitudeAngle);
ZenithAngle = deg2rad(90)- AltitudeAngle;
ZenithAngleDeg = rad2deg(ZenithAngle);
AM = 1/cos(ZenithAngle);
Id = 1.353*(0.7^(AM^0.678));
w = acos(-tan(deg2rad(Latitude)-deg2rad(PanelTilt))*tan(SolarDeclination));
Elevation = deg2rad(90-Latitude+SolarDeclinationDeg);
Rb = sin(Elevation+deg2rad(PanelTilt))/sin(Elevation);
Ioh = (1367*Id*(1+(0.034*cos(2*pi*(Day/365.25))))*((cos(SolarDeclination))*(cos(deg2rad(Latitude)))*(cos(deg2rad(Angle)))+((sin(SolarDeclination))*(sin(deg2rad(Latitude))))))/1000;
IohFiltered = (Ioh*PanelArea*PanelYield*PR)/100;
IohFilteredT = [IohFiltered>0];
IohFinal = IohFilteredT.*IohFiltered;
ConnectionCapacityHour = ones(24,1)*ConnectionCapacity;
Tilt = IohFinal*Rb;
MaxPanel = Tilt;
[row col] = find(MaxPanel>ConnectionCapacity);
LimitedOutputFinal = MaxPanel;
LimitedOutputFinal(row) = ConnectionCapacity;
ConstrainedAmount = [MaxPanel>LimitedOutputFinal].*(MaxPanel-LimitedOutputFinal)
DailyMaxPanelTotal = sum(MaxPanel)
DailyLimitedOutputTotal = sum(LimitedOutputFinal)
DailyConstrainedAmountTotal = sum(ConstrainedAmount);
%
if DailyConstrainedAmountTotal > BatteryCapacity;
DailyConnectionCapacityTotal = BatteryCapacity;
else
DailyConnectionCapacityTotal = DailyConstrainedAmountTotal;
end
%
OverallTotalEnergy = OverallTotalEnergy + DailyMaxPanelTotal
OverallLimitedEnergy = OverallLimitedEnergy + DailyLimitedOutputTotal
OverallConstrainedEnergy = OverallConstrainedEnergy + DailyConnectionCapacityTotal
PercentageConstrained = (OverallConstrainedEnergy/OverallTotalEnergy)*100
end
I want to change the PanelArea each time the loop runs. With
PanelArea = 1.6*[1.0;1.05;1.10;1.15;1.2;1.25;1.3;1.35;1.4;1.45;1.5]
(these I are the values are want to input each time.
Is this possible to carry out in a loop run without changing the PanelArea manually each time?

1 Kommentar

To make it clear I want to get ten values for each output of the loop (OverallTotalEnergy etc) by changing the PanelArea.

Antworten (1)

Study this
>> M = cssm
M =
0 0.0212 0.0212 0 7.1045 7.1045 0 0
0 0.0223 0.0223 0 7.4597 7.4597 0 0
0 0.0234 0.0234 0 7.8149 7.8149 0 0
0 0.0244 0.0244 0 8.1701 8.1701 0 0
0 0.0255 0.0255 0 8.5254 8.5254 0 0
0 0.0265 0.0265 0 8.8806 8.8806 0 0
0 0.0276 0.0276 0 9.2358 9.2358 0 0
0 0.0287 0.0287 0 9.5910 9.5910 0 0
0 0.0297 0.0297 0 9.9463 9.9463 0 0
0 0.0308 0.0308 0 10.3015 10.3015 0 0
0 0.0319 0.0319 0 10.6567 10.6567 0 0
where
function M = cssm
PanelArea = 1.6*[1.0;1.05;1.10;1.15;1.2;1.25;1.3;1.35;1.4;1.45;1.5];
M = nan( 11, 8 );
for ix = 1 : length( PanelArea )
[M(ix,1),M(ix,2),M(ix,3),M(ix,4),M(ix,5),M(ix,6),M(ix,7),M(ix,8)] ...
= cssm_( PanelArea(ix) );
end
end
function varargout = cssm_( PanelArea )
Isc = 1.0;
DeclinationAngle = 23.6;
var_2 = 1;
Latitude = 1;
PanelTilt = 1;
Angle = 1;
PanelYield = 1;
PR = 1;
ConnectionCapacity = 1;
BatteryCapacity = 1;
OverallTotalEnergy = 0;
OverallLimitedEnergy = 0;
OverallConstrainedEnergy = 0;
%
for Day = 1:365
Io = Isc*(1+(0.034*cos(2*pi*(Day/365.25))));
SolarDeclination = deg2rad(DeclinationAngle * sin(deg2rad(360/365)*(Day + var_2)));
SolarDeclinationDeg = rad2deg(SolarDeclination);
HoursAngle = acos(-tan(deg2rad(Latitude))*tan(SolarDeclination));
AltitudeAngle = asin((sin(SolarDeclination)*(sin(deg2rad(Latitude))))+(cos(SolarDeclination)*cos(deg2rad(15*1)))*cos(deg2rad(Latitude)));
AltitudeAngleDeg = rad2deg(AltitudeAngle);
ZenithAngle = deg2rad(90)- AltitudeAngle;
ZenithAngleDeg = rad2deg(ZenithAngle);
AM = 1/cos(ZenithAngle);
Id = 1.353*(0.7^(AM^0.678));
w = acos(-tan(deg2rad(Latitude)-deg2rad(PanelTilt))*tan(SolarDeclination));
Elevation = deg2rad(90-Latitude+SolarDeclinationDeg);
Rb = sin(Elevation+deg2rad(PanelTilt))/sin(Elevation);
Ioh = (1367*Id*(1+(0.034*cos(2*pi*(Day/365.25))))*((cos(SolarDeclination))*(cos(deg2rad(Latitude)))*(cos(deg2rad(Angle)))+((sin(SolarDeclination))*(sin(deg2rad(Latitude))))))/1000;
IohFiltered = (Ioh*PanelArea*PanelYield*PR)/100;
IohFilteredT = [IohFiltered>0];
IohFinal = IohFilteredT.*IohFiltered;
ConnectionCapacityHour = ones(24,1)*ConnectionCapacity;
Tilt = IohFinal*Rb;
MaxPanel = Tilt;
[row col] = find(MaxPanel>ConnectionCapacity);
LimitedOutputFinal = MaxPanel;
LimitedOutputFinal(row) = ConnectionCapacity;
ConstrainedAmount = [MaxPanel>LimitedOutputFinal].*(MaxPanel-LimitedOutputFinal);
DailyMaxPanelTotal = sum(MaxPanel);
DailyLimitedOutputTotal = sum(LimitedOutputFinal);
DailyConstrainedAmountTotal = sum(ConstrainedAmount);
%
if DailyConstrainedAmountTotal > BatteryCapacity;
DailyConnectionCapacityTotal = BatteryCapacity;
else
DailyConnectionCapacityTotal = DailyConstrainedAmountTotal;
end
%
OverallTotalEnergy = OverallTotalEnergy + DailyMaxPanelTotal;
OverallLimitedEnergy = OverallLimitedEnergy + DailyLimitedOutputTotal;
OverallConstrainedEnergy = OverallConstrainedEnergy + DailyConnectionCapacityTotal;
PercentageConstrained = (OverallConstrainedEnergy/OverallTotalEnergy)*100;
%
end
varargout = { ConstrainedAmount, DailyMaxPanelTotal, DailyLimitedOutputTotal ...
, DailyConstrainedAmountTotal ...
, OverallTotalEnergy, OverallLimitedEnergy, OverallConstrainedEnergy ...
, PercentageConstrained };
end

2 Kommentare

Thanks so much for this. Can you clarify what 'cssm' matrix is? How did you make this.
cssm is the name of the function, which is defined in the answer.

Diese Frage ist geschlossen.

Tags

Gefragt:

am 6 Mär. 2018

Geschlossen:

am 20 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by