Fzero: Index exceeds array elements (1)

7 ビュー (過去 30 日間)
Agra Sakti
Agra Sakti 2021 年 4 月 14 日
コメント済み: Agra Sakti 2021 年 4 月 24 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by