Apply boundary condition to parameters during function nlinfit ?
2 ビュー (過去 30 日間)
古いコメントを表示
function [] = nlinfitExample() % Here is an example of using nlinfit(). For simplicity, none of % of the fitted parameters are actually nonlinear! % Define the data to be fit x=(0:1:10)'; % Explanatory variable y = 5 + 3*x + 7*x.^2; % Response variable (if response were perfect) y = y + 2*randn((size(x)));% Add some noise to response variable % Define function that will be used to fit data % (F is a vector of fitting parameters) f = @(F,x) F(1) + F(2).*x + F(3).*x.^2; F_fitted = nlinfit(x,y,f,[1 1 1]); % Display fitted coefficients disp(['F = ',num2str(F_fitted)]) % Plot the data and fit figure plot(x,y,'*',x,f(F_fitted,x Does anyone knows how to apply boundary condition to the parameters during the fitting using the function nlinfit?
I know that this could be done using the function fit, but i need to use the function nlinfit. (in that regards see the post in the link attached)
Thank you very much in advance for the help.Does anyone knows how to apply boundary condition to the parameters during the fitting using the function nlinfit?
Thanks...
0 件のコメント
回答 (1 件)
Parag
2025 年 4 月 15 日
Yes, the standard ‘nlinfit’ function in MATLAB does not natively support constraints or boundary conditions on the parameters. However, if you must use ‘nlinfit’ due to specific project requirements, there are a couple of effective workarounds to apply parameter bounds indirectly.
One of the possible workarounds can be to reparametrize the model such that the optimization only explores values within your desired bounds.
If you want to restrict a parameter F(i) to lie between ‘a’ and ‘b’, you define a new variable ‘z(i)’ and map it using a bounded transformation like:
F(i)=a+(b−a) ⋅(1/(1+exp−z(i)))
This way, z(i) can vary freely during optimization, but ‘F(i)’ will always stay in [a,b].
You can refer to MATLAB documentation of ‘nlinfit’ for more details:
Hope it is beneficial!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!