find minimal difference for vector (Optimalisation algorithm)

Dear Experts,
At the moment I'm trying to minimise a vector which compares experimental data with a function dependent on 3 unknown constants. Lets call these constants A, B and C. This means the function is dependent on f(x,y,A,B,C). The y-values from the experimental data must be as close as possible to the y-values of the function. Thus, I make a new vector which calculates the y-values of the function with the same x values used as for the experimental data. Now I want to compare both y-vectors and make an algorithm which uses iterations to obtain the must optimal values for A, B and C.
I know a function in matlab is present called fmincon, however this function makes use of an objective function, while I now have a vector which needs to be compared to another vector. Are there any build in matlab functions I can look into. Or is there a simple way to make this algorithm.
I would like to hear from you.
Kind regards,
Iljar Dickhof

 採用された回答

Star Strider
Star Strider 2021 年 9 月 30 日

0 投票

In the Optimization Toolbox, one option is the lsqcurvefit function.
To use any of the others (or any of the Global Optimization Toolbox functions), it would be necessary to create a second function (here ‘fitfcn’):
x = 1:20;
y = rand(size(x));
objfcn = @(b,x) b(1) + b(2).*sin(b(3).*x); % Example Function, A=b(1), B=b(2), C=b(3)
fitfcn = @(b) norm(y - objfcn(b,x)); % Function To Fit Data
B0 = rand(3,1); % Initial Parameter Estimates
B = fmincon(fitfcn, B0) % Fit Data, Return Optimised Parameters
.

2 件のコメント

Iljar Dickhof
Iljar Dickhof 2021 年 9 月 30 日
Is there also a way to constrain the different parameters b/B0?
Star Strider
Star Strider 2021 年 9 月 30 日
編集済み: Star Strider 2021 年 9 月 30 日
Yes.
The lsqcurvefit function can use upper and lower bounds, and fmincon and some Global Optimization Toolbox functions can use additional constraints (although I rarely use any other than the bounds, and have not in several years).
EDIT — (30 Sep 2021 at 18:08)
See the fmincon documentation section beginning with Minimize with Bound Constraints and the lsqcurvefit documentation section on Best Fit with Bound Constraints for details.
.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2021 年 9 月 30 日
編集済み: Matt J 2021 年 9 月 30 日

0 投票

1 件のコメント

Matt J
Matt J 2021 年 9 月 30 日
Is there also a way to constrain the different parameters b/B0?
As you will see at the link I've provided, lsqcurvefit does let you impose upper and lower bounds.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeNonlinear Optimization についてさらに検索

質問済み:

2021 年 9 月 30 日

編集済み:

2021 年 9 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by