Optimizing the coefficients of basis functions to fit a curve
11 ビュー (過去 30 日間)
古いコメントを表示
I have 3 vectors F1, F2, and F3. I want to linearly combine these vectors such that I create a new function W(z)=a*F1+b*F2+c*F3, where a,b,c are just constant coefficients and the 3 vectors are essentially basis functions. These vectors are 1x70 doubles, and are shown plotted below (note that the horizontal axis 'Range' is the 'z'-variable in the equations below).

The problem I am having is finding a way to calculate the coefficients a,b,c so that W=a*F1+b*F2+c*F3 most closely matches a function given by:

Plotted together, W and r are shown below...

What sort of optimization process can I use to build a function W=a*F1+b*F2+c*F3 that fits 'W' to 'r' and returns the coefficients a,b,c used to do so? Please note that F1,F2, and F3 are all 1x70 doubles, and are not explicitly functions of z anymore. They have each individually been evaluated. And so I tried using the curvefitting app with no success because of this. I really just need a systematic way to optimize the coefficients a,b, and c. Is there a built in way to do this?
0 件のコメント
採用された回答
Matt J
2023 年 8 月 29 日
編集済み: Matt J
2023 年 8 月 29 日
You don't need any special curve fitting tool. Due to the linearity of the model, the coefficients can be found using mldivide, \
coefficients = [F1(:),F2(:),F3(:)]\r(:)
2 件のコメント
Image Analyst
2023 年 8 月 29 日
編集済み: Image Analyst
2023 年 8 月 29 日
Good answer Matt. I wish this trick was better known.
Shouldn't W be in the denominator instead of r?
Also note there is a similar version mrdivide, / that uses forward slash. Since I can never remember which to use I always have to look at the documentation and see which one best matches up with my data and coefficients. If you have a good mnemonic to avoid having to check the documentation, I'd like to hear it.
help mldivide
help mrdivide
Matt J
2023 年 8 月 29 日
Shouldn't W be in the denominator instead of r?
W=[F1(:),F2(:),F3(:)] is in the denominator. I jut didn't create a W variable explicitly.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interpolation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!