3
$\begingroup$

I have a $3\times 3$ matrix valued function $f(x)$ where $x\in\mathbb{R}$.

I want to perform the following:

$$\prod_{k=a}^b f(k),$$

where $a,b$ are known, but I cant seem to get Mathematica to do it. Any ideas?

I know I have to use .. instead of *, but I want something similar to

Product[f[k],{k,a,b}]

Clearly this won't work since Product works on $\mathbb{C}$ only (at least as far as my knowledge goes)

I have tried

Dot[f[k],{k,a,b}]

but that doesn't work.

$\endgroup$

closed as off-topic by MarcoB, dr.blochwave, C. E., Bob Hanlon, Öskå Sep 9 '15 at 17:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, dr.blochwave, C. E., Bob Hanlon, Öskå
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    $\begingroup$ If a,b are known, then Fold[Dot, Table[f[x], {x, a, b}]] will work. $\endgroup$ – Patrick Stevens Sep 8 '15 at 7:07
  • 6
    $\begingroup$ Try Dot @@ Table[f[j], {j, a, b}] $\endgroup$ – Hubble07 Sep 8 '15 at 7:34
  • 2
    $\begingroup$ Dot @@ (f /@ Range[a, b]) $\endgroup$ – Dr. belisarius Sep 8 '15 at 15:20
  • 2
    $\begingroup$ SetAttributes[f, Listable]; Dot @@ f@Range[a, b] $\endgroup$ – Dr. belisarius Sep 8 '15 at 15:22
  • $\begingroup$ "Put on hold". The mind boggles! $\endgroup$ – Pixel Sep 11 '15 at 11:57
4
$\begingroup$

There's a bunch of comments with upvotes. So, to sum up:

PatrickStevens says to Fold Dot over the List of f[x]'s

Fold[Dot, Table[f[x], {x, a, b}]]

Hubble07 says to try Applying Dot to the Table of f[x]'s.

Dot @@ Table[f[x], {x, a, b}]

belisarius says to Apply Dot to f Mapped over the Range:

Dot @@ f /@ Range[a, b]

or to make the function f Listable:

SetAttributes[f, Listable];
Dot @@ f@Range[a, b]

One more version:

Fold[Dot, Array[f, b - a + 1, a]]
Dot @@ Array[f, b - a + 1, a]
Array[f, b - a + 1, a, Dot]
$\endgroup$
  • $\begingroup$ Do all of these methods result in the full list of matrices being put into memory simultaneously? $\endgroup$ – ComptonScattering Aug 14 '17 at 22:06
  • 1
    $\begingroup$ @ComptonScattering. I believe so. You want something that generates the matrices on the fly as they're multiplied together? Maybe something like Fold[#1.f[#2] &, f[a], Range[a + 1, b]]? Or maybe it should be Fold[f[#2].#1 &, f[a], Range[a + 1, b]]; order matters of course, $\endgroup$ – march Aug 14 '17 at 22:22
  • $\begingroup$ I see what you have done. This has been very useful for me to understand. Thank you. $\endgroup$ – ComptonScattering Aug 15 '17 at 1:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.