Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Linux Foundation Training and Certification

Disclosure: My content contains affiliate links.

33,435 questions

43,815 answers

573 users

How to perform matrix multiplication with two matrices in R

Learn & Practice SQL


105 views
asked Jul 6, 2021 by avibootz
edited Jul 7, 2021 by avibootz

1 Answer

0 votes
vec <- c(1, 2, 3, 1, 0, 2, 3, 1, 1)
m1 <- matrix(vec, nrow = 3, ncol = 3)
  
vec <- c(2, 1, 3, 0, 0, 1, 2, 1, 0)
m2 <- matrix(vec, nrow = 3, ncol = 3)
 
mul <- m1 %*% m2

print(m1)
cat('\n')
print(m2)
cat('\n')
print(mul)
 
 
 
 
   
   
# run:
#
#      [,1] [,2] [,3]
# [1,]    1    1    3
# [2,]    2    0    1
# [3,]    3    2    1

#      [,1] [,2] [,3]
# [1,]    2    0    2
# [2,]    1    0    1
# [3,]    3    1    0

#      [,1] [,2] [,3]
# [1,]   12    3    3
# [2,]    7    1    4
# [3,]   11    1    8
#

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Jul 6, 2021 by avibootz
edited May 28, 2023 by avibootz

Related questions

1 answer 101 views
1 answer 113 views
113 views asked Jul 7, 2021 by avibootz
1 answer 124 views
1 answer 108 views
108 views asked Jul 7, 2021 by avibootz
1 answer 106 views
106 views asked Jul 7, 2021 by avibootz
...