前言
此课程由化学与材料科学学院负责,面向生态环境系环工、环科本科生。
教学地点:五四路校区化学楼402实验室。
主要教材:《基础化学实验4——物性参数与测定》 马志广、庞秀言主编 化学工业出版社 2016年
下载 百度网盘 ,包含大纲、教案&预做实验、绘图代码、电导率仪手册、学生实验报告等。
电导法测定弱电解质的电离平衡常数
实验思路
数据处理
表2 电导率测定结果
κ(HAc)=κ(溶液)-κ(水)
κ(水)一般小于10 µS·cm-1,即10*10-4 S·m-1
求解1/Λm(HAc)时,考虑Λm=κ/c。
求解cΛm(HAc)/c⊖时,考虑c⊖=1000 mol/m3。
Origin作图
step1
step2
step3
step4
Origin出图显示demo是因为破解不完全所致。
x轴、y轴单位别遗漏,此实验的图都有这个bug。
Python作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# -*-coding:utf-8 -*-
import os
import numpy as np
import matplotlib.pyplot as plt
os . chdir ( os . path . split ( os . path . realpath ( __file__ ))[ 0 ])
# 数据
data = [
[ 9.676E-6 , 415.87433 ],
[ 1.497E-5 , 672.01069 ],
[ 2.05E-5 , 981.46341 ],
[ 2.48E-5 , 1216.93548 ],
[ 2.85E-5 , 1410.87719 ],
[ 3.42E-5 , 1470.76023 ]
]
x , y = zip ( * data )
# 拟合数据
coefs = np . polyfit ( x , y , 1 )
fit_func = np . poly1d ( coefs )
# 绘图
plt . scatter ( x , y , color = 'tab:blue' , label = 'Data Points' )
plt . plot ( x , fit_func ( x ), color = 'tab:red' , label = f 'Fit: y = {coefs[0]:.4f}x + {coefs[1]:.4f}' )
plt . xlabel ( r '$c \times \frac{\Lambda_m}{c^{\ominus}}$' )
plt . ylabel ( r '$\frac{1}{\Lambda_m}$' )
plt . legend ()
plt . grid ( True )
# 保存到本地
plt . tight_layout ()
plt . savefig ( "result.jpg" , dpi = 300 )
plt . show ()
Matlab作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
% 数据
data = [
9.676E-6 , 415.87433 ;
1.497E-5 , 672.01069 ;
2.05E-5 , 981.46341 ;
2.48E-5 , 1216.93548 ;
2.85E-5 , 1410.87719 ;
3.42E-5 , 1470.76023
];
x = data (:, 1 );
y = data (:, 2 );
% 拟合数据
fit_result = polyfit ( x , y , 1 );
fit_x = linspace ( min ( x ), max ( x ), 100 ); % 为拟合线生成x值
fit_y = polyval ( fit_result , fit_x );
% 绘图
figure ;
scatter ( x , y , 'b' , 'DisplayName' , 'Data Points' );
hold on ;
plot ( fit_x , fit_y , 'r' , 'DisplayName' , sprintf ( 'Fit: y = %.4fx + %.4f' , fit_result ( 1 ), fit_result ( 2 )));
xlabel ( 'c \times \Lambda_m / c^\o' );
ylabel ( '1/\Lambda_m' );
legend ();
grid on ;
% 保存到本地
filename = 'C:\Users\lenovo\Desktop\result.jpg' ;
print ( gcf , '-djpeg' , sprintf ( '-r%d' , 300 ), filename );
Mathematica作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(* 数据 *)
data = {
{ 9.676 * 10 ^ -6 , 415.87433 },
{ 1.497 * 10 ^ -5 , 672.01069 },
{ 2.05 * 10 ^ -5 , 981.46341 },
{ 2.48 * 10 ^ -5 , 1216.93548 },
{ 2.85 * 10 ^ -5 , 1410.87719 },
{ 3.42 * 10 ^ -5 , 1470.76023 }
};
(* 拟合数据 *)
fit = Fit [ data , { 1 , x }, x ];
coeffs = CoefficientList [ fit , x ];
(* 格式化拟合方程文本 *)
fitText = "Fit: y = " <> ToString [ N [ coeffs [[ 2 ]]]] <> " x + " <> ToString [ N [ coeffs [[ 1 ]]]];
(* 绘图 *)
plot1 = ListPlot [ data , PlotStyle -> { Blue , PointSize [ 0.015 ]}];
plot2 = Plot [ fit , { x , 9.676 * 10 ^ -6 , 3.42 * 10 ^ -5 }, PlotStyle -> Red ];
combinedPlot = Show [ plot1 , plot2 ,
AxesLabel -> {
"c \[Times] \[CapitalLambda]\!\(\*SubscriptBox[\(m\), \(\(c\)\(^\)\(\[CircleMinus]\)\)]\)" ,
"1/\[CapitalLambda]\!\(\*SubscriptBox[\(m\), \(\(c\)\(^\)\(\[CircleMinus]\)\)]\)"
},
GridLines -> Automatic ,
Epilog -> Text [ fitText , { 2.5 * 10 ^ -5 , 900 }]
];
(* 保存到指定的路径 *)
Export [ "C:\\Users\\lenovo\\Desktop\\result.jpg" , combinedPlot , ImageResolution -> 300 ];
图上的拟合公式显示有些错位。
Julia作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Printf
using Plots
using LsqFit
using LaTeXStrings
# 数据
data = [
9.676E-6 415.87433 ;
1.497E-5 672.01069 ;
2.05E-5 981.46341 ;
2.48E-5 1216.93548 ;
2.85E-5 1410.87719 ;
3.42E-5 1470.76023
]
x = data [ : , 1 ]
y = data [ : , 2 ]
# 定义拟合模型
@ . model ( x , p ) = p [ 1 ] * x + p [ 2 ]
# 初始参数猜测
p0 = [ 1.0 , 1.0 ]
# 使用最小二乘法拟合数据
fit = curve_fit ( model , x , y , p0 )
# 获取拟合参数
coefs = fit . param
# 格式化拟合参数为字符串
coefs_str = string ( @sprintf ( " %.4f " , coefs [ 1 ]), "x + " , @sprintf ( " %.4f " , coefs [ 2 ]))
# 绘图
scatter ( x , y , color =: blue , label = "Data Points" , grid = true )
plot! ( x , model ( x , coefs ), color =: red , label = "Fit: y = $coefs_str " , grid = true )
xlabel! ( L "c \t imes \f rac{\Lambda_m}{c^{\ominus}}" )
ylabel! ( L " \f rac{1}{\Lambda_m}" )
# 保存到本地
savefig ( "C: \\ Users \\ lenovo \\ Desktop \\ result.png" )
# 显示图形
display ( current ())
using Plots下使用savefig保存的图有些小,可换其他绘图库。
蔗糖转化反应速率常数的测定
实验思路
蔗糖水解反应是一级反应,其反应速率常数与浓度有关;而浓度的实时测量需要与之成正比的旋光度α进行替换。
旋光度α的测量需要旋光仪。根据P51 式(7),需要测得一系列不同t时刻下的α和反应完全的α∞,代入式(7)作图,由斜率可得反应速率常数k。
根据上一步的k,再加上一级反应的特点(见P50 式(2))可知半衰期。
对于简单级数反应的半衰期:
零级反应的半衰期与反应的起始浓度成正比
一级反应的半衰期与反应的起始浓度无关
二级反应的半衰期与反应的起始浓度成反比
数据处理
根据P52 2. 作α-t图和4. 作ln[(α-α∞)/°]-t作图,因此,实验报告是两个图,不要遗漏!
4.作ln[(α-α∞)/°]-t作图时,用y = kx + b线性方程拟合。
蔗糖水解反应是一级反应,速率常数k的单位是min-1。
半衰期是min。
实验报告上这两个单位不要遗漏!
Origin作图
虚线不是必须,只是方便显示在19~20 min,旋光度由正变负。
2. 作α-t图
4. 作ln[(α-α∞)/°]-t
Python作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import matplotlib.pyplot as plt
# 数据
data = """
2.28 9.684
4.07 9.411
6.68 6.816
8.82 4.47
10.82 3.202
12.82 2.31
14.82 1.486
17.08 0.686
19.06 0.1
22.05 -0.638
25.06 -1.24
28.03 -1.713
31.1 -2.099
34.05 -2.411
37.05 -2.662
40.2 -2.864
45.03 -3.107
50.05 -3.278
55.02 -3.391
"""
# 解析数据
lines = data . strip () . split ( " \n " )
x , y = zip ( * [ map ( float , line . split ()) for line in lines ])
# 绘图
plt . plot ( x , y , color = 'tab:red' , label = 'Line through Data Points' )
plt . scatter ( x , y , color = 'tab:blue' , label = 'Data Points' )
plt . xlabel ( 't/min' )
plt . ylabel ( r '$\alpha$' + '/°' )
plt . legend ()
plt . grid ( True )
# 保存为300dpi的图像
plt . tight_layout ()
plt . savefig ( "C: \\ Users \\ lenovo \\ Desktop \\ pic1.jpg" , dpi = 300 )
# 显示图形
plt . show ()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
import matplotlib.pyplot as plt
import os
os . chdir ( os . path . split ( os . path . realpath ( __file__ ))[ 0 ])
# 数据
data = """
2.28 2.57322
4.07 2.55218
6.68 2.3263
8.82 2.0661
10.82 1.891
12.82 1.74641
14.82 1.59127
17.08 1.41342
19.06 1.2596
22.05 1.02461
25.06 0.78116
28.03 0.53708
31.1 0.28141
34.05 0.01292
37.05 -0.27181
40.2 -0.57982
"""
# 解析数据
lines = data . strip () . split ( " \n " )
x , y = zip ( * [ map ( float , line . split ()) for line in lines ])
# 使用numpy进行线性拟合
coefs = np . polyfit ( x , y , 1 )
fit_func = np . poly1d ( coefs )
# 绘图
plt . scatter ( x , y , color = 'tab:blue' , label = 'Data Points' )
plt . plot ( x , fit_func ( x ), color = 'tab:red' , label = f 'Fit: y = {coefs[0]:.4f}x + {coefs[1]:.4f}' )
plt . xlabel ( 't/min' )
plt . ylabel ( r 'ln($\alpha$-$\alpha_{\infty}$)/°' )
plt . legend ()
plt . grid ( True )
# 保存为300dpi的图像
plt . tight_layout ()
plt . savefig ( "pic2_ml.jpg" , dpi = 300 )
# 显示图形
plt . show ()
Python+Keras作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam
import os
os . chdir ( os . path . split ( os . path . realpath ( __file__ ))[ 0 ])
# 数据
data = """
2.28 2.57322
4.07 2.55218
6.68 2.3263
8.82 2.0661
10.82 1.891
12.82 1.74641
14.82 1.59127
17.08 1.41342
19.06 1.2596
22.05 1.02461
25.06 0.78116
28.03 0.53708
31.1 0.28141
34.05 0.01292
37.05 -0.27181
40.2 -0.57982
"""
# 解析数据
lines = data . strip () . split ( " \n " )
x , y = zip ( * [ map ( float , line . split ()) for line in lines ])
# 转换数据为Keras所需的numpy数组形式
x = np . array ( x )
y = np . array ( y )
x = x . reshape ( - 1 , 1 ) # 重塑x为2D数组以匹配Keras输入需求
# 建立模型
model = Sequential ([
Dense ( 1 , input_shape = ( 1 ,), activation = 'linear' ) # 一个神经元,线性激活函数
])
model . summary () # 查看模型结构
# 编译模型
model . compile ( optimizer = Adam ( learning_rate = 0.1 ), loss = 'mse' )
# 训练模型
history = model . fit ( x , y , epochs = 1000 , verbose = 0 ) # 训练过程不显示
# 获取模型权重(斜率)和偏置(截距)
weights = model . get_weights ()
slope = weights [ 0 ][ 0 , 0 ]
intercept = weights [ 1 ][ 0 ]
# 使用模型进行预测
y_pred = model . predict ( x )
# 绘图
plt . scatter ( x , y , color = 'tab:blue' , label = 'Data Points' )
plt . plot ( x , y_pred , color = 'tab:red' , label = f 'Fit: y = {slope:.4f}x + {intercept:.4f}' )
plt . xlabel ( 't/min' )
plt . ylabel ( r 'ln($\alpha$-$\alpha_{\infty}$)/°' )
plt . legend ()
plt . grid ( True )
# 保存为300dpi的图像
plt . tight_layout ()
plt . savefig ( "pic2_ml.jpg" , dpi = 300 )
# 显示拟合曲线
plt . show ()
Matlab作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
% 数据
data = [
2.28 , 9.684 ;
4.07 , 9.411 ;
6.68 , 6.816 ;
8.82 , 4.47 ;
10.82 , 3.202 ;
12.82 , 2.31 ;
14.82 , 1.486 ;
17.08 , 0.686 ;
19.06 , 0.1 ;
22.05 , - 0.638 ;
25.06 , - 1.24 ;
28.03 , - 1.713 ;
31.1 , - 2.099 ;
34.05 , - 2.411 ;
37.05 , - 2.662 ;
40.2 , - 2.864 ;
45.03 , - 3.107 ;
50.05 , - 3.278 ;
55.02 , - 3.391 ;
];
% 提取x和y
x = data (:, 1 );
y = data (:, 2 );
% 绘图
figure ;
plot ( x , y , '-r' , 'DisplayName' , 'Line through Data Points' );
hold on ; % 保持当前图形
scatter ( x , y , 'blue' , 'DisplayName' , 'Data Points' );
xlabel ( 't/min' );
ylabel ( '\alpha/°' );
legend ;
grid on ;
% 保存为300dpi的图像
print ( 'C:\Users\lenovo\Desktop\pic1.jpg' , '-djpeg' , '-r300' );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
% 数据
data = [
2.28 , 2.57322 ;
4.07 , 2.55218 ;
6.68 , 2.3263 ;
8.82 , 2.0661 ;
10.82 , 1.891 ;
12.82 , 1.74641 ;
14.82 , 1.59127 ;
17.08 , 1.41342 ;
19.06 , 1.2596 ;
22.05 , 1.02461 ;
25.06 , 0.78116 ;
28.03 , 0.53708 ;
31.1 , 0.28141 ;
34.05 , 0.01292 ;
37.05 , - 0.27181 ;
40.2 , - 0.57982 ;
];
% 提取x和y
x = data (:, 1 );
y = data (:, 2 );
% 使用MATLAB的polyfit进行线性拟合
coefs = polyfit ( x , y , 1 );
fit_values = polyval ( coefs , x );
% 绘图
figure ;
scatter ( x , y , 'blue' , 'DisplayName' , 'Data Points' );
hold on ;
plot ( x , fit_values , 'red' , 'DisplayName' , sprintf ( 'Fit: y = %.4fx + %.4f' , coefs ( 1 ), coefs ( 2 )));
xlabel ( 't/min' );
ylabel ( 'ln(\alpha-\alpha_{\infty})/°' );
legend ;
grid on ;
% 保存为300dpi的图像
print ( 'C:\Users\lenovo\Desktop\pic2.jpg' , '-djpeg' , '-r300' );
溶液表面张力的测定
Python作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import re
import numpy as np
import matplotlib.pyplot as plt
os . chdir ( os . path . split ( os . path . realpath ( __file__ ))[ 0 ])
# 数据
c = np . array ([ 0 , 1.69 , 2.54 , 3.39 , 4.23 , 6.77 , 8.47 ]) # concentration c / mol·L^-1
gamma = np . array ([ 0.0715 , 0.0517 , 0.0464 , 0.0423 , 0.0384 , 0.0321 , 0.0296 ]) # surface tension γ / N·m^-1
# 字体与图像参数
plt . rcParams . update ({ "font.size" : 14 })
# 绘图
plt . figure ()
plt . plot ( c , gamma , color = plt . get_cmap ( "tab10" )( 0 ), label = r "$\gamma$ vs $c$" ) # 蓝色线
plt . scatter ( c , gamma , color = plt . get_cmap ( "tab10" )( 1 ), marker = 'o' , zorder = 3 ) # 黄色点
# 标签与标题
plt . xlabel ( r "$c$ / mol$\cdot$L$^{-1}$" )
plt . ylabel ( r "$\gamma$ / N$\cdot$m$^{-1}$" )
plt . grid ( True )
plt . legend ()
plt . tight_layout ()
# 保存
plt . savefig ( "surface_tension.png" , dpi = 300 )
plt . show ()
Matlab作图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
% 数据
c = [ 0 , 1.69 , 2.54 , 3.39 , 4.23 , 6.77 , 8.47 ]; % concentration c / mol·L^-1
gamma = [ 0.0715 , 0.0517 , 0.0464 , 0.0423 , 0.0384 , 0.0321 , 0.0296 ]; % surface tension γ / N·m^-1
% 创建图像
figure ;
% 绘制蓝色线
plot ( c , gamma , '-o' , 'LineWidth' , 1.5 , 'Marker' , 'none' );
hold on ;
% 绘制橙色散点
scatter ( c , gamma , 60 , 'filled' );
% 标签
xlabel ( 'c / mol·L^{-1}' );
ylabel ( '\gamma / N·m^{-1}' );
% 网格与图例
grid on ;
legend ( '\gamma vs c' , 'Location' , 'best' );
% 设置字体大小为14
set ( gca , 'FontSize' , 14 );
% 保存为300dpi PNG
print ( gcf , 'surface_tension' , '-dpng' , '-r300' );