Fzero: Index exceeds array elements (1)

2 次查看(过去 30 天)
Hi, it is my first time here. So I was trying to find parameter value of k1 and k2 by using fzero on the phi = modeling data - experiment data. But the fzero keep giving me an error of "Index exceeds array elements (1)" in "konstanta = fzero (...) line. The kguess array has 2 element and so I write the K(1) and K(2). Where did I code wrong? Thanks in advance, Agra.
function kinetik
kguess = [0.5 0.1];
konstanta = fzero(@fobj,kguess);
k1 = konstanta (1);
k2 = konstanta (2);
end
function phi = fobj(K)
k1 = K(1);
k2 = K(2);
tspan = [0 3.5];
CFFAdata = 0.096;
CMEOdata = 1.636;
initial = [2.15 2.39 0 0];
[tmodel,Cmodel] = ode23s(@fun,tspan,initial,[],K);
CFFAmodel = Cmodel (length(Cmodel),1);
CMEOmodel = Cmodel (length(Cmodel),3);
phi = (CFFAmodel-CFFAdata)+(CMEOmodel-CMEOdata);
end
function dCdt = fun(t,c,K)
dCdt = zeros(4,1);
dCdt(1) = -(K(1)+K(2))*c(1)*c(2);
dCdt(2) = -( K(1)+K(2))*c(1)*c(2);
dCdt(3) = K(1)*c(1)*c(2);
dCdt(4) = K(2)*c(1)*c(2);
end

回答(1 个)

Shashank Gupta
Shashank Gupta 2021-4-19
Hi Agra,
Looking at the setup of the problem, it seems like you are trying to find out the value of 2 variable. I think fzero function is not suitable for such setup of the problem because the function handle which this function take as input only accept a scalar input, check out the input function handle description here.
I hope this address your issue.
Cheers.
  1 个评论
Agra Sakti
Agra Sakti 2021-4-24
Hi Gupta,
Thanks for your information about it.
I modified the code a bit and now it works.
Have a good day.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Geometry and Mesh 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by