How to Fix Limiting Variable

  Kiến thức lập trình

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.

%% 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;

New contributor

Crash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT