In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to realize matrix multiplication in C language". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to realize matrix multiplication in C language".
Dynamic programming method
Topic description: given n matrices {A _ 1 ~ A _ 2an}, in which Ai and Ai+1 can be multiplied, it is judged that the n matrices are multiplied by adding parentheses to minimize the number of times!
Take the matrix chain ABCD as an example
The optimal value is calculated according to the increment of matrix chain length.
When the length of matrix chain is 1, the optimal values of matrix chains A, B, C and D are calculated respectively.
When the length of matrix chain is 2, the optimal values of matrix chain AB, BC and CD are calculated respectively.
When the length of matrix chain is 3, the optimal values of matrix chain ABC and BCD are calculated respectively.
When the length of matrix chain is 4, the optimal value of matrix chain ABCD is calculated.
Dynamic regression equation:
Analysis:
K is the position where the matrix chain is broken.
D array stores the optimal value of matrix chain calculation. D [I] [j] is the optimal value of matrix chain beginning with I matrix and ending with j matrix, I > 0
The row and column information of the matrix chain is stored in the m array. M [I-1] and m [I] are the rows and columns of the I-th matrix (I = 1,2,3.)
C language implementation code:
# include # define N 20 void MatrixChain (int p [N], int NLINT m [N] [N], int s [N] [N]) {int iGrainj int r; / record the number of matrices multiplied by variables for
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.