Day 4: (Thu Sep 5) Kinematics Etc.

Notes for 2019-09-05. See also the Fall 2019 Calendar.

Notes from Day 3

Agenda

  1. Administrative

  2. Assignments

  3. In-class

    1. Demos for Exercise: Dynamic Gesture on a Simulated Double Pendulum

    2. Brief numpy tutorial.

    3. Discussion of two-link kinematics.

    4. A few videos.

    5. Discussion of common platform ideas.

Lecture code samples

NumPy

We may use some of the NumPy library for numerical computing, which isn’t part of core Python.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Make the numpy library available under the name 'np'.
import numpy as np

# Create a 3-element zero vector (all floating point)
z = np.zeros((3))
print(z)

# Create a 3-element zero vector (integer)
z = np.zeros((3), dtype=np.int)
print(z)

# Create a 3x4 zero matrix (3 rows, 4 columns).
z = np.zeros((3,4))
print(z)

# Create an uninitialized 2x3 matrix (2 rows, 3 columns).
u = np.ndarray((2,3))
print(u)

# Create a 3x3 identity matrix.
I = np.array(((1.0,0,0),(0,1.0,0),(0,0,1.0)))
print(I)

# Create a 3x3 identity matrix.
I = np.eye(3)
print(I)

# Create a random 3-element vector.
R = np.random.rand(3)
print(R)

# Multiply by a scalar.
print(10 * R)

# Vector arithmetic.  The following operate element-by-element.

print(10 * R**2 + R)

print(np.sin(R))


# The same notation provides efficient access to large arrays.

big = np.random.rand(10000)

# Calculate the magnitude of the high-dimensional vector:

magnitude = np.sqrt(np.dot(big,big))

print("Long vector magnitude:", magnitude)

# The same is available as a primitive:
print("Long vector magnitude:", np.linalg.norm(big))

# For more, see https://docs.scipy.org/doc/numpy/reference/routines.linalg.html

Reference manual items:

And the broader SciPy:

Not to mention more specialized libraries: