Created
October 18, 2020 21:01
-
-
Save czgdp1807/66e67f084c3419824508c9db83f0027b to your computer and use it in GitHub Desktop.
Convolution as Matrix Multiplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
from sympy import * | |
x, y, z, t = symbols('x y z t') | |
k, m, n = symbols('k m n', integer=True) | |
f, g, h = symbols('f g h', cls=Function) | |
init_printing() | |
a, b, c, d, e, f, g, h, i, v, x, y, z = symbols('a, b, c, d, e, f, g, h, i, v, x, y, z', real=True) | |
M = Matrix([[a, b, c], [d, e, f], [g, h, i]]) | |
K = Matrix([[v, x], [y, z]]) | |
Mc = Matrix([[a, b, d, e], [b, c, e, f], [d, e, g, h], [e, f, h, i]]) | |
Kc = Matrix([v, x, y, z]) | |
mc_vars = [a, b, c, d, e, f, g, h, i] | |
kc_vars = [v, x, y, z] | |
import random | |
mc_rand_vars = [random.random() for _ in range(len(mc_vars))] | |
kc_rand_vars = [random.random() for _ in range(len(kc_vars))] | |
M1 = M.subs({x: val for x, val in zip(mc_vars, mc_rand_vars)}) | |
K1 = K.subs({x: val for x, val in zip(kc_vars, kc_rand_vars)}) | |
Mc1 = Mc.subs({x: val for x, val in zip(mc_vars, mc_rand_vars)}) | |
Kc1 = Kc.subs({x: val for x, val in zip(kc_vars, kc_rand_vars)}) | |
a, b = M1.condition_number(), K1.condition_number() | |
c, d = Mc1.condition_number(), Kc1.condition_number() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment