Check NumPy Version

import numpy as np

np.__version__

1. 다음에 언급된 Physical Quantity들이 scalar인지 vector인지 고르시오.

  1. $20 \text{m}^2$의 넓이 : scalar
  2. $10 N$의 힘 : vector

2. 다음 벡터의 L2-Norm(크기)을 구하시오

  1. $\vec{a} = \langle1,0,2\rangle$
  2. $\vec{b}=\langle0,3\rangle$
vec = [[1,0,2],[0,3,0]]
L2_norm = np.linalg.norm(vec,axis=1,ord=2)
print('2-1:',L2_norm[0],'|np.sqrt(5)',np.sqrt(5))
print('2-2:',L2_norm[1])

3. 다음을 계산하시오.

다음과 같은 vector가 있음.

$$
\vec{a}=\langle2,1,-3\rangle ,
\vec{b}=\langle0,4,-2\rangle
$$

  1. $\vec{a}+\vec{b}$
  2. $\vec{a}-2\vec{b}$
  3. $3\vec{a}$
a = np.array([2,1,-3])
b = np.array([0,4,-2])

print('3-1:',a+b)
print('3-2:',a-2*b)
print('3-3:',3*a)

4. 다음 중 Unit vector인 것은?

  1. $\vec{a}=\langle0,2,-1\rangle$
  2. $\vec{a}=\langle0,0,-1\rangle$
  3. $\vec{a}=\langle1,1,1 \rangle$
  4. $\vec{a}=\langle\dfrac{3}{5}, 0 ,\dfrac{4}{5}\rangle$
vec = [[0,2,-1],[0,0,-1],[1,1,1],[3/5,0,4/5]]
L2_norm = np.linalg.norm(vec,axis=1,ord=2)
answers = [L2_norm==1]
for idx,val in enumerate(answers[0]):
    print('4-{}:{}'.format(idx+1,val))

5. 다음의 vector와 반대 방향의 unit vector를 구하시오.

$$
\vec{a} = \left< 3, 1, -2 \right>
$$

a = np.array([3,1,-2])
b = -1*a/np.linalg.norm(a)
print(b)
print(-3/np.sqrt(14),-1/np.sqrt(14),2/np.sqrt(14))

6. 다음을 구하시오.

$$
\vec{a}=\langle3,-2,1\rangle,\
\vec{b}=\langle-4,5,1\rangle
$$

  1. $\vec{a}\cdot\vec{b}$
  2. $\vec{b}\cdot\vec{b}$
a = np.array([3,-2,1])
b = np.array([-4,5,1])

print('6-1:',np.dot(a,b))
print('6-2:',np.dot(b,b))

7. 다음의 vector들이 orthogonal 인가?

  1. $\vec{a}=\langle4,0,0\rangle, \vec{b}=\langle0,-3,1\rangle$
  2. $\vec{a}=\langle4,0,1\rangle, \vec{b}=\langle0,-2,1\rangle$
def is_orthogonal(a,b):
    dot = np.dot(a,b)
    if dot == 0:
        #print('orthogonal')
        return True
    else:
        #print('not orthogonal')
        return False


a = np.array([4,0,0])
b = np.array([0,-3,1])
print('7-1: a and b is orthogonal:',is_orthogonal(a,b))

a = np.array([4,0,1])
b = np.array([0,-2,1])
print('7-2: a and b is orthogonal:',is_orthogonal(a,b))

#a = np.array([0,0,1])
#b = np.array([0,1,0])
#print('7-3: a and b is orthogonal:',is_orthogonal(a,b))

8. 다음을 구하시오.

$$
\vec{a}=\langle1,2,3\rangle, \vec{b}=\langle4,0,1\rangle
$$

  1. $\vec{a}\times\vec{b}$
  2. $\vec{b}\times\vec{b}$
  3. $\vec{b}\times\vec{a}$
a = np.array([1,2,3])
b = np.array([4,0,1])

print('8-1:',np.cross(a,b))
print('8-2:',np.cross(b,b))
print('8-3:',np.cross(b,a))

Ref.

(https://colab.research.google.com/github/dsaint31x/Physics/blob/master/src/20220329_vector_ex.ipynb#scrollTo=xlXBN-8da4Dj)

반응형

+ Recent posts