Skip to content

Instantly share code, notes, and snippets.

@codistwa
Last active February 23, 2022 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codistwa/443f038e906950f833cf95aebe78cbbd to your computer and use it in GitHub Desktop.
Save codistwa/443f038e906950f833cf95aebe78cbbd to your computer and use it in GitHub Desktop.
# ============================================================
# The 3 types of logarithms
# ============================================================
x = np.linspace(-3,3,100)
ln = np.log(x)
decimal = np.log10(x)
binary = np.log2(x)
plt.plot(x, ln, label='$natural$')
plt.plot(x, decimal, label='$decimal$')
plt.plot(x, binary, label='$binary$')
plt.title('Logarithms',fontsize=12)
plt.savefig('logarithms.png', bbox_inches='tight')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.legend()
plt.show()
# ============================================================
# Logarithm of a product
# ============================================================
a = 3
b = 4
log1 = np.log(a*b) # 2.48491
log2 = np.log(a) + np.log(b) # 2.48491
# ============================================================
# Logarithm of a quotient
# ============================================================
a = 3
b = 4
log1 = np.log(a / b) # −0.287682
log2 = res3 = np.log(a) - np.log(b) # −0.287682
# ============================================================
# Logarithm of a power
# ============================================================
a = 3
log1 = np.log(a ** 3)
log2 = 3 * np.log(a)
print(log1) # 3.295836866004329
print(log2) # 3.295836866004329
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment