Hi Azarany,
I understand that you are encountering the "Index exceeds array bounds" error when attempting to use “fzero” in your “kinetic” function to estimate kinetic parameters.
The issue occurs from using “fzero” with a vector input. MATLAB’s “fzero” function is designed strictly for scalar-valued functions and scalar inputs. However, in your implementation, the objective function “fobj” expects a 2-element vector (“K = [k1, k2]”), which “fzero” cannot handle, hence leading to the index error.
To solve this issue, I recommend using “fsolve” instead of “fzero”. The “fsolve” function is built to handle nonlinear equations and supports vector inputs. Kindly refer to the following corrected version of your code:
function kinetik
kguess = [0.5 0.1]; % Initial guess for [k1, k2]
options = optimoptions('fsolve','Display','iter');
konstanta = fsolve(@fobj, kguess, options);
k1 = konstanta(1);
k2 = konstanta(2);
fprintf('k1 = %.4f\n', k1);
fprintf('k2 = %.4f\n', k2);
end
These changes ensure that your input vector “[k1, k2]” is handled appropriately during optimization, and the error related to indexing is resolved.
For further reference, you can refer to the following MATLAB's official documentation on “fsolve” and “fzero”:
