Arrays: Difference between revisions

1,972 bytes added ,  6 years ago
+Stata
No edit summary
(+Stata)
Line 5,464:
00100000000000000000000000000000 26. 4</lang>
The program could easily be modified to work with arrays of unknown length, if required, along the lines of the second pseudocode example above.
 
=={{header|Stata}}==
In Stata, there are mainly two ways to work with arrays: the '''[http://www.stata.com/help.cgi?matrix matrix]''' command can create and manipulate arrays, either elementwise or using matrix functions. And there is Mata, a matrix programming language similar to MATLAB, R or SAS/IML.
 
There are ways to exchange data between Stata datasets, Stata matrices, and Mata matrices:
 
* the Mata functions '''[http://www.stata.com/help.cgi?mf_st_data st_data]''' and '''[http://www.stata.com/help.cgi?mf_st_view st_view]''' are used to read data from the current Stata dataset to a Mata matrix (st_data copies data, while st_view creates a view, that can be used to modify the dataset in place).
* The Mata function '''[http://www.stata.com/help.cgi?mf_st_store st_store]''' is used to write a Mata matrix into the current dataset.
* the Mata function '''[http://www.stata.com/help.cgi?mf_st_matrix st_matrix]''' is used to read or write from/to a Stata matrix to a Mata matrix.
* the '''[http://www.stata.com/help.cgi?mkmat mkmat]''' and '''svmat''' commands are used to store data from a dataset to a Stata matric and vice versa.
 
Both Stata matrices and Mata matrices have either one or two dimensions. For both, functions are provided for the usual linear algebra function (QR and SVD decompositions, for instance). Stata matrices must contain real numbers (or missing values), while Mata matrices may contain complex numbers, or strings (but either a matrix contains only numeric values, either it contains only string values).
 
=== Matrix command ===
<lang stata>matrix a = 2,9,4\7,5,3\6,1,8
display det(a)
matrix svd u d v = a
matrix b = u*diag(d)*v'
matrix list b
* store the u and v matrices in the current dataset
svmat u
svmat v</lang>
 
=== Mata ===
<lang stata>mata
a = 2,9,4\7,5,3\6,1,8
det(a)
svd(a, u=., s=., v=.)
// Notice that to reconstruct the matrix, v is not transposed here,
// while it is with -matrix svd- in Stata.
u*diag(s)*v</lang>
 
=={{header|Suneido}}==
1,336

edits