Math
Probability
python
months = 12
months_with_m_and_j = 5
probability = (months_with_m_and_j/months) * 100
probability = float("{:.2f}".format(probability))
print(f"There is a {probability}% chance that the month will start with an M or a J")
Statistics
Making sense of data
Linear Algebra
python
scalar = 24
vector = [-2,-6,9]
matrix = [
[2,-6,9],
[4,5,-7]
]
python
import numpy as np
from numpy import arccos, dot
v = np.array([[0, 2, 0]])
w = np.array([[3, 0, 0]])
print(np.cross(v, w))
Calculus
Let's go through examples of finding the derivative and integral using Python. We'll use the sympy
library for symbolic mathematics. First, ensure you have the sympy
library installed. If not, you can install it using pip:
bash
pip install sympy
Example of Finding the Derivative
Let's find the derivative of the function ( f(x) = x^2 + 3x + 2 ).
python
from sympy import symbols, diff
# Define the variable
x = symbols('x')
# Define the function
f = x**2 + 3*x + 2
# Find the derivative
derivative_f = diff(f, x)
print(f"The derivative of f(x) is: {derivative_f}")
Example of Finding the Integral
Let's find the indefinite integral of the function ( f(x) = x^2 + 3x + 2 ).
python
from sympy import symbols, integrate
# Define the variable
x = symbols('x')
# Define the function
f = x**2 + 3*x + 2
# Find the indefinite integral
integral_f = integrate(f, x)
print(f"The indefinite integral of f(x) is: {integral_f} + C")
For a definite integral, say from ( x = 0 ) to ( x = 1 ):
python
# Find the definite integral from 0 to 1
definite_integral_f = integrate(f, (x, 0, 1))
print(f"The definite integral of f(x) from 0 to 1 is: {definite_integral_f}")
Putting It All Together
Here's a complete script that calculates both the derivative and the integral (both indefinite and definite) of the function ( f(x) = x^2 + 3*x + 2 ):
python
from sympy import symbols, diff, integrate
# Define the variable
x = symbols('x')
# Define the function
f = x**2 + 3*x + 2
# Find the derivative
derivative_f = diff(f, x)
print(f"The derivative of f(x) is: {derivative_f}")
# Find the indefinite integral
indefinite_integral_f = integrate(f, x)
print(f"The indefinite integral of f(x) is: {indefinite_integral_f} + C")
# Find the definite integral from 0 to 1
definite_integral_f = integrate(f, (x, 0, 1))
print(f"The definite integral of f(x) from 0 to 1 is: {definite_integral_f}")
Running this script will give you the derivative, indefinite integral, and definite integral of the given function.