Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes and improvements for Sage (Jupyter Notebook) -> Markdown #9

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ commands :
@grep -h -E '^##' ${MAKEFILES} | sed -e 's/## //g'

## serve : run a local server.
serve : lesson-rmd
serve : lesson-rmd lesson-ipynb
${JEKYLL} serve

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

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

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

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

Expand All @@ -112,6 +112,8 @@ unittest :
lesson-files :
@echo 'RMD_SRC:' ${RMD_SRC}
@echo 'RMD_DST:' ${RMD_DST}
@echo 'IPYNB_SRC:' ${IPYNB_SRC}
@echo 'IPYNB_DST:' ${IPYNB_DST}
@echo 'MARKDOWN_SRC:' ${MARKDOWN_SRC}
@echo 'HTML_DST:' ${HTML_DST}

Expand Down
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ exclude:

# Turn off built-in syntax highlighting.
highlighter: false

kramdown:
parse_block_html: true
36 changes: 0 additions & 36 deletions _episodes/01-first-session.md

This file was deleted.

110 changes: 110 additions & 0 deletions _episodes/01-introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: First session with SageMath
teaching: 30
exercises: 0
questions:
- "..."
objectives:
- "..."
---

Lesson text



~~~
1 + 1
~~~
{: .source .python}



~~~
2
~~~
{: .output}




~~~
matrix([[1,2], [3,4]])^(-1)
~~~
{: .source .python}



~~~
[ -2 1]
[ 3/2 -1/2]
~~~
{: .output}


Output with error message:


~~~
x[10]
~~~
{: .source .python}

~~~
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-084faa554d6d> in <module>()
----> 1 x[Integer(10)]

TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
~~~
{: .error}
Output generating figures:


~~~
plot(sin, (0,10))
~~~
{: .source .python}



![png](../01-introduction_files/01-introduction_6_0.png)


For the challenges
you need to pay attention to include `<blockquote class="challenge">`
before it and `<\blockquote>` after it.
And for the solutions
you need to pay attention to include `<blockquote class="solution">`
before it and `<\blockquote>` after it.
**This hacks is necessary for allow include Jupyter cells on challenges and solutions.**
<blockquote class="challenge">
## Challenge: Can you do it?

What is the output of this command?

~~~
"a" + "b"
~~~
{: .source}

<blockquote class="solution">

## Solution


~~~
"a" + "b"
~~~
{: .source .python}



~~~
'ab'
~~~
{: .output}


</blockquote>
</blockquote>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
163 changes: 163 additions & 0 deletions _episodes/02-multiply-matrix-and-vector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
title: Multiply a matrix and a vector
teaching: 30
exercises: 0
questions:
- "..."
objectives:
- "..."
---
Let us define the 3 x 3 minus-identity matrix


~~~
A = matrix([[-1,0,0], [0,-1,0], [0,0,-1]])
A
~~~
{: .source .python}



~~~
[-1 0 0]
[ 0 -1 0]
[ 0 0 -1]
~~~
{: .output}


Or simply


~~~
A = -identity_matrix(3)
A
~~~
{: .source .python}



~~~
[-1 0 0]
[ 0 -1 0]
[ 0 0 -1]
~~~
{: .output}


Define vector `v` to be the vector with coordinates `x`, `y`, `z`


~~~
v = vector([x, y, z])
~~~
{: .source .python}

~~~
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-74f33ececb47> in <module>()
----> 1 v = vector([x, y, z])

NameError: name 'y' is not defined
~~~
{: .error}
Didn't work... We need to define `y` (and `z`) as symbolic variables. Only `x` is defined by default when you launch Sage!


~~~
x, y, z = SR.var("x y z")
~~~
{: .source .python}


~~~
v = vector([x, y, z])
v
~~~
{: .source .python}



~~~
(x, y, z)
~~~
{: .output}


Multiply matrix and vector using `*`


~~~
A * v
~~~
{: .source .python}



~~~
(-x, -y, -z)
~~~
{: .output}




~~~
v.subs(x=1, y=0, z=3)
~~~
{: .source .python}



~~~
(1, 0, 3)
~~~
{: .output}




~~~
A * v.subs(x=1, y=0, z=3)
~~~
{: .source .python}



~~~
(-1, 0, -3)
~~~
{: .output}




~~~
A * v
~~~
{: .source .python}



~~~
(-x, -y, -z)
~~~
{: .output}




~~~
_.subs(x=1, y=0, z=3)
~~~
{: .source .python}



~~~
(-1, 0, -3)
~~~
{: .output}


Loading