<s>[INST] Get number of elements of a square matrix given a vector that has upper right elements of that matrix Suppose I have some vectors:


*

*$[1,2,1]$  its length is $3$ wich represents a matrix like $\begin{pmatrix}
 1 & 2\\ 
 -1 & 1
\end{pmatrix}$  the complete matrix would have $4$ elements

*$[1,2,1,3,4,1]$  its length is $6$ wich represents $\begin{pmatrix}
 1&  2& 3\\ 
 -1& 1 & 4\\ 
 -1& -1 &1 
\end{pmatrix}$  the complete matrix would have $9$ elements  

*$[1,2,1,3,4,1,5,6,7,1]$  its length is $10$ wich represents $\begin{pmatrix}
1 &  2&  3& 5\\ 
-1 &1  &  4& 6\\ 
-1 &-1  &1  & 7\\ 
-1 &-1  &-1  &1 
\end{pmatrix}$ the complete matrix would have $16$ elements

*$[1,2,1,3,4,1,5,6,7,1,8,9,10,11,1]$  its length is $15$ wich represents  
$\begin{pmatrix}
1 &2  &3  &5  &8 \\ 
-1 &1  &4  &6  &9 \\ 
-1 &-1  &1  &7  &10 \\ 
-1 &-1  &-1  &1  &11 \\ 
-1 &-1  &-1  &-1  &-1 
\end{pmatrix}$ the complete matrix would have $25$ elements
How do I find a general formula to get all elements of a square matrix from the number of elements in a vector?
So  


*

*$3\to 4$

*$6\to 9$ 

*$10\to 16$ 

*$15\to 25$

*etc...


also: How would you know the matrix size $2\times 2$, $3\times 3$,...$n\times n$?
 [/INST] As Billy explains, you can find an explicit formula by solving a quadratic, the result of which appears in Fabian's answer.
An alternative is to note that $$\frac{m^2}{2}\lt\frac{m(m+1)}{2}\lt\frac{(m+1)^2}{2}.$$  You are given $n=\frac{m(m+1)}{2}$, and you want $m^2$.  The inequalities above yield $$m^2<2n<(m+1)^2,$$ so $$m<\sqrt{2n}<m+1.$$ This implies that $m=\lfloor\sqrt{2n}\rfloor$ (the greatest integer not greater than $\sqrt{2n}$). Finally, if the vector has $n$ entries, then the matrix has $\lfloor\sqrt{2n}\rfloor^2$ entries.
</s>