Surface fit to determine the coefficients of a hypothetical equation

4 views (last 30 days)
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!

Answers (1)

Star Strider
Star Strider on 13 May 2018
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 Comments
Bohan Liu
Bohan Liu on 14 May 2018
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 on 14 May 2018
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!

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!