How to bundle function input for optimization
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi!
I am trying to optimize a pdepe function of the form;
function I_num_ano1 = PSw_EK_v11(k_m, D_m, s_bulk)
Here I want to optimize the k_m and D_m input via the lsqcurvefit function. I have made a separate file to accomodate the optimization function. But for that I need a single variable containing both k_m and D_m (because in the documentation the example give is of a objective function with variables x(1) and x(2)). How can I do that?
Script "PSw_EK_v11_Caller" is given below:
% The purpose of this script is to call PSw_EK_v11 and give it mutiple
% substrate concentrations and calculate the respective current values.
% Using this we can plot a [S] vs I plot and then try to fit Kavita's curve
% onto it and calculate parameters using that.
I_exp = 2.73e-03;
s_bulk = 5.00e-06;
% x = [k_m, D_m];
options = optimoptions('lsqcurvefit','Algorithm','trust-region-reflective', ...
'OptimalityTolerance',1e-13,'FunctionTolerance',1e-13);
lb = [1e03, 1e-09];
ub = [1e08, 1e-04];
k_0 = [1e03, 10e-08]; %starting point
% % lsqnonlin(@(k_m)PSw_EK_v7(k_m, s_bulk)-I_exp, k_m_0, lb, ub);
[x, resnorm,residual,exitflag,output,I_num_ano1]=lsqcurvefit(@PSw_EK_v11, k_0, s_bulk, I_exp, lb, ub, options)
댓글 수: 2
Star Strider
2022년 4월 4일
These are for fitting systems of ordinary differential equations, however the techniques should be adaptable to other systems and solvers.
답변 (1개)
Nipun
2024년 1월 25일
Hi Hashim,
I understand that you are trying to to bundle the function parameters (in this case arrays) to pass it to the objective function,
There are many ways to bundle arrays as a single variable. Here are two of the ways you can leverage array bundling:
- Structures: You may create a variable "x" such that x.'1' = k_m and x.'2' = D_m
- Cell arrays: You can define a "x" as a cell array, with each element as the required variable.
x = {k_m, D_m};
However, since you need to fit the xdata and ydata based on the mentioned function, I believe variable "x" will be returned by the curve fitting function. Therefore, instead of assigning "k_m" and "D_m" to "x", you may want to return the output as:
k_m = x(1); D_m = x(2);
Hope this helps.
Regards,
Nipun
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!