Align two equations vertically

You can use on these, depending on whether you want to align the = signs or the beginning of each line. Remember that aligned (or align) requires marking the alignment point with an ampersand:

$\begin{aligned} 
   f_{s_{i}} &=-\frac{w_{s}}{n_{i}}\sum_{j=1}^{n}g(d_{ij})d_{ij} \\
    g(d_{ij}) &=
  \begin{cases} 
    1 & d_{ij}\leq r_{h}\\
    \exp\Bigl(-\frac{(d_{ij}-r_{h})^{2}}{\sigma^{2}}\Bigr)   & d_{ij}> r_{h}
  \end{cases}
\end{aligned}$ 

$\begin{aligned} 
   &f_{s_{i}} =-\frac{w_{s}}{n_{i}}\sum_{j=1}^{n}g(d_{ij})d_{ij} \\
   &g(d_{ij})  =
  \begin{cases} 
    1 & d_{ij}\leq r_{h}\\
    \exp\bigl(-\frac{(d_{ij}-r_{h})^{2}}{\sigma^{2}}\bigr)   & d_{ij}> r_{h}
  \end{cases}
\end{aligned}$   

I added two different sizes for the parentheses after exp in the two proposed codes.

Unrelated: like all usual functions having a name, the exp function should typed in upshape, which is obtained with the command \exp (like \sin, \cos, \log, &c.)

enter image description here


You just need to use the & charactere whereever you want to put the alignment.

For example, if you want to align at the left side of the column:

$\begin{aligned} 
   & f_{s_{i}}=-\frac{w_{s}}{n_{i}}\sum_{j=1}^{n}g(d_{ij})d_{ij} \\
   & g(d_{ij}) =
  \begin{cases} 
    1 & d_{ij}\leq r_{h}\\
    exp(-\frac{(d_{ij}-r_{h})^{2}}{\sigma^{2}})   & d_{ij}> r_{h}
  \end{cases}
\end{aligned}$ 

else, if you want to align in the = charactere, you do as:

$\begin{aligned} 
   f_{s_{i}} & =-\frac{w_{s}}{n_{i}}\sum_{j=1}^{n}g(d_{ij})d_{ij} \\
   g(d_{ij}) & =
  \begin{cases} 
    1 & d_{ij}\leq r_{h}\\
    exp(-\frac{(d_{ij}-r_{h})^{2}}{\sigma^{2}})   & d_{ij}> r_{h}
  \end{cases}
\end{aligned}$