# Solvers

Boilerplate to make the doctester work. 


```
import sys
import os
sys.path.insert(1, os.path.join(os.path.pardir, "ipython_doctester"))
from sympy import *
from ipython_doctester import test
# Work around a bug in IPython. This will disable the ability to paste things with >>>
def notransform(line): return line
from IPython.core import inputsplitter
inputsplitter.transform_classic_prompt = notransform
init_printing()
```

For each exercise, fill in the function according to its docstring. Execute the cell to see if you did it right. 


```
a, b, c, d, x, y, z, t = symbols('a b c d x y z t')
f, g, h = symbols('f g h', cls=Function)
```

## Algebraic Equations

Write a function that computes the [quadratic equation](http://en.wikipedia.org/wiki/Quadratic_equation).


```
def quadratic():
    return solve(a*x**2 + b*x + c, x)
quadratic()
```




$$\begin{bmatrix}\frac{- b + \sqrt{- 4 a c + b^{2}}}{2 a}, & - \frac{b + \sqrt{- 4 a c + b^{2}}}{2 a}\end{bmatrix}$$



Write a function that computes the general solution to the cubic $x^3 + ax^2 + bx + c$.


```
def cubic():
    return solve(x**3 + a*x**2 + b*x + c, x)
cubic()
```




$$\begin{bmatrix}- \frac{1}{3} a + \frac{- \frac{1}{9} a^{2} + \frac{1}{3} b}{\sqrt[3]{\frac{1}{27} a^{3} - \frac{1}{6} a b + \frac{1}{2} c + \sqrt{\left(- \frac{1}{9} a^{2} + \frac{1}{3} b\right)^{3} + \frac{1}{4} \left(\frac{2}{27} a^{3} - \frac{1}{3} a b + c\right)^{2}}}} - \sqrt[3]{\frac{1}{27} a^{3} - \frac{1}{6} a b + \frac{1}{2} c + \sqrt{\left(- \frac{1}{9} a^{2} + \frac{1}{3} b\right)^{3} + \frac{1}{4} \left(\frac{2}{27} a^{3} - \frac{1}{3} a b + c\right)^{2}}}, & - \frac{1}{3} a + \frac{- \frac{1}{9} a^{2} + \frac{1}{3} b}{\left(- \frac{1}{2} - \frac{1}{2} \sqrt{3} \mathbf{\imath}\right) \sqrt[3]{\frac{1}{27} a^{3} - \frac{1}{6} a b + \frac{1}{2} c + \sqrt{\left(- \frac{1}{9} a^{2} + \frac{1}{3} b\right)^{3} + \frac{1}{4} \left(\frac{2}{27} a^{3} - \frac{1}{3} a b + c\right)^{2}}}} - \left(- \frac{1}{2} - \frac{1}{2} \sqrt{3} \mathbf{\imath}\right) \sqrt[3]{\frac{1}{27} a^{3} - \frac{1}{6} a b + \frac{1}{2} c + \sqrt{\left(- \frac{1}{9} a^{2} + \frac{1}{3} b\right)^{3} + \frac{1}{4} \left(\frac{2}{27} a^{3} - \frac{1}{3} a b + c\right)^{2}}}, & - \frac{1}{3} a + \frac{- \frac{1}{9} a^{2} + \frac{1}{3} b}{\left(- \frac{1}{2} + \frac{1}{2} \sqrt{3} \mathbf{\imath}\right) \sqrt[3]{\frac{1}{27} a^{3} - \frac{1}{6} a b + \frac{1}{2} c + \sqrt{\left(- \frac{1}{9} a^{2} + \frac{1}{3} b\right)^{3} + \frac{1}{4} \left(\frac{2}{27} a^{3} - \frac{1}{3} a b + c\right)^{2}}}} - \left(- \frac{1}{2} + \frac{1}{2} \sqrt{3} \mathbf{\imath}\right) \sqrt[3]{\frac{1}{27} a^{3} - \frac{1}{6} a b + \frac{1}{2} c + \sqrt{\left(- \frac{1}{9} a^{2} + \frac{1}{3} b\right)^{3} + \frac{1}{4} \left(\frac{2}{27} a^{3} - \frac{1}{3} a b + c\right)^{2}}}\end{bmatrix}$$



## Differential Equations

A population that grows without bound is modeled by the differential equation

$$f'(t)=af(t)$$

Solve this differential equation using SymPy.


```
dsolve(f(t).diff(t) - a*f(t), f(t))
```

If the population growth is bounded, it is modeled by 

$$f'(t) = f(t)(1 - f(t))$$


```
dsolve(f(t).diff(t) - f(t)*(1 - f(t)), f(t))
```

47ce9087ce760bb2273c8659bd83cea67034e86f
ipynb
Jupyter Notebook
tutorial_exercises/Solvers Solutions.ipynb
certik/scipy-2013-tutorial
26a1cab3a16402afdc20088cedf47acd9bc58483
BSD-3-Clause
2015-02-28T08:53:05.000Z
2021-12-05T05:37:59.000Z
sympy/Solvers Solutions.ipynb
certik/scipy-in-13
418c139ab6e1b0c9acd53e7e1a02b8b930005096
BSD-3-Clause
2021-04-17T15:05:46.000Z
2021-04-17T15:05:46.000Z
sympy/Solvers Solutions.ipynb
certik/scipy-in-13
418c139ab6e1b0c9acd53e7e1a02b8b930005096
BSD-3-Clause
2015-03-11T00:25:21.000Z
2021-08-25T14:52:40.000Z
Qwen/Qwen-72B
1. YES
2. YES