# A Regression-Based Technique for Capacity Estimation of Lithium-Ion Batteries
## 3 Capacity Estimation
### Proposed Methods to Estimate \(Q\)
#### 3.2.2 The Second Type of Least Squares Method  
By considering noise of \(x_{i}\), the linear form of the problem changes as:  
\[y-\Delta y=Q\ (x-\Delta x) \tag{29}\]  
where \(\Delta y\) and \(\Delta x\) are white noise with zero mean and known variances of \(\sigma_{y_{i}}^{2}\) and \(\sigma_{x_{i}}^{2}\). The cost function is rewritten as:  
\[\chi_{LS2}^{2}=\sum\limits_{i=1}^{n}\frac{(x_{i}-X_{i})^{2}}{\sigma_{x_{i}}^{ 2}}+\frac{(y_{i}-Y_{i})^{2}}{\sigma_{y_{i}}^{2}}-\lambda_{i}\big{(}Y_{i}-\hat {Q}X_{i}\big{)} \tag{30}\]  
In which the last term applies constraint of \(Y_{i}=\hat{Q}X_{i}\) with Lagrange multipliers of \(\lambda_{i}\).  
By differentiating cost functions with respect to \(X_{i}\), \(Y_{i}\), and \(\lambda_{i}\), setting them to zero, and placing the results in the cost function, new equations can be derived. The function with known and straightforward terms can be reached by employing the following equations:  
\[\frac{\partial\chi_{LS2}^{2}}{\partial\lambda_{i}}=-\big{(}Y_{i}-\hat{Q}X_{i} \big{)}=0\rightarrow\ \ \ \ \textbf{Y}_{i}=\hat{Q}X_{i} \tag{31}\]  
\[\frac{\partial\chi_{LS2}^{2}}{\partial Y_{i}}=\frac{-2(y_{i}-Y_{i})}{\sigma_{ y_{i}}^{2}}-\lambda_{i}=0\rightarrow\ \ \ \ \textbf{\lambda}_{i}=\frac{-2\ (y_{i}-Y_{i})}{\sigma_{y_{i}}^{2}} \tag{32}\]\[\frac{\partial\chi_{LS2}^{2}}{\partial\hat{X}_{i}}=\frac{-2(x_{i}-X_{i})}{ \sigma_{x_{i}}^{2}}+\lambda_{i}\hat{Q}=0=-\frac{2(x_{i}-X_{i})}{\sigma_{x_{i}}^ {2}}-\frac{2(y_{i}-Y_{i})}{\sigma_{y_{i}}^{2}}\hat{Q} \tag{33}\] \[\sigma_{y_{i}}^{2}\;(x_{i}-X_{i})+\sigma_{x_{i}}^{2}\;(y_{i}-Y_{i })\hat{Q}=\sigma_{y_{i}}^{2}x_{i}-\sigma_{y_{i}}^{2}X_{i}+\sigma_{x_{i}}^{2}y_{ i}\hat{Q}-\sigma_{x_{i}}^{2}X_{i}\hat{Q}^{2}\] (34) \[X_{i}=\frac{\sigma_{y_{i}}^{2}x_{i}+\sigma_{x_{i}}^{2}y_{i}\hat{ Q}}{\sigma_{y_{i}}^{2}+\sigma_{x_{i}}^{2}\hat{Q}^{2}} \tag{35}\]  
By replacing these quantities in cost function:  
\[\begin{array}{ll}\chi_{LS2}^{2}&=\sum\limits_{i=1}^{N}\frac{\hat{Q}^{2} \sigma_{x_{i}}^{4}\big{(}y_{i}-\hat{Q}x_{i}\big{)}^{2}}{\sigma_{x_{i}}^{2} \big{(}\sigma_{y_{i}}^{2}+\hat{Q}^{2}\sigma_{x_{i}}^{2}\big{)}^{2}}+\frac{ \sigma_{y_{i}}^{4}\big{(}y_{i}-\hat{Q}x_{i}\big{)}^{2}}{\sigma_{y_{i}}^{2} \big{(}\sigma_{y_{i}}^{2}+\hat{Q}^{2}\sigma_{x_{i}}^{2}\big{)}^{2}}\\ &=\sum\limits_{i=1}^{N}\frac{\big{(}y_{i}-\hat{Q}x_{i}\big{)}^{2}}{\sigma_{y_ {i}}^{2}+\hat{Q}^{2}\sigma_{x_{i}}^{2}}\end{array} \tag{36}\]  
The partial derivative of the cost function can be calculated with respect to \(\hat{Q}\), and it can be considered zero in order to find optimized \(\hat{Q}\) by employing the following equations:  
\[\frac{\partial\chi_{LS2}^{2}}{\partial\hat{Q}}=\sum\limits_{i=1}^{N}\frac{2 \big{(}\hat{Q}x_{i}-y_{i}\big{)}\big{(}\hat{Q}y_{i}\sigma_{x_{i}}^{2}+x_{i} \sigma_{y_{i}}^{2}\big{)}}{\big{(}\hat{Q}^{2}\sigma_{x_{i}}^{2}+\sigma_{y_{i} }^{2}\big{)}^{2}}=0 \tag{37}\]  
Numerical methods are able to solve this equation, and the Newton-Raphson method is one of them. A noise of \(x_{i}\) can be considered, but the equation has not reached a close form, which means deriving an equation with \(\hat{Q}\) on one side and other parameters on the other side. Subsequently, \(\hat{Q}\) cannot be updated in a recursive manner, and it means a huge computational load and a need for large storage memory. Thus, this method is not practical and not applicable in embedded systems. Therefore, the third type of least squares method is proposed in the following.