Skip to content

Commit ad55037

Browse files
Merge pull request #9 from rgaiacs/episodes-ipynb
Minor fixes and improvements for Sage (Jupyter Notebook) -> Markdown
2 parents 5693c07 + 5c04bb4 commit ad55037

32 files changed

+3806
-140
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ commands :
1717
@grep -h -E '^##' ${MAKEFILES} | sed -e 's/## //g'
1818

1919
## serve : run a local server.
20-
serve : lesson-rmd
20+
serve : lesson-rmd lesson-ipynb
2121
${JEKYLL} serve
2222

2323
## site : build files but do not run a server.
@@ -62,7 +62,7 @@ RMD_DST = $(patsubst _episodes_rmd/%.Rmd,_episodes/%.md,$(RMD_SRC))
6262

6363
# RMarkdown files
6464
IPYNB_SRC = $(wildcard _episodes_ipynb/??-*.ipynb)
65-
IPYNB_DST = $(patsubst _episodes_ipynb/%.ipynb,_episodes/%.ipynb,$(RMD_SRC))
65+
IPYNB_DST = $(patsubst _episodes_ipynb/%.ipynb,_episodes/%.ipynb,$(IPYNB_SRC))
6666

6767
# Lesson source files in the order they appear in the navigation menu.
6868
MARKDOWN_SRC = \
@@ -88,7 +88,7 @@ HTML_DST = \
8888
lesson-rmd: $(RMD_SRC)
8989
@bin/knit_lessons.sh $(RMD_SRC)
9090

91-
## lesson-ipynb : convert IPython Notebook files to markdown
91+
## lesson-ipynb : convert IPython Notebook files to markdown
9292
lesson-ipynb: $(IPYNB_SRC)
9393
${SAGE} -sh -c "jupyter nbconvert -y --execute --allow-errors --to markdown --output-dir=_episodes --template=_layouts/ipynb2md.tpl $(IPYNB_SRC)"
9494

@@ -112,6 +112,8 @@ unittest :
112112
lesson-files :
113113
@echo 'RMD_SRC:' ${RMD_SRC}
114114
@echo 'RMD_DST:' ${RMD_DST}
115+
@echo 'IPYNB_SRC:' ${IPYNB_SRC}
116+
@echo 'IPYNB_DST:' ${IPYNB_DST}
115117
@echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
116118
@echo 'HTML_DST:' ${HTML_DST}
117119

_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ exclude:
6767

6868
# Turn off built-in syntax highlighting.
6969
highlighter: false
70+
71+
kramdown:
72+
parse_block_html: true

_episodes/01-first-session.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

_episodes/01-introduction.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
title: First session with SageMath
3+
teaching: 30
4+
exercises: 0
5+
questions:
6+
- "..."
7+
objectives:
8+
- "..."
9+
---
10+
11+
Lesson text
12+
13+
14+
15+
~~~
16+
1 + 1
17+
~~~
18+
{: .source .python}
19+
20+
21+
22+
~~~
23+
2
24+
~~~
25+
{: .output}
26+
27+
28+
29+
30+
~~~
31+
matrix([[1,2], [3,4]])^(-1)
32+
~~~
33+
{: .source .python}
34+
35+
36+
37+
~~~
38+
[ -2 1]
39+
[ 3/2 -1/2]
40+
~~~
41+
{: .output}
42+
43+
44+
Output with error message:
45+
46+
47+
~~~
48+
x[10]
49+
~~~
50+
{: .source .python}
51+
52+
~~~
53+
---------------------------------------------------------------------------
54+
TypeError Traceback (most recent call last)
55+
<ipython-input-3-084faa554d6d> in <module>()
56+
----> 1 x[Integer(10)]
57+
58+
TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
59+
~~~
60+
{: .error}
61+
Output generating figures:
62+
63+
64+
~~~
65+
plot(sin, (0,10))
66+
~~~
67+
{: .source .python}
68+
69+
70+
71+
![png](../01-introduction_files/01-introduction_6_0.png)
72+
73+
74+
For the challenges
75+
you need to pay attention to include `<blockquote class="challenge">`
76+
before it and `<\blockquote>` after it.
77+
And for the solutions
78+
you need to pay attention to include `<blockquote class="solution">`
79+
before it and `<\blockquote>` after it.
80+
**This hacks is necessary for allow include Jupyter cells on challenges and solutions.**
81+
<blockquote class="challenge">
82+
## Challenge: Can you do it?
83+
84+
What is the output of this command?
85+
86+
~~~
87+
"a" + "b"
88+
~~~
89+
{: .source}
90+
91+
<blockquote class="solution">
92+
93+
## Solution
94+
95+
96+
~~~
97+
"a" + "b"
98+
~~~
99+
{: .source .python}
100+
101+
102+
103+
~~~
104+
'ab'
105+
~~~
106+
{: .output}
107+
108+
109+
</blockquote>
110+
</blockquote>
25.9 KB
Loading
26 KB
Loading
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
title: Multiply a matrix and a vector
3+
teaching: 30
4+
exercises: 0
5+
questions:
6+
- "..."
7+
objectives:
8+
- "..."
9+
---
10+
Let us define the 3 x 3 minus-identity matrix
11+
12+
13+
~~~
14+
A = matrix([[-1,0,0], [0,-1,0], [0,0,-1]])
15+
A
16+
~~~
17+
{: .source .python}
18+
19+
20+
21+
~~~
22+
[-1 0 0]
23+
[ 0 -1 0]
24+
[ 0 0 -1]
25+
~~~
26+
{: .output}
27+
28+
29+
Or simply
30+
31+
32+
~~~
33+
A = -identity_matrix(3)
34+
A
35+
~~~
36+
{: .source .python}
37+
38+
39+
40+
~~~
41+
[-1 0 0]
42+
[ 0 -1 0]
43+
[ 0 0 -1]
44+
~~~
45+
{: .output}
46+
47+
48+
Define vector `v` to be the vector with coordinates `x`, `y`, `z`
49+
50+
51+
~~~
52+
v = vector([x, y, z])
53+
~~~
54+
{: .source .python}
55+
56+
~~~
57+
---------------------------------------------------------------------------
58+
NameError Traceback (most recent call last)
59+
<ipython-input-3-74f33ececb47> in <module>()
60+
----> 1 v = vector([x, y, z])
61+
62+
NameError: name 'y' is not defined
63+
~~~
64+
{: .error}
65+
Didn't work... We need to define `y` (and `z`) as symbolic variables. Only `x` is defined by default when you launch Sage!
66+
67+
68+
~~~
69+
x, y, z = SR.var("x y z")
70+
~~~
71+
{: .source .python}
72+
73+
74+
~~~
75+
v = vector([x, y, z])
76+
v
77+
~~~
78+
{: .source .python}
79+
80+
81+
82+
~~~
83+
(x, y, z)
84+
~~~
85+
{: .output}
86+
87+
88+
Multiply matrix and vector using `*`
89+
90+
91+
~~~
92+
A * v
93+
~~~
94+
{: .source .python}
95+
96+
97+
98+
~~~
99+
(-x, -y, -z)
100+
~~~
101+
{: .output}
102+
103+
104+
105+
106+
~~~
107+
v.subs(x=1, y=0, z=3)
108+
~~~
109+
{: .source .python}
110+
111+
112+
113+
~~~
114+
(1, 0, 3)
115+
~~~
116+
{: .output}
117+
118+
119+
120+
121+
~~~
122+
A * v.subs(x=1, y=0, z=3)
123+
~~~
124+
{: .source .python}
125+
126+
127+
128+
~~~
129+
(-1, 0, -3)
130+
~~~
131+
{: .output}
132+
133+
134+
135+
136+
~~~
137+
A * v
138+
~~~
139+
{: .source .python}
140+
141+
142+
143+
~~~
144+
(-x, -y, -z)
145+
~~~
146+
{: .output}
147+
148+
149+
150+
151+
~~~
152+
_.subs(x=1, y=0, z=3)
153+
~~~
154+
{: .source .python}
155+
156+
157+
158+
~~~
159+
(-1, 0, -3)
160+
~~~
161+
{: .output}
162+
163+

0 commit comments

Comments
 (0)