10 views

Uploaded by Saurav Anand

- Matrix Chain Multiplication
- Assessment of Two Methods to Select Wide-Area
- Determination of Admittance and Impedance Bus Matrices Using Linear Algebra and Matlab in Electric Power Systems
- Projects.pdf
- Dynamic Programming
- Control Draw 3 Manual
- Www.csd.Cs.cmu.Edu Education Bscs Ugcourses
- 2011_7_5_1575_1581
- Excel Commands
- Knapsack
- Alp19.1 Manual
- Csc503 Data-structures-And-Algorithms Eth 2.00 Ac26
- ECE 551 Lecture 2
- 11th Business Maths - Unit 1 Model Question Paper - TamilNadu TN State Board English Medium - Brainkart.com
- 0l model paper
- A Semianalytical Method for Steadystate Solution in HVDC Analysis
- Student Solution Chap 02
- Abstract Isvcs8
- UT Dallas Syllabus for math2333.001.11f taught by William Scott (wms016100)
- NumPy

You are on page 1of 5

M = M1M2M3 MN.

Each matrix Mk has dimension pk-1 x pk. The dimensions are stored in array

P = < p0 p1 pN>.

Math behind this problem: matrices can be multiplied only two by two, and their order in the chain must be preserved (partially because number of columns of the first matrix must equal the number of rows of the second matrix). In other words, if A and B are matrices, AB BA. Number of scalar multiplications in AaxbBbxc equals to a*b*c. For example, M1M2M3 can be calculated as (M1M2)M3 or M1(M2M3). The order of multiplication, i.e. the placement of parenthesis, will determine the number of scalar multiplications. Example: M = M1M2M3, P = <10 100 5 50>.

If we calculate M = (M1M2)M3, then the number of scalar multiplications is: 10*100*5 to multiply K=M1M2. Dimension of K is 10x5. + 10*5*50 to multiply M=KM3. Dimension of M is 10x50. Total: 7,500 scalar multiplications. If we calculate M = M1(M2M3), then the number of scalar multiplications is: 100*5*50 to multiply L=M2M3. Dimension of L is 100x50. + 10*100*50 to multiply M=M1L. Dimension of M is 10x50. Total: 75,000 scalar multiplications. Therefore, the problem boils down to: given a product chain of N matrices, fully parenthesize the chain in order to minimize the number of scalar multiplications. A solution: brute force method using dynamic programming, i.e. write and implement a dynamic programming formula to solve the problem. A dynamic programming formula is always recursive. It can be implemented as: 1. plain recursive code (top down) 2. memoized code (i.e. recursive code with storage, top down) 3. iterative code (bottom up)

m[i,j] is the number of scalar multiplications needed to multiply matrices Mi Mi+1 Mi+2 Mj.

Each matrix Mk has dimension pk-1 x pk. Dimensions of all matrices are stored in array P = < p0 p1 pN>. i=1, n, j = 1, n.

for all k

if i=j if i < j

i k<j

Task: Write the recursive pseudocode which calculates m[1,n] and also records where to put the optimal parenthesis. //calculate m[i,j] for matrix chain P RecursiveMatrixChain(P, i, j) {

MATRIX-CHAIN-ORDER(P) { n = length(P) 1 for i = 1, n m[i,i] = 0 for L = 2, n for i = 1, n L + 1 j=i+L1 m [i, j] = for k = i, j-1 q = m[i, k] + m[k+1, j] + pi-1pkpj if q < m[i,j] m[i,j] = q s[i,j] = k return m and s } Initial call: ____________________

Order of filling m matrix for n=4 (i.e. m11 is filled first, then m22, then m33, then m44, then m12, etc.) 1 5 8 10 2 6 9 3 7 4

RMC(P, i, j) { if i = j return 0 m [i, j] = for k = i, j-1 q = RMC(P, i, k) + RMC(P, k+1, j) + pi-1pkpj if q < m[i,j] m[i,j] = q s[i,j] = k return m[i,j] and s } Initial call: ____________________

The following matrix shows the order of calculating values in m matrix for n=4 (the subscripts are denoting order of all calls that end up on the stack, regardless of how long they have to wait for their offspring to return. Some of those calls return immediately, e.g. calls where p=r). 12,13,19,24 812,23 24,9,14,21,25 9 18 6 8,20 36,10,16,22,26 10 1 73 5 5,15 47,11,17,27

Q: i got really messed up in the recursive part too, although memoization wasn't a walk in >the part either! all together i think it took me about 6 hours to complete the homework! it wasn't so much the degree of difficulty as it was just trying to keep track of what you did and not messing up the numbers, i did that a couple of times and had to redo the >entire trace all over again! A: Yes, that's why good bookkeeping is *essential* here. And good bookkeeping depends on understanding the principle of the algorithm. Drawing the recursive calls like the tree in Fig.15.5 is the best. It is easy when you realize what the pattern is: if there is i-j piece to deal with, then split it in all possible ways (in order to find the best way). So, 1-4 gets split into: 1-1,2-4; 1-2, 3-4; 1-3,4-4.

This is very important to understand, this is the basic of dynamic programming. We will use it later for graphing algorithms. To continue the splitting: the next step is to realize that this is all recursive, so the algorithm goes all the way down the left splits, then comes back and does the right. That's why you must understand recursion very well. So, to continue this example, I will write it in the order called: 1-1 2-4; 2-2 3-4

- Matrix Chain MultiplicationUploaded byHarsh Tibrewal
- Assessment of Two Methods to Select Wide-AreaUploaded byRabbuni Gangavarapu
- Determination of Admittance and Impedance Bus Matrices Using Linear Algebra and Matlab in Electric Power SystemsUploaded byAbhishek gupta
- Projects.pdfUploaded byAhsan Naeem
- Dynamic ProgrammingUploaded bySourabh Bansal
- Control Draw 3 ManualUploaded byLuqman 'ul Hakim
- Www.csd.Cs.cmu.Edu Education Bscs UgcoursesUploaded by1985 production
- 2011_7_5_1575_1581Uploaded byPutra Gunawan
- Excel CommandsUploaded byKhoaNamNguyen
- KnapsackUploaded byDhairya Reddy
- Alp19.1 ManualUploaded byJorge Gtz
- Csc503 Data-structures-And-Algorithms Eth 2.00 Ac26Uploaded bynetgalaxy2010
- ECE 551 Lecture 2Uploaded byadambose1990
- 11th Business Maths - Unit 1 Model Question Paper - TamilNadu TN State Board English Medium - Brainkart.comUploaded byBrainKart Com
- 0l model paperUploaded bychinthaka
- A Semianalytical Method for Steadystate Solution in HVDC AnalysisUploaded byVijay Raj
- Student Solution Chap 02Uploaded bysmazai
- Abstract Isvcs8Uploaded bydozio
- UT Dallas Syllabus for math2333.001.11f taught by William Scott (wms016100)Uploaded byUT Dallas Provost's Technology Group
- NumPyUploaded byVarun Akuthota
- Chapt 1Uploaded bykbarseghyan
- Lay Linalg5!01!04Uploaded byfrankjamison
- Arrays Made EasyUploaded byAadil Muklhtar
- Applied Linear Algebra by BoorUploaded byVikram Singh
- Functionality SpaceUploaded byFelipe Andres Araneda Gallardo
- lecture21.pdfUploaded byLuis Alejandro Gonzalez
- dny2017Uploaded byAndras Zaj
- UT Dallas Syllabus for math2333.005.11f taught by Anatoly Eydelzon (axe031000)Uploaded byUT Dallas Provost's Technology Group
- Math IB Revision Matrices SLUploaded bymykiri79
- Simulation of Arc ModelsUploaded byEleazar Sierra Espinoza

- New Microsoft Word Document (2)Uploaded bySaurav Anand
- Load Combinations IRC-6Uploaded bySaurav Anand
- Amdt4Uploaded bySaurav Anand
- Report DatewiseUploaded bySaurav Anand
- TRAFFIC ENGINEERINGUploaded bySaurav Anand
- SportsUploaded bySaurav Anand
- Summer Training ONGC (2)Uploaded bySunil Sharma
- tugas critica review birokrasiUploaded byClarenciaAdhemesTantri

- Guide Civil Service Guidance Volume 2 0Uploaded byjosh mcracken
- 55473966 Project Report on Payroll ProcessUploaded byRenjith Krishnan
- MOnitor LG 1943SUploaded byapvtecnology
- Iso 15504 - Maturity Model for SoftwareUploaded bythaistalyn
- WPS Validation Tool - End User Guide 1 2_molsaUploaded byanwarali1975
- Common Law Trust Unincorporated Business Trust Asset Protection Remedy (protect assets)Uploaded byin1or
- SAP CRM Reume of BhogatUploaded bySuneet Kumar
- MAY G.K..docxUploaded byAnkit Bissa
- Allan Resume FinalUploaded byAlyssa Cureg
- about MCBUploaded bySana Kazmi
- 4 Ichong v. HernandezUploaded byKJPL_1987
- MSP432_DriverLib_Users_Guide-MSP432P4xx-3_10_00_09Uploaded bysonti11
- City RankingUploaded bysaurav.mart
- rampone anthony resumeUploaded byapi-284811983
- doc_MG90J502Uploaded byFernando Sierra
- LTD - 20120902 DigestUploaded byNico Bambao
- ch1.pptUploaded bykodilkarsameer123
- Quant 1Uploaded byTecwyn Lim
- Bab 1 Organizations and Organization Theory (modified).pptUploaded byAndri Ariyanto
- Conscious SedationUploaded byLu Cil
- Vst Vellore Tn Srinivasan Waste ManagementUploaded bynvkar
- White Dwarf Magazine 21Uploaded bybadmouth1999
- The Sales Promotion Employees (Conditions of Service) Act, 1976Uploaded bypoojasikka1963
- Technical Specifications Kia Picanto Ion 0.8 3c g3hgUploaded byrectificamos
- 00254_Prod e App_Catálogo EuropaUploaded byGleison Prateado
- Fuel Conservation - BoeingUploaded byGuilherme Bernabe
- Discrete IO ModulesUploaded byJose Javier Pereira
- The Business Times June 6 2017Uploaded byVeronica Yaremenko
- Duro DyneUploaded byMohammed Jassim
- Calculation electrode consumption.pdfUploaded byhiteshnmodi