Fzero: Index exceeds array elements (1)

1 Ansicht (letzte 30 Tage)
Agra Sakti
Agra Sakti am 14 Apr. 2021
Kommentiert: Agra Sakti am 24 Apr. 2021
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

Antworten (1)

Shashank Gupta
Shashank Gupta am 19 Apr. 2021
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 Kommentar
Agra Sakti
Agra Sakti am 24 Apr. 2021
Hi Gupta,
Thanks for your information about it.
I modified the code a bit and now it works.
Have a good day.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by