estimate parameter from kinetic model
4 views (last 30 days)
Show older comments
Hi! I want to ask question
So, this is a reversible reaction, all I want to do is fit my data to this function to find 'K'(equilibrium constant). I've tried make a code by using lsqcurvefit, but when I run the code, I have an error like this:
Error using plot
Vectors must be the same length.
Error in trycurvefit (line 66)
hlp = plot(tv,Cfit);
and when I change the initial parameter, the result is changing. Can anybody help me with the code? Any little advice or help will be much appreciated. Thank you.
function trycurvefit
clc
clear all
function obj = objective(p,t)
%initial concentration at t=0
C0 = [0.1;0];
%function handle to pass p through substrate function and obtain numerical
%model by solving nonlinear differential equation
[t,Cv] = ode45(@(t,C)subpro(t,C,p),ts,C0);
function dcdt = subpro(t,C,p)
%Known Parameters
k = 0.0003; %rate constant
%Unknown Parameters
K = p(1); %equilibrium constant
dcdt = zeros(2,1);
dcdt(1) = -k.*(C(1)-C(2)./K);
dcdt(2) = k.*(C(1)-C(2)./K);
dcdt = dcdt;
end
obj = Cv;
end
%Parameter Initial Guess
K = 100;
p0 = K;
%data from experiment
ts = [0
1
2
3
5
8
10
12
15
20
30];
Cmeasured = [0.1 0
0.068 0.015
0.065 0.016
0.062 0.017
0.06 0.018
0.059 0.02
0.058 0.0206
0.057 0.021
0.056 0.022
0.0553 0.023
0.055 0.024];
[p,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@objective,p0,ts,Cmeasured);
K = p;
disp(['K : ' num2str(K)])
tv = linspace(min(ts), max(ts));
Cfit = objective(p,tv);
figure(1)
plot(ts, Cmeasured, 'p')
hold on
hlp = plot(tv,Cfit);
hold off
grid
xlabel('Time')
ylabel('Concentration')
legend('glucose','fructose')
end
1 Comment
Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!