Last active
February 23, 2022 15:26
-
-
Save codistwa/443f038e906950f833cf95aebe78cbbd to your computer and use it in GitHub Desktop.
Course source code: https://codistwa.com/guides/logarithm-function. More courses on https://codistwa.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============================================================ | |
# 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