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
0 个评论
回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geometry and Mesh 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!