Factoring.ipynb
115 lines
| 2.1 KiB
| text/plain
|
TextLexer
Brian E. Granger
|
r16092 | { | ||
Min RK
|
r18669 | "cells": [ | ||
Brian E. Granger
|
r16092 | { | ||
Min RK
|
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", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
"outputs": [], | ||||
"source": [ | ||||
"from IPython.html.widgets import interact\n", | ||||
"from IPython.display import display" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
"outputs": [], | ||||
"source": [ | ||||
"from sympy import Symbol, Eq, factor, init_printing\n", | ||||
"init_printing(use_latex='mathjax')" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
"outputs": [], | ||||
"source": [ | ||||
"x = Symbol('x')" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "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", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
Jonathan Frederic
|
r20541 | "outputs": [], | ||
Min RK
|
r18669 | "source": [ | ||
"factorit(12)" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
Jonathan Frederic
|
r20541 | "outputs": [], | ||
Min RK
|
r18669 | "source": [ | ||
"interact(factorit, n=(2,40));" | ||||
] | ||||
Brian E. Granger
|
r16092 | } | ||
Min RK
|
r18669 | ], | ||
Min RK
|
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", | ||||
Jonathan Frederic
|
r20541 | "version": "3.4.0" | ||
Min RK
|
r20278 | } | ||
}, | ||||
Min RK
|
r18669 | "nbformat": 4, | ||
"nbformat_minor": 0 | ||||
Min RK
|
r20278 | } | ||