Graphing
1) 2D plots
a) 2D normal plot
In[1]: figure(1) # first figure
plt2('x**2'); #plot one
plt2('x**3+5'); # plot two
title('Fig 1') # title
# Addinge a legend
lgd2('{x}^2', '{x}^3+5') # lgd2 means 2 input legend
# specefic range
range2(-10, 10) # x and y values if only x use xlim([p, q])
b) 2D scatter plot
In[2]: point2([5, 3, 4], [7, 8, 9]) # multiple points
range2(-2, 10) # range
axis2d # adding x and y axis
c) 2D parametric plot
In[3]: param2("cos(t)*t", "t*sin(t)")
d) 2D vector plot
In[4]: # defining the grid
[x, y] = grid2(-5, 5, 0.5); # uses ndgrid
# the plot
u1 = y .^ 3-9 .* y;
v1 = x .^ 3-9 .* x;
vector2(u1, v1, -5, 5, 0.5); # 0.5 is intensity lower more intense
axis2d # axis
e) Implicit plot
In[5]: plt2("x^2+y^2-5")
2) 3D plots
a) Normal 3D plots
In[6]: plt3('x**2+y**2')
range3(-5, 40) # 3D range
b) 3D scatter plot
In[7]: point3([-5, 2, 3], [1, 4, 10], [5, -2, 8]) #[x], [y], [z]
range3(-10, 10)
axis3d # 3d axis
c) 3D parametric
i) variables with t and s
In[8]: param3("3*cos(t) + cos(t)*cos(s)", "3*sin(t) + sin(t)*cos(s)", "sin(s)")
ii) t variable
In[9]: ezplot3("6+t", "5+4*t", "1-2*t")
d) 3D vector
In[10]: # the grid
[x, y, z] = grid3(-5, 5, 2);
# the plot
u1 = y;
v1 = 0;
w1 = 0;
vector3(u1, v1, w1, -5, 5, 2)
e) 3D implicit
In[11]: # the grid
[x, y, z] = grid3(-5, 5, 1);
# the plot
iso3(x.^2+y.^2-z.^2, -5, 5, 1)
Algebra
1) General
a) Initials
In[1]: x, u, z, y, a, b = symbols('x u z y a b')
b) General syntax
In[2]: # Defining an equation
i = Eq(x**2, 1) # x^2 = 1
# subsiting a value
s = x**2
s.subs(s, 2)
2) Simplification
a) Normal simplification
In[3]: simplify((x**3 + x**2 - x - 1)/(x**2 + 2*x + 1))
b) Expansion
In[4]: expand((x + 1)**3) # works for binomial expansion
c) Factorisation
In[5]: factor(x**3 - x**2 + x - 1)
d) Collecting like terms
In[6]: collect(x**2+z*x**2-7*x+u*x, x)
e) Rational fractions to polynomials in form
In[7]: cancel((x**2 + 2*x + 1)/(x**2 + x))
f) Partial fraction
In[8]: apart((4*x-3)/((3*x+4)*(7*x)))
e) Trigonometry
i) Trigonometric simplification
In[9]: trigsimp(sin(x)*tan(x)/sec(x))
ii) Trigonometric expansion
In[10]: expand_trig(sin(x + y))
f) Power
i) Power simplification
In[11]: powsimp(x**a*x**b)
ii) Power expansion
In[12]: # expression expansion
expand_power_exp(x**(a + b))
In[13]: # same power expansion
expand_power_base((x*y)**a, force=True)
In[14]: # power to power expansion
powdenest((x**y)**a, force=True)
e) Logarithms
i) Log expansion
In[15]: expand_log(log(z**2), force=True)
ii) Log combination
In[16]: logsimp(a*log(x))
f) Taylor series
In[17]: series(sin(x))
3) Special functions
a) Factorial
In[18]: factorial(x)
b) Combination
In[19]: binomial(x, y)
4) Equations
a) Normal
i) Simple
In[20]: # Defining the equation x^2=1
j = Eq(x**2, 1)
# solving
solveset(j, x) # or solve()
ii) Complex
In[21]: # the function
z = lambda x: np.sin(x) - x**2+1
# solution
fsolve(z, 1) # 1 is the initial guess
b) Simultaneous equations
i) Linear
In[22]: linsolve([x+y, 2*x], (x, y))
ii) Non-linear
In[23]: nonlinsolve([exp(x)-sin(y), 1/y-3], [x, y])
c) Inequalities
i) Normal inequalities
In[24]: reduce_rational_inequalities([[x**2 -4 <= 0]], x)
ii) Polynomial inequalities
In[25]: solve_poly_inequalities(((
Poly(x**2 - 3), ">"), (
Poly(-x**2 + 1), ">")))
iii) Inequalities with absolute value
In[26]: reduce_abs_inequality(Abs(x - 5) - 3, '<', x)
5) Sequences
a) Sequence formula
In[26]: seq(2*x+3, 17) # where 17 is the term
b) Summation
summation(x**2, (x, 1, 7)) # from 1 to 7
Calculus
1) Initials
In[1]: # symbols
x, y, t = symbols('x y t')
# functions
f, g = symbols('f g', cls=Function)
2) Integration
a) Numerical integration
In[2]: integ(x**2, 2, 7)
b) Symbolic integration
In[3]: integrate(x**2, x)
c) Volume of rotation
In[4]: vol(x**2, 2, 4)
3) Derivatives
a) Numerical derivative
In[5]: c = diff(x**2, x, 1) # 1st derivative
c.subs(x, 2) # f'(2)
b) Symbolic derivative
In[6]: diff(x**3, x, 2) # 2nd derivative
c) Partial derivative
i) With respect to x
In[7]: diff(x**2+y**2, x)
ii) With respect to y
In[8]: diff(x**2+y**2, y)
iii) With respect to x and y (2nd partial)
In[9]: diff(diff(sin(x)*y**2, x), y)
d) Implicit
In[10]: impl(sin(y)+x*y-100*x)
e) Parametric
i) 1st derivative
In[11]: idif1(t**2, t**3)
ii) 2nd derivative
In[12]: idif2(t**2, t**3)
e) stationary points
In[13]: station(sin(x))
1st is max and 2nd is min
4) Differential
a) 1st order
In[14]: # Equation
eq = Eq(f(x).diff(x) - 4 * f(x), 0)
print(latex(eq)) # displying the equation
# solution
dsolve(eq, f(x))
b) 2nd order
In[15]: # Equation
eq = Eq(f(x).diff(x, 2) - 4 * f(x), 0)
pprint(eq)) # displying the equation
# solution
dsolve(eq, f(x))
5) Limits
In[16]: limit(1/x, x, 0, '-') # limit to 0 from -ve side
Complex numbers
1) Simplification
a) General
In[1]: complex((4 + 5*i)**2)
b) Imaginary and real part
In[2]: # imaginary
im(3+5*i)
# real
re(3+5*i)
c) Cartesian to polar form
In[3]: z, theta = pol(3+4*i)
d) Polar to Cartesian
In[4]: rect(5, 0.9272952180016122)
e) Conjugate
In[4]: conjugate(2+3*i)