MATLAB Answers

How to fit curve to see the scaling

10 ビュー (過去 30 日間)
Auryn_ 2019 年 1 月 9 日
コメント済み: A_V_G 2019 年 1 月 24 日
I would like to see the scaling (\alpha) of my curve f(x,y): x^\alpha
Thus, I need to fit my data to a curve but I cannot use the function polyfit as the value of \alpha could be any value between 0 and 2, and I receive the error message:
Index in position 2 is invalid. Array indices must be positive integers or logical values.
Is there any direct method to do this in Matlab?
Thanks in advance!

  4 件のコメント

表示 1 件の古いコメント
Auryn_ 2019 年 1 月 9 日
Hi Rik,
actually what I try to do is to find the value of \alpha. It should be certainly a value between 0 and 2.
If I use 1.5 for example the error mentioned above will appear.
I could install any additional tool box if needed.
Rik 2019 年 1 月 9 日
What is the exact code that you are currently using? Because you should be fitting your x-y data to something like this
fitfun=@(x,alpha) x.^alpha;
The error doesn't look like you are doing a curve fit.
Auryn_ 2019 年 1 月 9 日
I just did this:
f1 = polyval(p,x);
which is obviously wrong.
How can I plot the result of the fitfun function you mentioned?

Sign in to comment.


Rik 2019 年 1 月 9 日
That code doesn't work, because your data is not a polynomial. It doesn't make sense to fit to a polynomial if your data is not. The code below will generate some example data, perform the fit, and plot the result.
In this case you could also make an estimation of alpha by taking the x-base log of y. You'll probably have to do that in a loop.
%generate example data
y=x.^1.7 + noise;
%define function
fitfun=@(alpha,x) x.^alpha;
%perform fit
fitobject = fit(x(:),y(:),fitfun,'StartPoint',1);
%plot in a clean figure

  6 件のコメント

表示 3 件の古いコメント
Auryn_ 2019 年 1 月 24 日
Thanks, but actually that is not what I meant.
Instead of the error for each of the fitting points, I would like the total error for my fitting parameter alpha.
So, in the case that I have a lot of different curves and for each of them one alpha, if I want to plot all the alphas versus one parameter, how can I show the error bar for the alpha of each curve.
In your example above, I am talking about the total error for the whole fitting.
I hope this is a bit more clear now.
Rik 2019 年 1 月 24 日
The second output of the fit functions returns goodness-of-fit parameters, as you can read in the doc. I expect the sse is closest to what you mean.
A_V_G 2019 年 1 月 24 日

Sign in to comment.

その他の回答 (0 件)

Translated by