How to bundle function input for optimization
3 ビュー (過去 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!