# Using Python for maths

## Introduction

This notebook lists examples of simple Python commands and programs that can be used to help with the understanding of maths, essentially at A level.

I will introduce simpler GCSE level materials later. the new A-Level syllabus. 

This is a Jupyter notebook created from within the Anaconda data science platform. Anaconda can be downloaded here:
https://www.anaconda.com

Python is an open-source programming language used extensively around the world. You can use almost for anything: game, scripts to automate repetititve task, mapping, statistical analysis, machine learning, scientific computation, ...
https://www.python.org/about/gettingstarted/

To execute commands in Jupyter, either Run the cell or hit SHIFT + ENTER.

The notation should self-explanatory: x**2 is $x^2$.
To write nice mathematical equation, I use LaTex and the text is written in a Markdown language similar to HTML, the language use to write web pages, but you do not have to worry about that for now.

This idea is that if you want to solve a problem you <br>
> 1) Insert a new cell <br>
2) Copy the cell that solve a problem similar to yours <br>
3) Hit SHIFT + ENTER <br>


If you spot any mistakes, please feel free to correct. 


## 1. Surds and Indices

1) Simplify $(2 + 2 \sqrt{2})(-\sqrt{2} + 4)$ <br>
2) Simplify $\frac{6}{5 \sqrt{2}}$ <br>
3) Simplify $(2-3 \sqrt{5})^{10}$


```python
# Load functions from the SYMbolic PYthon module.
from sympy import sqrt, simplify            
simplify((2 + 2 * sqrt(2))*(-sqrt(2) + 4))
```


```python
simplify(6 / (5 * sqrt(2)))
```


```python
simplify((2 - 3 * sqrt(5))**10)
```

Find, to 3 significant figures, the value of  $x$ for which $8^x=0.8$


```python
from sympy import Symbol, solve
x = Symbol('x')
sol = solve(8**x - 0.8, x)
# Zero-based indexing in Python: sol[0] is the first solution.
# The other two roots are complex.
# Format the solution.
print('The real solution is {:0.3g},'.format(sol[0]), 'to 3 sig. figs.')  
```

## 2. Quadratic Functions

(i) Determine the roots of the equation: $x^2+3x-5=0$  <br>

(ii) Plot the quadratic function: $y=x^2+3x-54$ <br>


```python
from sympy import solve, Symbol
x = Symbol('x')
solve(x**2 + 3 * x - 5, x)
```


```python
# Use the alias np instead of numpy (NUMerical PYthon).
# Use the alias plt for matplotlib.pyplot.
import numpy as np                  
import matplotlib.pyplot as plt  
%matplotlib inline
# x ranges from -8 to 5 in 100 intervals.
x = np.linspace(-8, 5, 100)         
plt.plot(x, x**2 + 3 * x - 5)
plt.xlabel('x')
plt.ylabel('y')
# Show the plot.
plt.show()    
```

## Print dependences
This is required to record the computational environment in order to share the results online and for reproducibility.


```python
%load_ext watermark

# python, ipython, packages, and machine characteristics
%watermark -v -m -p simpy,matplotlib,pandas,numpy,watermark 

# date
print (" ")
%watermark -u -n -t -z 
```


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

# evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)

# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()
```


```python
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()
```


```python

```

46e5d09d510fd39cb76082c131b8458bd0637a67
ipynb
Jupyter Notebook
Maths_intro.ipynb
alex-cuenat/Math_GCSE
8a9d0741726e1a4e78c1dcaf757286046d97c8a2
MIT
Maths_intro.ipynb
alex-cuenat/Math_GCSE
8a9d0741726e1a4e78c1dcaf757286046d97c8a2
MIT
Maths_intro.ipynb
alex-cuenat/Math_GCSE
8a9d0741726e1a4e78c1dcaf757286046d97c8a2
MIT
Qwen/Qwen-72B
1. YES
2. YES