How to Fix Limiting Variable

1 回表示 (過去 30 日間)
Brady
Brady 2024 年 4 月 17 日
回答済み: Karanjot 2024 年 4 月 22 日
%% Calculate the amount of energy in the system's battery in each time step
for i = 2:length(timesteps)
excess_energy_kWh = E(i) - home_energy_use_kWh(i); % Calculate excess energy
if excess_energy_kWh > 0 % If excess energy is produced
battery_energy_kWh(i) = min(battery_energy_kWh(i-1) + excess_energy_kWh, battery_capacity_kWh); % Charge battery
else % If energy deficit
battery_energy_kWh(i) = max(battery_energy_kWh(i-1) + excess_energy_kWh, 0); % Discharge battery
purchase_from_grid_kWh(i) = -excess_energy_kWh; % Record grid purchase
end
end
%% Calculate how much energy you will need to get from the energy company
total_purchase_from_grid_kWh = sum(purchase_from_grid_kWh);
% Calculate how much money you would save over the hypothetical period
total_savings_with_solar_USD = total_purchase_from_grid_kWh * price_per_kWh_USD;
% Calculate how much money you would save if you didn't use solar panels
energy_from_company_kWh = sum(home_energy_use_kWh);
% Use price_per_kWh_USD
savings_without_solar_USD = energy_from_company_kWh * price_per_kWh_USD;
As shown above, I'm trying to create a model solar panel energy and revenue predictor. The only problem I'm having is that the revenue I get is different from the actual revenue, with the error being in this battery section. The battery capacity is 14 kWh, and this section is needed as there are days when the solar panel doesn't produce the required energy amount (home_energy_use_kWh). I've tried multiple ways to solve this, and none of them have worked. If needed, I can post the whole code and the datasheet. Thank you for your help.

回答 (1 件)

Karanjot
Karanjot 2024 年 4 月 22 日
Hi Brady,
I see that the revenue computation for the battery section is different than expected. I have the following points and potential issues to consider:
  1. Ensure that 'battery_energy_kWh', 'purchase_from_grid_kWh' and 'home_energy_use_kWh' are initialized correctly before the loop. For 'battery_energy_kWh', its first element should represent the initial state of charge of the battery. 'purchase_from_grid_kWh' should be initialized as a zeros array of the same length as 'timesteps' to ensure you can index into it without errors.
  2. Ensure that when the battery discharges (providing energy to the home), this energy is not mistakenly counted as needing to be purchased from the grid. Ensure that purchase_from_grid_kWh(i) only accounts for the deficit not covered by the battery.
  3. Make sure you're handling edge cases correctly, such as:
  • The battery starting partially or fully charged.
  • Days with exactly enough energy produced to meet consumption (no excess, no deficit).
  • The battery being exactly full or empty at the start or end of a timestep
In case the above steps don't resolve your issue, Feel free to share the entire code and datasheet.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by