I have a grid 5x5 and I have to fill 16 little squares with a diagonal
Rules
- You cannot place more than 1 diagonal in each square
- The diagonals cannot touch each other (example bellow)

Click here to view the solution
But what I seek here is a mathematical solution for this puzzle, I don't even know where to start looking for information.
Can someone explain how do I solve this puzzle using equations?



Think of it this way: You have a 5x5 array, and you need to fill it with values 0, 1, or -1, with three restrictions:
Here, cells containing a "1" have a diagonal running top-left to bottom-right, and cells containing a "-1" have a diagonal running the other way. Cells containing 0 do not have a diagonal at all.
So, for the example grid you provide, you start with the grid:
$$ \begin{matrix}0&0&-1&0&0\\0&-1&0&-1&1\\0&0&0&0&0\\0&0&0&0&0\\0&0&0&0&0\end{matrix} $$
I don't think there's "a mathematical solution" to it - that is, I doubt that one could immediately find the "right answer" without some level of trial and error. But it does give a good starting point to automating the search, if you want to try solving it computationally.