## 2 Methodology
### Mathematical Formulation
#### 2.2.1 Economic-Based Formulation  
The aim of the problem stated in this study is to maximize total profit and is obtained by subtracting expenses from incomes. The objective function is defined in Equation (1). The aim is to maximize total profit and is obtained by subtracting expenses from incomes. \[\text{Max.}\;TNPV=V_{present}^{income}-V_{present}^{outflow} \tag{1}\]  
Equation (2) refers to the balance of power at each time \(t\). Herein, the sum of the power bought from the grid, the power used from the PV, and the power used from the battery is equal to the sum of the power consumed on the loads, the power stored in the battery, and power sold to the grid. \[P_{t}^{grid,buy}+P_{t}^{PV,used}+P_{t}^{bat,used}=P_{t}^{load}+P_{t}^{bat,ch}+P_ {t}^{grid,sold} \tag{2}\]  
In Equation (3), the power produced in the PV system is equal to the sum of the power consumed in the system and sold to the grid. \(n_{PV}\) refers to the number of 1 kW PV system. \[P_{t}^{PV,used}+P_{t}^{PV,sold}=P_{t}^{PV,prod}\cdot n_{PV} \tag{3}\]  
In addition, Equation (4) expresses that \(n_{PV}\), which is the number of PVs of 1 kW, is less than the maximum number of PVs that is predetermined. \[n_{PV}\leq n_{PV}^{max} \tag{4}\]  
The power discharged from the battery is either sold to the grid or consumed on loads. This value must also be multiplied by the discharge efficiency. This is described in Equation (5). \[P_{t}^{bat,used}+P_{t}^{bat,sold}=P_{t}^{bat,disch}\cdot\eta_{bat}^{disch} \tag{5}\]  
\(R_{bat}^{disch}\) and \(R_{bat}^{ch}\) in Equations (6) and (7) indicate the maximum power at which the battery is discharged and charged for a 1 kWh unit, respectively. These expressions are multiplied by \(n_{bat}\) to determine the power limits for the battery size. \[P_{t}^{bat,disch}\leq R_{bat}^{disch}\cdot n_{bat} \tag{6}\]  
\[P_{t}^{bat,ch}\leq R_{bat}^{ch}\cdot n_{bat} \tag{7}\]  
As stated in Equation (8), the maximum value is assigned to the number of PV panels with \(n_{bat}^{max}\) to determine the solution constraints of the optimization problem. \[n_{bat}\leq n_{bat}^{max} \tag{8}\]  
Equation (9) calculates the energy level of the battery at each time \(t\). According to this equation, the energy level at time \(t\) is obtained by power at the time \((t-1)\) with collection by the discharge powerof the battery or by subtracting the charge power in this interval (\((t-1)\) to \(t\)). Herein, \(\eta_{\text{hat}}^{ch}\) is given as the charging efficiency of the battery. \[E_{t}^{\text{{hat}}}=E_{(t-1)}^{\text{{hat}}}+P_{t}^{\text{{hat}},ch}\cdot\eta _{\text{{hat}}}^{ch}\cdot\Delta T-P_{t}^{\text{{hat}},disch}\cdot\Delta T,\;t>1 \tag{9}\]  
In Equations (10)-(12), the state of energy (SoE) of battery at the initial time, the maximum energy level of battery, and the minimum energy level of battery are defined respectively. \[E_{t}^{\text{{hat}}}=E^{\text{{hat}},ini}\cdot n_{\text{{hat}}},\;t=1 \tag{10}\]  
\[P_{t}^{grid,buy}+P_{t}^{PV,used}+P_{t}^{bat,used}=P_{t}^{load}+P_{t}^{bat,ch}+P_ {t}^{grid,sold} \tag{2}\]0  
\[P_{t}^{grid,buy}+P_{t}^{PV,used}+P_{t}^{bat,used}=P_{t}^{load}+P_{t}^{bat,ch}+P_ {t}^{grid,sold} \tag{2}\]1  
Since the battery cannot be charged and discharged at the same time, the \(u_{t}^{\text{{hat}}}\) binary decision variable is defined to prevent this situation. This condition is provided by Equations (13) and (14). Herein, \(N\) is defined as a sufficiently big positive number. \[P_{t}^{grid,buy}+P_{t}^{PV,used}+P_{t}^{bat,used}=P_{t}^{load}+P_{t}^{bat,ch}+P_ {t}^{grid,sold} \tag{2}\]2  
\[P_{t}^{grid,buy}+P_{t}^{PV,used}+P_{t}^{bat,used}=P_{t}^{load}+P_{t}^{bat,ch}+P_ {t}^{grid,sold} \tag{2}\]3  
The limits of the maximum power that can be withdrawn from the grid and sold to the grid are easily indicated in the Equations (15) and (16), respectively. This is important in terms of grid capacity as the withdrawal of energy from the grid and the sale of energy to the grid cannot be materialized at the same time, therefore \(u_{t}^{grid}\) binary decision variable is defined for this situation.