# Calculate the cross-product of a Matrix in R Programming – crossprod() Function

`crossprod()` function in R Language is used to return the cross-product of the specified matrix.

Syntax: crossprod(x)

Parameters:
x: numeric matrix

Example 1:

 `# R program to illustrate ` `# crossprod function ` ` `  `# Initializing a matrix with ` `# 2 rows and 2 columns ` `x <``-` `matrix(``1``:``4``, ``2``, ``2``) ` ` `  `# Getting the matrix representation ` `x ` ` `  `# Calling the crossprod() function ` `crossprod(x) `

Output:

```     [, 1] [, 2]
[1, ]    1    3
[2, ]    2    4

[, 1] [, 2]
[1, ]    5   11
[2, ]   11   25
```

Example 2:

 `# R program to illustrate ` `# crossprod function ` ` `  `# Initializing a matrix with ` `# 3 rows and 3 columns ` `x <``-` `matrix(``1``:``9``, ``3``, ``3``) ` ` `  `# Getting the matrix representation ` `x ` ` `  `# Calling the crossprod() function ` `crossprod(x) `

Output:

```     [, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9

[, 1] [, 2] [, 3]
[1, ]   14   32   50
[2, ]   32   77  122
[3, ]   50  122  194
```
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.