Last active
March 29, 2019 09:58
-
-
Save dsaint31x/267f832eb929fc29ca984c0715d92fa5 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 1: 다음에 언급된 Physical Quantity들이 scalar인지 vector인지 고르시오.\n", | |
"\n", | |
"1. $20m^2$의 넓이 : Scalar\n", | |
"2. $10N$의 힘(F) : Vector" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 2: 다음 벡터의 2-Norm(크기)을 구하시오\n", | |
"\n", | |
"1. $ \\vec{a} = <1,0,2>$\n", | |
"2. $ \\vec{b}=<0,3>$\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 58, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"2-1: 2.23606797749979 |np.sqrt(5) 2.23606797749979\n", | |
"2-2: 3.0\n" | |
] | |
} | |
], | |
"source": [ | |
"vec = [[1,0,2],[0,3,0]]\n", | |
"L2_norm = np.linalg.norm(vec,axis=1,ord=2)\n", | |
"print('2-1:',L2_norm[0],'|np.sqrt(5)',np.sqrt(5))\n", | |
"print('2-2:',L2_norm[1])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 3: 다음을 계산하시오.\n", | |
"\n", | |
"다음과 같은 vector가 있음.\n", | |
"\n", | |
"$$\n", | |
"\\vec{a}=<2,1,-3> \\\\\n", | |
"\\vec{b}=<0,4,-2>\n", | |
"$$\n", | |
"\n", | |
"1. $\\vec{a}+\\vec{b}$\n", | |
"2. $\\vec{a}-2\\vec{b}$\n", | |
"3. $\\vec{a}$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 44, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"3-1: [ 2 5 -5]\n", | |
"3-2: [ 2 -7 1]\n", | |
"3-3: [ 2 1 -3]\n" | |
] | |
} | |
], | |
"source": [ | |
"a = np.array([2,1,-3])\n", | |
"b = np.array([0,4,-2])\n", | |
"\n", | |
"print('3-1:',a+b)\n", | |
"print('3-2:',a-2*b)\n", | |
"print('3-3:',a)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 4: 다음 중 Unit vector인 것은?\n", | |
"\n", | |
"1. $\\vec{a}=<0,2,-1>$\n", | |
"2. $\\vec{a}=<0,0,-1>$\n", | |
"3. $\\vec{a}=<1,1,1>$\n", | |
"4. $\\vec{a}=<\\frac{3}{5},0,\\frac{4}{5}>$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 52, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4-1:False\n", | |
"4-2:True\n", | |
"4-3:False\n", | |
"4-4:True\n" | |
] | |
} | |
], | |
"source": [ | |
"vec = [[0,2,-1],[0,0,-1],[1,1,1],[3/5,0,4/5]]\n", | |
"L2_norm = np.linalg.norm(vec,axis=1,ord=2)\n", | |
"answers = [L2_norm==1]\n", | |
"for idx,val in enumerate(answers[0]):\n", | |
" print('4-{}:{}'.format(idx+1,val))\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 5: 다음의 vector와 반대 방향의 unit vector를 구하시오.\n", | |
"\n", | |
"$$ \\vec{a}=<3,1,-2> $$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 59, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[-0.80178373 -0.26726124 0.53452248]\n", | |
"-0.8017837257372732 -0.2672612419124244 0.5345224838248488\n" | |
] | |
} | |
], | |
"source": [ | |
"a = np.array([3,1,-2])\n", | |
"b = -1*a/np.linalg.norm(a)\n", | |
"print(b)\n", | |
"print(-3/np.sqrt(14),-1/np.sqrt(14),2/np.sqrt(14))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 6: 다음을 구하시오\n", | |
"\n", | |
"$$ \\vec{a}=<3,-2,1> \\\\ \\vec{b}=<-4,5,1> $$\n", | |
"\n", | |
"1. $\\vec{a}\\cdot\\vec{b}$\n", | |
"2. $\\vec{b}\\cdot\\vec{b}$\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 51, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"6-1: -21\n", | |
"6-2: 42\n" | |
] | |
} | |
], | |
"source": [ | |
"a = np.array([3,-2,1])\n", | |
"b = np.array([-4,5,1])\n", | |
"\n", | |
"print('6-1:',np.dot(a,b))\n", | |
"print('6-2:',np.dot(b,b))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 7: 다음의 vector들이 orthogonal한지 증명하시오.\n", | |
"\n", | |
"1. $\\vec{a}=<4,0,0>, \\vec{b}=<0,-3,1>$\n", | |
"2. $\\vec{a}=<4,0,1>, \\vec{b}=<0,-2,1>$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 54, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"7-1: a and b is orthogonal: True\n", | |
"7-2: a and b is orthogonal: False\n" | |
] | |
} | |
], | |
"source": [ | |
"def is_orthogonal(a,b):\n", | |
" dot = np.dot(a,b)\n", | |
" if dot == 0:\n", | |
" #print('orthogonal')\n", | |
" return True\n", | |
" else:\n", | |
" #print('not orthogonal')\n", | |
" return False\n", | |
" \n", | |
" \n", | |
"a = np.array([4,0,0])\n", | |
"b = np.array([0,-3,1])\n", | |
"print('7-1: a and b is orthogonal:',is_orthogonal(a,b))\n", | |
"\n", | |
"a = np.array([4,0,1])\n", | |
"b = np.array([0,-2,1])\n", | |
"print('7-2: a and b is orthogonal:',is_orthogonal(a,b))\n", | |
"\n", | |
"#a = np.array([0,0,1])\n", | |
"#b = np.array([0,1,0])\n", | |
"#print('7-3: a and b is orthogonal:',is_orthogonal(a,b))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### 8: 다음을 구하시오.\n", | |
"\n", | |
"$$ \\vec{a}=<1,2,3> \\\\ \\vec{b}=<4,0,1> $$\n", | |
"\n", | |
"1. $\\vec{a}\\times\\vec{b}$\n", | |
"2. $\\vec{b}\\times\\vec{b}$\n", | |
"3. $\\vec{b}\\times\\vec{a}$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 55, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"8-1: [ 2 11 -8]\n", | |
"8-2: [0 0 0]\n", | |
"8-3: [ -2 -11 8]\n" | |
] | |
} | |
], | |
"source": [ | |
"a = np.array([1,2,3])\n", | |
"b = np.array([4,0,1])\n", | |
"\n", | |
"print('8-1:',np.cross(a,b))\n", | |
"print('8-2:',np.cross(b,b))\n", | |
"print('8-3:',np.cross(b,a))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment