```python
# Solving an expression in python

my_value = 2 * (3 + 2)**2 / 5 - 4

print(my_value) 
```

    6.0



```python
# making use of parenthesis for clarity in python

my_value = 2 * ((3 + 2)**2 / 5) - 4

print(my_value) # prints 6.0
```

    6.0



```python
# Functions are expressions that define relationships between two or more variables.
# More specifically, a function takes input variables (also called domain variables or independent variables),
# plugs them into an expression, and then results in an output variable (also called dependent variable).

def f(x):
    return 2 * x + 1


x_values = [0, 1, 2, 3]

for x in x_values:
    y = f(x)
    print(y)
    
```

    1
    3
    5
    7



```python
# Charting a linear function in  python using Sympy (Sympy comes auto bundled in Anaconda)
from matplotlib import *
from sympy import *

x = symbols('x')
f = 2*x + 1
plot(f)
```


```python
x = symbols('x')
f = x**2 + 1
plot(f)
```


```python
from sympy.plotting import plot3d

x, y = symbols('x y')
f = 2*x + 3*y
plot3d(f)
```


```python
# A summation is expressed as a sigma  and adds elements together.
# Summation in python

summation = sum(2*i for i in range(1,6))
print(summation)
```

    30



```python
# Exponents multiplies a number by itself a specified number of times
# .The base is the variable or value we are exponentiating,
# and the exponent is the number of times we multiply the base value.
# using sympy to print exponent expression

x = symbols('x')
expr = x**2 / x**5
print(expr) # x**(-3)
```

    x**(-3)



```python
# A logarithm is a math function that finds a power for a specific number and base.
# Using the log function in python

from math import log

# 2 raised to what power gives me 8?
x = log(8, 2)

print(x) 
```

    3.0



```python
# There is a special number that shows up quite a bit in math called Euler’s number e.
# It is a special number much like Pi π, and is approximately 2.71828.
# e is used a lot because it mathematically simplifies a lot of problems.

# Calculating continuous interest in python, A = P*e**rt

from math import exp

p = 100 # principal, starting amount
r = .20 # interest rate, by year
t = 2.0 # time, number of years

a = p * exp(r*t)

print(a)
```

    149.18246976412703



```python
# When we use e as our base for a logarithm, we call it a natural logarithm.

from math import log

# e raised to what power gives us 10?
x = log(10)

print(x) # prints 2.302585092994046
```

    2.302585092994046



```python
# A derivative tells the slope of a function, and it is useful to measure the rate of change at any point in a function.
# derivative calculator in python

def derivative_x(f, x, step_size):
    m = (f(x + step_size) - f(x)) / ((x + step_size) - x)
    return m


def my_function(x):
    return x**2

slope_at_2 = derivative_x(my_function, 2, .00001)

print(slope_at_2)
```

    4.000010000000827



```python
# Calculating a derivative in Sympy

# Declare 'x' to SymPy
x = symbols('x')

# Now just use Python syntax to declare function
f = x**2

# Calculate the derivative of the function
dx_f = diff(f)
print(dx_f) # prints 2*x
```

    2*x



```python
# Calculating partial derivative with Sympy

# Declare x and y to SymPy
x,y = symbols('x y')

# Now just use Python syntax to declare function
f = 2*x**3 + 3*y**3

# Calculate the partial derivatives for x and y
dx_f = diff(f, x)
dy_f = diff(f, y)

print(dx_f) # prints 6*x**2
print(dy_f) # prints 9*y**2

# plot the function
plot3d(f)
```


```python
#  integral, which finds the area under the curve for a given range.
# Integral approximation in python

def approximate_integral(a, b, n, f):
    delta_x = (b - a) / n
    total_sum = 0

    for i in range(1, n + 1):
        midpoint = 0.5 * (2 * a + delta_x * (2 * i - 1))
        total_sum += f(midpoint)

    return total_sum * delta_x

def my_function(x):
    return x**2 + 1

area = approximate_integral(a=0, b=1, n=5, f=my_function)

print(area)
```

    1.33



```python

```

111f5b4fbf81c793831764f11a1746a655eb1019
ipynb
Jupyter Notebook
Maths/Basic Maths and Calculus Review/Basic Maths and Calculus Review.ipynb
rishi9504/Data-Science
10344bf641c601bf16451ddd9eaa28ab4c0fc75b
MIT
Maths/Basic Maths and Calculus Review/Basic Maths and Calculus Review.ipynb
rishi9504/Data-Science
10344bf641c601bf16451ddd9eaa28ab4c0fc75b
MIT
Maths/Basic Maths and Calculus Review/Basic Maths and Calculus Review.ipynb
rishi9504/Data-Science
10344bf641c601bf16451ddd9eaa28ab4c0fc75b
MIT
Qwen/Qwen-72B
1. YES
2. YES