Matrix chain multiplication: Difference between revisions
m
no edit summary
(New post.) |
mNo edit summary |
||
Line 1:
{{task|Discrete math}}
[[Category:Matrices]]
;Problem
Using the most
For instance, with four matrices, one can compute A(B(CD)), A((BC)D), (AB)(CD), (A(BC))D, (AB)C)D. The number of different ways to put the parens is a [[Catalan numbers|Catalan number]], and grows exponentially with the number of factors.
Line 30 ⟶ 31:
=={{header|11l}}==
{{trans|Nim}}
<syntaxhighlight lang="11l">T Optimizer
[Int] dims
Line 477:
=={{header|Fortran}}==
{{trans|Python}}
This is a translation of the Python iterative solution.
Line 890 ⟶ 889:
Cost : 1777600
</pre>
=={{header|Julia}}==
Line 1,128 ⟶ 1,126:
1773740
1*((((((2*3)*4)*(((5*6)*7)*8))*9)*10)*11)</pre>
=={{header|MATLAB}}==
{{trans|Fortran}}
<syntaxhighlight lang="matlab">function [r,s] = optim(a)
n = length(a)-1;
Line 1,573 ⟶ 1,569:
=={{header|R}}==
<syntaxhighlight lang="rsplus">aux <- function(i, j, u) {
k <- u[[i, j]]
Line 1,627 ⟶ 1,622:
=={{header|Racket}}==
'''Memoization'''
|