cftool custom equation doesn't work ?

16 views (last 30 days)
I have tried to fit the attached data (fit.mat) using custom equation fit, but it does not seem to work.
The equation used is: a1*sin(b1*x+c1) + a2*sin(b2*x+c2) + a3*sin(b3*x+c3) +
a4*sin(b4*x+c4) + a5*sin(b5*x+c5) + a6*sin(b6*x+c6) +
a7*sin(b7*x+c7) + a8*sin(b8*x+c8).
When I tried to use Sum of Sines fit (same data, same equation) it did something.
Is there a problem with Custon Equation fitting?
  5 Comments
Cosmin Traicu
Cosmin Traicu on 7 Jan 2019
First of all I am sorry if I bothered you with my questions. I insisted because I wanted to get the transfer function from this model.
I apologize again and thank you for your time.
Cosmin Traicu
Cosmin Traicu on 7 Jan 2019
That is a great answer.
Thank you so much.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 7 Jan 2019
I think I get the issue. I think it is why does 'sin8' work better than does a custom equation fit? The issue with a custom equation is it can be almost anything. As such, the code will have difficulties coming up with intelligent starting values for the coefficients. The default is a random start. Intelligently provided starting values will go a LONG way. But that sometimes almost requires you already know the answer, or at least something close.
But when you use a canned model like 'sin8', the tool knows something very valuable. At least it does if the programmer was on their toes. Someone who understands modeling might understand that the model has parameters that fall into specific classes. (At least, this is how I would write the code.) It would understand that some of the parameters are essentially linear parameters, that really do not need starting values, nor is iteration on those parameters even needed. That makes the entire problem much simpler.
For example, were I writing the code for fit, when I saw a model like 'sin1', I would recognize the mdoel can be written in the form
y = a*sin(b*x+c)
but that the same model can be written as
y = a1*sin(b*x) + a2*cos(b*x)
AND that I would recognize the parameters a1 and a2 are conditionally linear parameters. So given a value for b, I can then use a simple linear regression to recover a1 and a2. Then by simple mathematics when the fit is done, I can convert the model back into the original form. That is just application of a simple identity for the sine function. I can even put approximate confidence limits around the estimated parameters.
The reason for the expansion that I did was to be able to reduce the problem from one where you need to estimate THREE nonlinear parameters, to a nonlinear estimation with only ONE parameter to search for. As such, it will be MUCH more robust to poorly chosen starting values. It will converge more rapidly.
I'm not sure this is how they wrote the code inside fit. It certainly is the way I would have written that code. Regardless, there are surely other tricks they might have chosen. At least I would have chosen some way to arrive at an intelligent set of starting values, perhaps based on something like the expansion I described.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!