<a href="https://colab.research.google.com/github/ricklon/jupytercalculus/blob/master/Calculus_Self_Guided.ipynb" target="_parent"></a>

Plot a parabola

Example from: https://stackoverflow.com/questions/30553585/graphing-a-parabola-using-matplotlib-in-python

More examples: https://github.com/nishadhka/Learning-Calculus-with-Python/blob/master/p1_sympy_intro/basic_calculus_sympy.ipynb



```python
!pip install matplotlib
!pip install numpy
!pip install sympy

```

    WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
    Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
    To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
    Collecting matplotlib
      Downloading matplotlib-3.1.3-cp37-cp37m-manylinux1_x86_64.whl (13.1 MB)
    [K     |████████████████████████████████| 13.1 MB 4.2 MB/s eta 0:00:01    |█████▊                          | 2.4 MB 3.2 MB/s eta 0:00:04     |████████▊                       | 3.6 MB 3.2 MB/s eta 0:00:03     |█████████████████████▌          | 8.8 MB 4.6 MB/s eta 0:00:01     |█████████████████████████████   | 11.9 MB 4.2 MB/s eta 0:00:01
    [?25hCollecting cycler>=0.10
      Downloading cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)
    Collecting kiwisolver>=1.0.1
      Downloading kiwisolver-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (90 kB)
    [K     |████████████████████████████████| 90 kB 6.0 MB/s eta 0:00:011
    [?25hRequirement already satisfied: python-dateutil>=2.1 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from matplotlib) (2.8.1)
    Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1
      Downloading pyparsing-2.4.6-py2.py3-none-any.whl (67 kB)
    [K     |████████████████████████████████| 67 kB 6.9 MB/s  eta 0:00:01
    [?25hCollecting numpy>=1.11
      Downloading numpy-1.18.1-cp37-cp37m-manylinux1_x86_64.whl (20.1 MB)
    [K     |████████████████████████████████| 20.1 MB 4.0 MB/s eta 0:00:01     |██████                          | 3.7 MB 14.1 MB/s eta 0:00:02     |███████▎                        | 4.5 MB 3.4 MB/s eta 0:00:05     |███████████▎                    | 7.1 MB 3.4 MB/s eta 0:00:04
    [?25hRequirement already satisfied: six in /srv/conda/envs/notebook/lib/python3.7/site-packages (from cycler>=0.10->matplotlib) (1.14.0)
    Requirement already satisfied: setuptools in /srv/conda/envs/notebook/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib) (45.1.0.post20200119)
    Installing collected packages: cycler, kiwisolver, pyparsing, numpy, matplotlib
    Successfully installed cycler-0.10.0 kiwisolver-1.1.0 matplotlib-3.1.3 numpy-1.18.1 pyparsing-2.4.6
    WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
    Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
    To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
    Requirement already satisfied: numpy in /srv/conda/envs/notebook/lib/python3.7/site-packages (1.18.1)
    WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
    Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
    To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
    Collecting sympy
      Downloading sympy-1.5.1-py2.py3-none-any.whl (5.6 MB)
    [K     |████████████████████████████████| 5.6 MB 3.5 MB/s eta 0:00:01     |██████████▌                     | 1.8 MB 3.5 MB/s eta 0:00:02
    [?25hCollecting mpmath>=0.19
      Downloading mpmath-1.1.0.tar.gz (512 kB)
    [K     |████████████████████████████████| 512 kB 40.4 MB/s eta 0:00:01
    [?25hBuilding wheels for collected packages: mpmath
      Building wheel for mpmath (setup.py) ... [?25ldone
    [?25h  Created wheel for mpmath: filename=mpmath-1.1.0-py3-none-any.whl size=532238 sha256=ca029f4987204b2da4e00e4e5272410660a8319bde9c9dd77930cffb6f831f62
      Stored in directory: /home/jovyan/.cache/pip/wheels/e2/46/78/e78f76c356bca9277368f1f97a31b37a8cb937176d9511af31
    Successfully built mpmath
    Installing collected packages: mpmath, sympy
    Successfully installed mpmath-1.1.0 sympy-1.5.1



```python
import matplotlib.pyplot as plt
import numpy as np

```


```python
from sympy import *
init_printing(use_latex='mathjax')
from IPython.display import HTML, Math
display(HTML(""))
Math(r"e^\alpha")

```








$\displaystyle e^\alpha$




```python
a=[]
b=[]

for x in range(-50, 50,1):
  y=x**2
  a.append(x)
  b.append(y)
```


```python
fig = plt.figure()
axes= fig.add_subplot(111)
axes.plot(a,b)
plt.show()

```

Plot derivative of x**2

f(x) = 2x


```python
a=[]
b=[]

for x in range(-50, 50,1):
  y=2*x
  a.append(x)
  b.append(y)
```


```python
fig = plt.figure()
axes= fig.add_subplot(111)
axes.plot(a,b)
plt.show()
```

Plot tangent lines for x**2

We'll need the slope 2*x

Then we need a point on the parabola
x = 10



```python
a=[]
b=[]

def func(x):
  return x**2

def slope(x):
  return 2*x

#define the tangent line
def line(x, x1, y1):
  return slope(x1)*(x-x1)+y1

x1 = -30
y1 =  func(x1)



```


```python
# https://stackoverflow.com/questions/54961306/how-to-plot-the-slope-tangent-line-of-parabola-at-any-point
```


```python
# Define x data range for parabola
xa = np.linspace(-50,50,101)
#xa = np.linspace(-5,5,11)

yb = slope(xa)

#print(xa)
#print(yb)

print("x={},y={}".format(x1,y1))

```

    x=-30,y=900



```python

# Plot the figure
plt.figure()
plt.plot(xa, func(xa))
plt.scatter(x1, y1, color='C1', s=50)
plt.plot(xa, line(xa, x1, y1), 'C1--', linewidth = 2)

```

Test the sympy options and graph with matplotlib


```python
# start testing sympy
x, y, z = symbols('x y z')


def f(x):
  return x**3

figure = diff(x**3,x)
print(figure)
display(figure)


```

    3*x**2



$\displaystyle 3 x^{2}$



```python

```

c1e1eb7bc7c9cb16fadc7cc1dc181e1b5bddd482
ipynb
Jupyter Notebook
Calculus_Self_Guided.ipynb
ricklon/jupytercalculus
2c8a4d6b94881eedfe3d3ed54bdebfb5847ba611
Apache-2.0
Calculus_Self_Guided.ipynb
ricklon/jupytercalculus
2c8a4d6b94881eedfe3d3ed54bdebfb5847ba611
Apache-2.0
Calculus_Self_Guided.ipynb
ricklon/jupytercalculus
2c8a4d6b94881eedfe3d3ed54bdebfb5847ba611
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES