Fittype - Fitting Curve and Starting Point
5 次查看(过去 30 天)
显示 更早的评论
Hello guys. I used the following code in order to get the coefficients of King's law for Hot-Wire Anemometry.
The form of this equation is "E^2 = A + B*u^n" where n is given in my example. E and u are already defined as vectors. Now how can I use "fittype" considering that n is given and where can I define it? Furthermore how do I have to define my startpoint for this method?
start = [3;0.5;0.45];
up = [inf;inf;inf];
low = [-inf;-inf;-inf];
options = fitoptions('Method','NonlinearLeastSquares','Upper',up,'Lower',low,'Display','iter','TolFun',10^-10,'TolX',10^-10,'StartPoint',start);
f = fittype('sqrt(A+B*x^n)');
res1 = fit(u,E,f,options)
5 个评论
John D'Errico
2017-6-9
编辑:John D'Errico
2017-6-9
READ THE ERROR MESSAGE!!!!!!! Of course it works.
If n is fixed and known, which is what you claim, then you have TWO parameters. NOT 3. But you have set THREE bounds, and THREE starting values.
If you want to estimate n, then do so. But then you cannot have it also fixed and known. So what do you really want to do?
回答(1 个)
John D'Errico
2017-6-9
编辑:John D'Errico
2017-6-9
Ok. Think of an optimizer as a blind man placed on the surface of the earth, then tasked with finding the lowest point of elevation. Yes, we know that to be a trench in the Pacific ocean, but he needs to find his way there.
All this fellow can do is look around locally, as well as remember what he has learned about the surface from previous tests with his cane. Am I pointing downhill? Is this a good direction to search? If so, he tries walking in some direction. At some point, he will decide that he has gone far enough, and he needs to search around him again. Now which direction looks like a good way to go?
Yes, I know, this is a rather difficult job for a blind man to be given. But we are paying him quite well. I do hope we remembered to give him SCUBA gear, as he may need it before he is done. :)
I think you can imagine why it would be important to start him out near the true solution. Otherwise, he may get stuck in some locally low spot. For example, start out near the dead sea, and while he will get wet at the end, there are lower points of elevation, if he just got started in a better place. But once in a local minimizer, it can be essentially impossible to escape, since all directions look to be uphill.
Starting values are just that - where do we set the fellow down to start? For this task, the Pacific ocean might be a good start. A really good submarine will help too. If instead, you set him down in the Himalayas, you may well find he gets stuck in a frozen lake in some random valley.
So how does this impact how you choose starting values? You should know something about your problem. Hey, it is your problem, and your data! In the example function, here with n==3:
sqrt(A+B*x^3)
what do A and B mean? For example, suppose that B is negative? For positive x, then your function is a decreasing function. If your data is increasing as x increases, then B should be a positive number! So you probably know something about at least the sign of B. Again, if you don't, then it is time to plot your data and think about the model. There are similar inferences you can make about A.
By the way, with a model like this, be careful that the optimizer does not try to look in a place where it starts generating complex numbers. That will confuse it. Bad values of A and B could cause that to happen. So use bound constraints where necessary, to avoid bad stuff happening.
What might be reasonable values for A and B? Random numbers for a start point are a great way to start that poor fellow down in the Himalayas, or perhaps a patch of Amazon rain forest, or the Dead Sea. At least give the guy a chance of success.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!