Fzero: Index exceeds array elements (1)

조회 수: 1(최근 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);
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);
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);


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.
  댓글 수: 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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by