Skip to content

Commit 5435c78

Browse files
author
Murilo Marinho
committed
[lesson2] Adding draft answers.
1 parent 5097883 commit 5435c78

3 files changed

Lines changed: 157 additions & 1 deletion

File tree

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# L2 Exercise Answers\n",
8+
"\n",
9+
"*License: CC-BY-NC-SA 4.0*\n",
10+
"\n",
11+
"### I found an issue\n",
12+
"Thank you! Please report it at https://github.com/MarinhoLab/OpenExecutableBooksRobotics/issues\n",
13+
"\n",
14+
"### Latex Macros"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {
20+
"vscode": {
21+
"languageId": "latex"
22+
}
23+
},
24+
"source": [
25+
"$\\providecommand{\\myvec}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}$\n",
26+
"$\\providecommand{\\mymatrix}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}$"
27+
]
28+
},
29+
{
30+
"cell_type": "raw",
31+
"metadata": {
32+
"vscode": {
33+
"languageId": "raw"
34+
}
35+
},
36+
"source": [
37+
"\\providecommand{\\myvec}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}\n",
38+
"\\providecommand{\\mymatrix}[1]{{\\mathbf{\\boldsymbol{{#1}}}}}"
39+
]
40+
},
41+
{
42+
"metadata": {},
43+
"cell_type": "markdown",
44+
"source": "# Valid imports"
45+
},
46+
{
47+
"metadata": {},
48+
"cell_type": "code",
49+
"source": [
50+
"from math import pi, sin, cos\n",
51+
"import numpy as np"
52+
],
53+
"outputs": [],
54+
"execution_count": null
55+
},
56+
{
57+
"metadata": {},
58+
"cell_type": "markdown",
59+
"source": [
60+
"# Exercises\n",
61+
"\n",
62+
"## Exercise a"
63+
]
64+
},
65+
{
66+
"metadata": {},
67+
"cell_type": "code",
68+
"source": [
69+
"θ_a = pi/4.0\n",
70+
"\n",
71+
"R_a = np.array([[cos(θ_a),-sin(θ_a)],\n",
72+
" [sin(θ_a), cos(θ_a)]])\n",
73+
"\n",
74+
"# Printing the result is NOT a mandatory part of the answer.\n",
75+
"print(f'R_a = {R_a}')"
76+
],
77+
"outputs": [],
78+
"execution_count": null
79+
},
80+
{
81+
"metadata": {},
82+
"cell_type": "markdown",
83+
"source": "## Exercise b"
84+
},
85+
{
86+
"metadata": {},
87+
"cell_type": "code",
88+
"source": [
89+
"θ_b1 = pi/12.0\n",
90+
"θ_b2 = -pi/2.0\n",
91+
"\n",
92+
"R_b1 = np.array([[cos(θ_b1),-sin(θ_b1)],\n",
93+
" [sin(θ_b1), cos(θ_b1)]])\n",
94+
"\n",
95+
"R_b2 = np.array([[cos(θ_b2),-sin(θ_b2)],\n",
96+
" [sin(θ_b2), cos(θ_b2)]])\n",
97+
"\n",
98+
"R_b = R_b1 @ R_b2\n",
99+
"\n",
100+
"print(f'R_b = {R_b}')"
101+
],
102+
"outputs": [],
103+
"execution_count": null
104+
},
105+
{
106+
"metadata": {},
107+
"cell_type": "markdown",
108+
"source": "## Exercise c"
109+
},
110+
{
111+
"metadata": {},
112+
"cell_type": "code",
113+
"source": [
114+
"θ_c = pi/3.0 # As given in the exercise\n",
115+
"x_c = 2.0 # As given in the exercise\n",
116+
"y_c = 5.0 # As given in the exercise\n",
117+
"\n",
118+
"H_c1 = np.array([[cos(θ_c),-sin(θ_c), 0],\n",
119+
" [sin(θ_c), cos(θ_c), 0],\n",
120+
" [0, 0, 1]])\n",
121+
"\n",
122+
"H_c2 = np.array([[1,0,x_c],\n",
123+
" [0,1,y_c],\n",
124+
" [0,0,1]])\n",
125+
"\n",
126+
"H_c = H_c1 @ H_c2\n",
127+
"\n",
128+
"print(f'H_c = {H_c}')"
129+
],
130+
"outputs": [],
131+
"execution_count": null
132+
}
133+
],
134+
"metadata": {
135+
"kernelspec": {
136+
"display_name": ".venv",
137+
"language": "python",
138+
"name": "python3"
139+
},
140+
"language_info": {
141+
"codemirror_mode": {
142+
"name": "ipython",
143+
"version": 3
144+
},
145+
"file_extension": ".py",
146+
"mimetype": "text/x-python",
147+
"name": "python",
148+
"nbconvert_exporter": "python",
149+
"pygments_lexer": "ipython3",
150+
"version": "3.12.9"
151+
}
152+
},
153+
"nbformat": 4,
154+
"nbformat_minor": 2
155+
}

basic_lessons/lesson2_tutorial.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@
608608
"source": [
609609
"θ_c = pi/3.0 # As given in the exercise\n",
610610
"x_c = 2.0 # As given in the exercise\n",
611-
"y_c = 4.0 # As given in the exercise\n",
611+
"y_c = 5.0 # As given in the exercise\n",
612612
"\n",
613613
"H_c = None # Replace None with your solution to this exercise."
614614
],

myst.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ project:
4040
- file: basic_lessons/lesson4_tutorial.ipynb
4141
- file: basic_lessons/lesson5_tutorial.ipynb
4242
- file: basic_lessons/lesson1_exercise_answers.ipynb
43+
- file: basic_lessons/lesson2_exercise_answers.ipynb
4344
- title: "[Advanced] DQ Robotics"
4445
children:
4546
- file: dqrobotics/README.md

0 commit comments

Comments
 (0)