Surface fit to determine the coefficients of a hypothetical equation

2 次查看(过去 30 天)
Dear all! As is mentioned in the title, I have to perform a surface fit to figure out coefficients of an analytical model. The equation describing the model in Matlab syntax is shown as follows:
JordanMdl=@(K,B,f) K(1).*(f./f0).*(B./B0).^2+K(2).*(f./f0).^2.*(B./B0).^2;
B,f are two inputs variables, whereas B0 and f0 are known constants. K(1),K(2) are the coefficients to be determined. In short, JordanMdl=f(B,f). I tried to use the built-in function lsqcurvefit, but one variable must be deactivated to let it run(e.g. f, and thus JordanMdl=f(B)), and the coefficients that were figured out differed greatly for different values of this deactivated variable. Apparently, curve fitting can only take one input while matching the random data points, and does not serve my purpose well. I wonder if there is any handy built-in functions/algorithum that can fulfill this purpose. Thanks a lot!

回答(1 个)

Star Strider
Star Strider 2018-5-13
The easiest way to approach this is to create a separate matrix from ‘B’ and ‘f’, then pass that as your independent variable:
JordanMdlShell = @(K,Bf) JordanMdl(K,Bf(:,1),Bf(:,2));
where:
Bf = [B(:) f(:)];
This creates ‘Bf’ as an (Nx2) matrix. This also requires that your dependent variable becomes a column vector, for example: ‘Y(:)’. Change that if you want them as row vectors.
This should work with lsqcurvefit.
  2 个评论
Bohan Liu
Bohan Liu 2018-5-14
Hi, thanks for your proposed solution. But the thing is it triggered an error message, saying index exceeds matrix dimensions. One tricky thing about this solution is that, it was assumed that B and f had the same length but actually they did not. I tried to modify B to be the same size as f yet it did not work. Please find attached a snapshot of the error message and the data points with which I want to perform the curve fit. Then you will get a better picture of my task. Thanks again!
Star Strider
Star Strider 2018-5-14
You cannot use ‘Loss_1000Hz’ and ‘Loss_2500Hz’ in your model because they do not have the same lengths as your other data.
Alternatively, you can use all the columns, although using only rows 3 through 12 (so that B<=1).
Those are the only options that I see.
Good luck!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics and Optimization 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by