- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the cross product of two vectors in R by adding the elements?
To find the cross product of two vectors in R by adding the elements, we can calculate outer product by using %o% operator.
For example, if we have two vectors say x and y then cross product of these two vectors by adding the elements can be found by using the command given below −
x%o%y
Check out the below examples to understand how it works.
Example 1
To find the cross product of two vectors in R by adding the elements, use the code given below −
x1<-1:5 y1<-1:5 x1%o%y1
Output
If you execute the above given code, it generates the following output −
[,1] [,2] [,3][,4][,5] [1,] 1 2 3 4 5 [2,] 2 4 6 8 10 [3,] 3 6 9 12 15 [4,] 4 8 12 16 20 [5,] 5 10 15 20 25
Example 2
To find the cross product of two vectors in R by adding the elements, use the code given below −
x2<-1:6 y2<-1:6 x2%o%y2
Output
If you execute the above given code, it generates the following output −
[,1][,2][,3][,4][,5][,6] [1,] 1 2 3 4 5 6 [2,] 2 4 6 8 10 12 [3,] 3 6 9 12 15 18 [4,] 4 8 12 16 20 24 [5,] 5 10 15 20 25 30 [6,] 6 12 18 24 30 36
Example 3
To find the cross product of two vectors in R by adding the elements, use the code given below −
x3<-1:8 y3<-1:8 x3%o%y3
Output
If you execute the above given code, it generates the following output −
[,1][,2][,3][,4][,5][,6][,7][,8] [1,] 1 2 3 4 5 6 7 8 [2,] 2 4 6 8 10 12 14 16 [3,] 3 6 9 12 15 18 21 24 [4,] 4 8 12 16 20 24 28 32 [5,] 5 10 15 20 25 30 35 40 [6,] 6 12 18 24 30 36 42 48 [7,] 7 14 21 28 35 42 49 56 [8,] 8 16 24 32 40 48 56 64
Example 4
To find the cross product of two vectors in R by adding the elements, use the code given below −
x4<-1:10 y4<-1:10 x4%o%y4
Output
If you execute the above given code, it generates the following output −
[,1][,2][,3][,4][,5][,6][,7][,8][,9][,10] [1,] 1 2 3 4 5 6 7 8 9 10 [2,] 2 4 6 8 10 12 14 16 18 20 [3,] 3 6 9 12 15 18 21 24 27 30 [4,] 4 8 12 16 20 24 28 32 36 40 [5,] 5 10 15 20 25 30 35 40 45 50 [6,] 6 12 18 24 30 36 42 48 54 60 [7,] 7 14 21 28 35 42 49 56 63 70 [8,] 8 16 24 32 40 48 56 64 72 80 [9,] 9 18 27 36 45 54 63 72 81 90 [10,] 10 20 30 40 50 60 70 80 90 100
- Related Articles
- Return the cross product of two (arrays of) vectors in Python
- C++ Program to Compute Cross Product of Two Vectors
- C++ Program for dot product and cross product of two vectors
- Return the multiple vector cross product of two (arrays of) vectors in Python
- How to find the union of two vectors in R?
- How to find different elements between two string vectors in R?
- Return the cross product of two (arrays of) vectors with different dimensions in Python
- How to find the common elements in multiple vectors in R?
- How to find the unique elements in multiple vectors in R?
- How to find the covariance between two vectors in R?
- How to find the sum product of two matrix by row in R?
- Return the multiple vector cross product of two vectors and change the orientation of the result in Python
- Program to find out the dot product of two sparse vectors in Python
- How to find the dot product of two matrices in R?
- How to find the number of common words between two string vectors in R?
