##// END OF EJS Templates
add kernel metadata to example notebooks
add kernel metadata to example notebooks

File last commit:

r20278:8f4dcac7
r20278:8f4dcac7
Show More
Factoring.ipynb
155 lines | 3.4 KiB | text/plain | TextLexer
Brian E. Granger
Refactoring interact examples.
r16092 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cells": [
Brian E. Granger
Refactoring interact examples.
r16092 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cell_type": "markdown",
"metadata": {},
"source": [
"# Factoring Polynomials with SymPy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here is an example that uses [SymPy](http://sympy.org/en/index.html) to factor polynomials."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from IPython.html.widgets import interact\n",
"from IPython.display import display"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from sympy import Symbol, Eq, factor, init_printing\n",
"init_printing(use_latex='mathjax')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = Symbol('x')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def factorit(n):\n",
" display(Eq(x**n-1, factor(x**n-1)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice how the output of the `factorit` function is properly formatted LaTeX."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
Brian E. Granger
Refactoring interact examples.
r16092 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "data": {
"text/latex": [
"$$x^{12} - 1 = \\left(x - 1\\right) \\left(x + 1\\right) \\left(x^{2} + 1\\right) \\left(x^{2} - x + 1\\right) \\left(x^{2} + x + 1\\right) \\left(x^{4} - x^{2} + 1\\right)$$"
],
"text/plain": [
Min RK
add kernel metadata to example notebooks
r20278 " 12 ⎛ 2 ⎞ ⎛ 2 ⎞ ⎛ 2 ⎞ ⎛ 4 2 ⎞\n",
"x - 1 = (x - 1)⋅(x + 1)⋅⎝x + 1⎠⋅⎝x - x + 1⎠⋅⎝x + x + 1⎠⋅⎝x - x + 1⎠"
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
Brian E. Granger
Refactoring interact examples.
r16092 "metadata": {},
Min RK
upate exmaple notebooks to nbformat v4
r18669 "output_type": "display_data"
}
],
"source": [
"factorit(12)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
Brian E. Granger
Refactoring interact examples.
r16092 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "data": {
"text/latex": [
"$$x^{21} - 1 = \\left(x - 1\\right) \\left(x^{2} + x + 1\\right) \\left(x^{6} + x^{5} + x^{4} + x^{3} + x^{2} + x + 1\\right) \\left(x^{12} - x^{11} + x^{9} - x^{8} + x^{6} - x^{4} + x^{3} - x + 1\\right)$$"
],
"text/plain": [
Min RK
add kernel metadata to example notebooks
r20278 " 21 ⎛ 2 ⎞ ⎛ 6 5 4 3 2 ⎞ ⎛ 12 11 \n",
"x - 1 = (x - 1)⋅⎝x + x + 1⎠⋅⎝x + x + x + x + x + x + 1⎠⋅⎝x - x + x\n",
Min RK
upate exmaple notebooks to nbformat v4
r18669 "\n",
Min RK
add kernel metadata to example notebooks
r20278 "9 8 6 4 3 ⎞\n",
" - x + x - x + x - x + 1⎠"
Min RK
upate exmaple notebooks to nbformat v4
r18669 ]
},
Brian E. Granger
Refactoring interact examples.
r16092 "metadata": {},
Min RK
upate exmaple notebooks to nbformat v4
r18669 "output_type": "display_data"
Brian E. Granger
Refactoring interact examples.
r16092 }
],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"interact(factorit, n=(2,40));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
Brian E. Granger
Refactoring interact examples.
r16092 }
Min RK
upate exmaple notebooks to nbformat v4
r18669 ],
Min RK
add kernel metadata to example notebooks
r20278 "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.4.2"
}
},
Min RK
upate exmaple notebooks to nbformat v4
r18669 "nbformat": 4,
"nbformat_minor": 0
Min RK
add kernel metadata to example notebooks
r20278 }