0
0

Pythonでわかる高校化学の式

Last updated at Posted at 2024-04-13

import math

def body_centered_cubic_fill_rate(l):
    volume_sphere = (4/3) * math.pi * ((math.sqrt(3) * l) / 4)**3
    total_volume = l**3
    fill_rate = (volume_sphere * 2) / total_volume
    return fill_rate

def face_centered_cubic_fill_rate(l):
    volume_sphere = (4/3) * math.pi * ((math.sqrt(2) * l) / 4)**3
    total_volume = l**3
    fill_rate = (volume_sphere * 4) / total_volume
    return fill_rate

# 既知の辺の長さ
l_bcc = 5  # 体心立方格子の場合の辺の長さ
l_fcc = 5  # 面心立方格子の場合の辺の長さ

# 体心立方格子の充填率を計算
bcc_fill_rate = body_centered_cubic_fill_rate(l_bcc)
print("体心立方格子の充填率:", bcc_fill_rate)

# 面心立方格子の充填率を計算
fcc_fill_rate = face_centered_cubic_fill_rate(l_fcc)
print("面心立方格子の充填率:", fcc_fill_rate)

image.png

import numpy as np
import matplotlib.pyplot as plt

# 水素イオン濃度の範囲を定義(例:10^-14から10^0)
h_concentration = np.logspace(-14, 0, 1000)

# pHを計算
pH = -np.log10(h_concentration)

# プロット
plt.figure(figsize=(8, 6))
plt.plot(h_concentration, pH, color='blue')
plt.xscale('log')  # x軸を対数スケールに設定
plt.xlabel('Hydrogen Ion Concentration [H+] (mol/L)')
plt.ylabel('pH')
plt.title('pH vs Hydrogen Ion Concentration')
plt.grid(True)
plt.show()

image.png

import numpy as np
import matplotlib.pyplot as plt

# ボイルの法則の関数
def boyles_law(P, V_const):
    return V_const / P

# シャルルの法則の関数
def charles_law(T, V_const):
    return V_const / (273 + T)

# ボイルの法則のパラメータ
V_const_boyle = 1.0  # 一定の体積

# シャルルの法則のパラメータ
V_const_charles = 1.0  # 一定の体積

# プロットの範囲設定
pressure_range = np.linspace(0.1, 10, 100)  # 圧力の範囲
temperature_range = np.linspace(0, 100, 100)  # 温度の範囲

# プロット
plt.figure(figsize=(12, 6))

# ボイルの法則のプロット
plt.subplot(1, 2, 1)
plt.plot(pressure_range, boyles_law(pressure_range, V_const_boyle), label='Boyle\'s Law')
plt.xlabel('Pressure (P)')
plt.ylabel('Volume (V)')
plt.title('Boyle\'s Law')
plt.legend()

# シャルルの法則のプロット
plt.subplot(1, 2, 2)
plt.plot(temperature_range, charles_law(temperature_range, V_const_charles), label='Charles\' Law')
plt.xlabel('Temperature (T)')
plt.ylabel('Volume (V)')
plt.title('Charles\' Law')
plt.legend()

plt.tight_layout()
plt.show()

image.png




import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 与えられた値
n = 1.0  # モル数
R = 0.0821  # 気体定数 (L atm / K mol)

# 圧力、体積の範囲を設定
P_min = 1.0  # 最小圧力 (atm)
P_max = 10.0  # 最大圧力 (atm)
V_min = 1.0  # 最小体積 (L)
V_max = 10.0  # 最大体積 (L)

# 各パラメータの値を生成
P_values = np.linspace(P_min, P_max, 10)  # 圧力の値
V_values = np.linspace(V_min, V_max, 10)  # 体積の値

# 二次元グリッドの作成
P, V = np.meshgrid(P_values, V_values, indexing='ij')

# Tを計算
T = P * V / (n * R)

# 三次元プロットの作成
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# プロット
ax.plot_surface(P, V, T, rstride=1, cstride=1, cmap='viridis', edgecolor='none')

# 軸ラベルの設定
ax.set_xlabel('Pressure (atm)')
ax.set_ylabel('Volume (L)')
ax.set_zlabel('Temperature (K)')

# グラフのタイトルの設定
plt.title('P × V / T = nR')

# 表示
plt.show()

image.png

import numpy as np
import matplotlib.pyplot as plt

# アレニウスの式の関数
def arrhenius_eq(A, E, R, T):
    return A * np.exp(-E / (R * T))

# 平衡定数と温度の関係の関数
def equilibrium_eq(a, b, T):
    return a - b / T

# 定数の設定
R = 8.314  # 気体定数
A = 1e13   # 頻度因子
E = 50000  # 活性化エネルギー
a = 10     # 平衡定数の定数
b = 5000   # 平衡定数の定数

# 温度の範囲設定
T_range = np.linspace(200, 1000, 100)

# アレニウスプロットの作成
plt.figure(figsize=(10, 5))

# アレニウスプロット
plt.subplot(1, 2, 1)
k_values = arrhenius_eq(A, E, R, T_range)
plt.plot(1 / T_range, np.log(k_values), marker='o')
plt.xlabel('1/T (K^-1)')
plt.ylabel('ln(k)')
plt.title('Arrhenius Plot')
plt.grid(True)

# 平衡定数と温度の関係のプロット
plt.subplot(1, 2, 2)
K_values = equilibrium_eq(a, b, T_range)
plt.plot(T_range, K_values, marker='o')
plt.xlabel('Temperature (K)')
plt.ylabel('log(K)')
plt.title('Equilibrium Constant vs Temperature')
plt.grid(True)

plt.tight_layout()
plt.show()

image.png

1次反応速度式

import numpy as np
import matplotlib.pyplot as plt

# 反応速度定数 k
k = 0.1

# 初期濃度 [A]_0
A_0 = 1.0

# 時間の範囲を設定
t = np.linspace(0, 10, 100)

# 濃度 [A](t) を計算
A_t = A_0 * np.exp(-k * t)

# グラフをプロット
plt.plot(t, A_t, label='[A](t)')
plt.xlabel('Time')
plt.ylabel('Concentration of A')
plt.title('Concentration of A vs Time')
plt.legend()
plt.grid(True)
plt.show()

image.png

import numpy as np
import matplotlib.pyplot as plt

# 2次反応の速度定数
k = 0.1  # 任意の値を設定

# 初期濃度
A0 = 1.0  # 任意の値を設定

# 時間の配列を生成
t = np.linspace(0, 10, 100)  # 0から10までの時間を100等分した配列

# 濃度の計算
A = A0 / (1 + k * A0 * t)

# プロット
plt.plot(t, A)
plt.xlabel('Time')
plt.ylabel('Concentration [A]')
plt.title('Second Order Reaction')
plt.show()

image.png

import numpy as np
import matplotlib.pyplot as plt

# グラフ描画の範囲を設定
x = np.linspace(-10, 10, 400)

# 各関数の定義
y1 = 1 / (1 + x)
y2 = 1 / (1 - x)
y3 = 1 / np.sqrt(1 + x)
y4 = np.sin(x)
y5 = np.cos(x)
y6 = np.log(1 + x)

# グラフの描画
plt.figure(figsize=(12, 8))

plt.subplot(3, 2, 1)
plt.plot(x, y1, label='1/(1+x)')
plt.plot(x, y2, label='1/(1-x)')
plt.legend()

plt.subplot(3, 2, 2)
plt.plot(x, y3, label='1/√(1+x)')
plt.plot(x, 1 - x/2, label='1-x/2')
plt.legend()

plt.subplot(3, 2, 3)
plt.plot(x, y4, label='sin(x)')
plt.plot(x, x, label='x')
plt.legend()

plt.subplot(3, 2, 4)
plt.plot(x, y5, label='cos(x)')
plt.plot(x, np.ones_like(x), label='1')
plt.legend()

plt.subplot(3, 2, 5)
plt.plot(x, y6, label='log(1+x)')
plt.plot(x, x, label='x')
plt.legend()

plt.show()

image.png


import numpy as np
import matplotlib.pyplot as plt

# 電離度の範囲を生成
alpha = np.linspace(0.001, 0.999, 100)

# 濃度を設定
c = 0.00001

# 式 c(α^2)/(1-α) と cα^2 の計算
y1 = c * (alpha**2) / (1 - alpha)
y2 = c * alpha**2

# プロット
plt.plot(alpha, y1, label='c(α^2)/(1-α)')
plt.plot(alpha, y2, label='cα^2')
plt.xlabel('Ionization degree (α)')
plt.ylabel('Value')
plt.title('Relationship between Ionization Degree and Concentration')
plt.legend()
plt.grid(True)
plt.show()

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0