{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Solvers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from sympy import *\n", "init_printing()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For each exercise, fill in the function according to its docstring. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a, b, c, d, x, y, z, t = symbols('a b c d x y z t')\n", "f, g, h = symbols('f g h', cls=Function)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Algebraic Equations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write a function that computes the [quadratic equation](http://en.wikipedia.org/wiki/Quadratic_equation)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def quadratic():\n", " return solve(a*x**2 + b*x + c, x)\n", "quadratic()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write a function that computes the general solution to the cubic $x^3 + ax^2 + bx + c$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def cubic():\n", " return solve(x**3 + a*x**2 + b*x + c, x)\n", "cubic()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Differential Equations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A population that grows without bound is modeled by the differential equation\n", "\n", "$$f'(t)=af(t)$$\n", "\n", "Solve this differential equation using SymPy." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dsolve(f(t).diff(t) - a*f(t), f(t))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If the population growth is bounded, it is modeled by \n", "\n", "$$f'(t) = f(t)(1 - f(t))$$\n", "\n", "Solve this differential equation using SymPy." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dsolve(f(t).diff(t) - f(t)*(1 - f(t)), f(t))" ] } ], "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.6.1" } }, "nbformat": 4, "nbformat_minor": 1 }