?? kineticsest1_diff.m
字號(hào):
function KineticsEst1_Diff
% 動(dòng)力學(xué)參數(shù)辨識(shí): 用微分法進(jìn)行反應(yīng)速率分析得到速率常數(shù)k和反應(yīng)級(jí)數(shù)n
% Analysis of kinetic rate data by using the differential method
%
% Author: HUANG Huajiang
% Copyright 2003 UNILAB Research Center,
% East China University of Science and Technology, Shanghai, PRC
% $Revision: 1.0 $ $Date: 2003/07/27 $
%
% Reaction of the type -- rate = kCA^order
% order - reaction order
% rate -- reaction rate vector
% CA -- concentration vector for reactant A
% T -- vector of reaction time
% N -- number of data points
% k- reacion rate constant
clear all
clc
% 動(dòng)力學(xué)數(shù)據(jù)
t = [0 20 40 60 120 180 300];
CAm = [10 8 6 5 3 2 1];
% 用最小二乘樣條擬合法計(jì)算微分dCA/dt--使用不經(jīng)過(guò)實(shí)驗(yàn)點(diǎn)的B樣條插值函數(shù)
knots = 3;
K = 3; % 三次B樣條
sp = spap2(knots,K,t,CAm);
pp = fnder(sp); % 計(jì)算B樣條函數(shù)的導(dǎo)函數(shù)
dCAdt = fnval(pp,t); % 計(jì)算t處的導(dǎo)函數(shù)值
rAm = dCAdt;
% 繪制濃度擬合曲線(xiàn)
ti = linspace(t(1),t(end),200);
CAi = fnval(sp,ti);
plot(t,CAm,'ro',ti,CAi,'b-')
xlabel('t')
ylabel('C_A')
legend('實(shí)驗(yàn)值','B樣條擬合')
% 非線(xiàn)性擬合
beta0 = [0.0053 1.39];
[beta,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(@OptObjFunc,beta0,[],[],[],rAm,CAm);
ci = nlparci(beta,residual,jacobian);
% 參數(shù)辨識(shí)結(jié)果
fprintf('Estimated Parameters:\n')
fprintf('\tk = %.4f ± %.4f\n',beta(1),ci(1,2)-beta(1))
fprintf('\tn = %.2f ± %.2f\n',beta(2),ci(2,2)-beta(2))
fprintf(' The sum of the squares is: %.1e\n\n',sum(residual.^2))
% 繪制反應(yīng)速率擬合曲線(xiàn)
figure
plot(t,rAm,'ro',t,Rate(CAm,beta),'b*')
xlabel('t')
ylabel('dC_Adt')
legend('Experiment','Kinetic Model')
% ------------------------------------------------------------------
function f = OptObjFunc(beta,rAm,CAm)
rAc = Rate(CAm,beta);
f = rAc - rAm;
% ------------------------------------------------------------------
function rA = Rate(CA,beta)
rA = -beta(1)*CA.^beta(2); % -rA = -dCAdt = k*CA^n, 其中k=beta(1), n=beta(2)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -