How to fit a multivariate nonlinear function to experimental data?

2 views (last 30 days)
I've developed a function that should fit my experimental data. I'm trying to use the nonlinear regression model, but I'm having some difficulties executing the command with the function and associated data.
The function (shown below), in its full expression, is comprised of 8 variables (i.e., b(1), b(2), b(3), b(4), b(5), b(6), b(7), and x). x is the independent variable. b(4) is fixed at 0 or +/-Pi/6 in these examples.
Three representative data sets are found in the attachment that vary in complexity. I provide starting coefficient guesses for each set based on beta0 = [b(1) b(2) b(3) b(4) b(5) b(6) b(7)].
Data 1:
beta0 = [0.89 0.81 0 0 0 0 0]
Data 2:
beta0 = [0.38 0.97 0 0 0 0.54 0]
Data 3:
beta0 = [0.71 0.835 0 -0.523599 -0.15 -0.045 0]
The full functional form is illustrated here:
modelfun = @(b,x)b(1)^4 * cos(x)^2 * cos(b(4) - b(6) * sin(x))^4 + b(1)^4 * cos(b(4) - b(5) * sin(x))^4 * sin(x)^2 + b(3)^2 * (cos(x)^2 * (3 * b(2)^2 * cos(b(4) - b(6) * sin(x))^2 - 2 * b(1) * b(2) * cos(b(4) - b(6) * sin(x)) * cos(b(4) - b(5) * sin(x)) + b(1)^2 * cos(b(4) - b(5) * sin(x))^2) + (b(2)^2 * cos(b(4) - b(6) * sin(x))^2 - 2 * b(1) * b(2) * cos(b(4) - b(6) * sin(x)) * cos(b(4) - b(5) * sin(x)) + 3 * b(1)^2 * cos(b(4) - b(5) * sin(x))^2) * sin(x)^2) * sin(b(4) - b(7) * cos(x))^2 + b(3)^4 * sin(b(4) - b(7) * cos(x))^4
  5 Comments
Star Strider
Star Strider on 1 Feb 2018
By ‘vectorization’ I mean using element-wise operators instead of operators that could be interpreted as array operations.
Further reading: Array vs. Matrix Operations (link)
Carbon
Carbon on 5 Feb 2018
Thank you. Vectorization became a more significant contributor to my issue than the degrees/radians usage.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 31 Jan 2018
Your x values appear to be in degrees, but your Cos and Sin are going to be interpreted as requests to calculate with radians. You would need cosd and sind to calculate with degrees. However, if you are calculating with degrees, then I would tend to expect that b(4) would potentially be much larger than negative 1/2 degree.
  4 Comments
John D'Errico
John D'Errico on 1 Feb 2018
I would strongly suggest that you work ENTIRELY in degrees or radians. Otherwise, you will constantly be fighting bugs. Convert your data or your parameters to be consistent.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!