3. 基底と次元
code: lincombi.py
from vpython import vec, arrow, color, points
from numpy.random import normal
x = vec(*normal(0, 1, 3))
arrow(pos=vec(0, 0, 0), axis=x, color=color.red)
y = vec(*normal(0, 1, 3))
arrow(pos=vec(0, 0, 0), axis=y, color=color.red)
points(pos=W, radius=2)
https://gyazo.com/20ccc2b29748905aefdd386211acd332
code: eqn1.py
from sympy import solve
from sympy.abc import a, b, x, y
code: python
>> ans
{b: 2*x - y, a: -3*x + 2*y}
-3*x + 2*y
2*x - y
code: eqn2.py
from sympy import solve
from sympy.abc import a, b, x, y, z
code:python
>> ans
[]
code: eqn3.py
from sympy import solve
from sympy.abc import a, b, c, x, y, z
ans = solve([a + 2 * b + 3 * c - x, 2 * a + 3 * b + c - y,
3 * a + 4 * b + 2 * c - z], a, b, c) code:python
>> M
>> N = [m.subs(x, 2], y, 3, [z, 5) for m in M] >> N
code: eqn4.py
from sympy import solve
from sympy.abc import x, y
print(ans)
code: python
{x: 0, y: 0}
code: eqn5.py
from sympy import solve
from sympy.abc import x, y
print(ans)
code: python
{x: -2*y}
code: arrow2d.py
import matplotlib.pyplot as plt
o, a, b, c = (0, 0), (1, 2), (2, 3), (2, 4)
arrows = o, a, 'r', 0.1], o, b, 'g', 0.05, [o, c, 'b', 0.05 for p, v, c, w in arrows:
plt.quiver(p0, p1, v0, v1, units='xy', scale=1, color=c, width=w)
plt.axis('scaled'), plt.xlim(0, 5), plt.ylim(0, 5), plt.show()
https://gyazo.com/8729a1c4491de2284748de8eae079498
code: eqn6.py
from sympy import solve
from sympy.abc import x, y, z
print(ans1)
print(ans2)
code:python
{y: -2*z, x: z}
{z: 0, y: 0, x: 0}
code: arrow3d.py
from vpython import vec, arrow, mag
o = vec(0, 0, 0)
for p in (1, 2, 3), (2, 3, 4), (3, 4, 5), (3, 1, 2): v = vec(*p)
arrow(pos=o, axis=v, color=v, shaftwidth=mag(v) * 0.02)
https://gyazo.com/a1aa8b01d2967e43c056483318739e9b
code: lena3.py
from vpython import canvas, vec, curve, arrow, color, points
from numpy import array, linspace, sin, cos, pi, random
canvas(background=color.white, foreground=color.black)
curve(pos=-v, v, color=v) with open('lena.txt', 'r') as fd:
XY = eval(fd.read())
random.seed(123)
a = vec(*random.normal(0, 1, 3))
arrow(pos=vec(0, 0, 0), axis=a, shaftwidth=0.1)
b = vec(*random.normal(0, 1, 3))
arrow(pos=vec(0, 0, 0), axis=b, shaftwidth=0.1)
points(pos=P, radius=2, color=color.cyan)
curve(pos=Q, color=color.magenta)
https://gyazo.com/8bc425427abeb8f1649de8a95b9be788
code: rank.py
from numpy.linalg import matrix_rank
def f(*x): return matrix_rank(x)
a, b, c = (1, 2), (2, 3), (2, 4)
print(f(a, b), f(b, c), f(a, c), f(a, b, c))
a, b, c, d = (1, 2, 3), (2, 3, 4), (3, 4, 5), (3, 4, 4)
print(f(a, b), f(a, b, c), f(a, b, d), f(a, b, c, d))
code: dim.py
from numpy import array
B = array(1, 2, 3], [4, 5, 6)
code: random2d.py
import matplotlib.pyplot as plt
from numpy.random import normal
P = normal(0, 1, (1000, 2))
plt.axis('equal'), plt.show()
https://gyazo.com/f3fc5f68b36bee01030756a14edfe727
code: random3d.py
from vpython import canvas, color, vec, curve, points
from numpy.random import normal
canvas(background=color.white, foreground=color.black)
curve(pos=-v, v, color=v) P = normal(0, 1, (1000, 3))
https://gyazo.com/0113a3ccaeb10654390095d2f61a8770