Jump to content

Matrix/Practice/Matrix multiplication: Difference between revisions

From Wikibase
AI-assisted (RonzzWikiCowriter) (via update-page on MediaWiki MCP Server)
AI-assisted (RonzzWikiCowriter) (via update-page on MediaWiki MCP Server)
Line 232: Line 232:


3. $m = p \cdot q$
3. $m = p \cdot q$
{{Hidden solution}}
The matrix of a linear map in the canonical basis has, as its $j$-th column, the image of the $j$-th basis vector, which is the Jacobian of the map with respect to $(x,y,z)$. Composing maps multiplies their matrices in the same order: $p=g\circ f$ has matrix $\mathbf G\mathbf F$, and $q=f\circ g$ has matrix $\mathbf F\mathbf G$. Each matrix is cross-checked against the direct symbolic composition.
<syntaxhighlight lang="python" class="pyodide" copy>
import sympy as sp
x, y, z = sp.symbols("x y z")
vec = sp.Matrix([x, y, z])
f = sp.Matrix([x + 3*z, x + y + 4*z, 3*x + 3*z])
g = sp.Matrix([x - z, y, -x + y])
# columns are the images of the basis vectors e_1, e_2, e_3
F = f.jacobian(vec)
G = g.jacobian(vec)
def compose(outer, inner):
    return outer.subs(list(zip(vec, list(inner))), simultaneous=True)
# 1. p = g o f
P = G * F
print("P = G F =", P.tolist())
print("p(x, y, z) =", compose(g, f).T.tolist())
# 2. q = f o g
Q = F * G
print("Q = F G =", Q.tolist())
print("q(x, y, z) =", compose(f, g).T.tolist())
# 3. m = p . q
M = P * Q
print("M = P Q =", M.tolist())
print("m(x, y, z) =", compose(P * vec, Q * vec).T.tolist())
print("P Q == Q P :", P * Q == Q * P)
</syntaxhighlight>
{{End hidden}}

Revision as of 09:32, 19 November 2026

Languages: English · français · Esperanto

The solutions are programmatic: the code in each