Polyfit in case of power function

Hi All. I have an equation of the form y=b+ a.x^(1/3)
I tried to fit a line by assuming
m=x^(1/3);
p=polyfit(m,y,1);
f=polyval(p,m);
plot(x,y,'o',x,f,'-');
but the plot isn't satisfactory. Is there any wrong with the code or is the problem with my selection of fitting equation?
Regards,

7 Comments

Jan
Jan on 29 Jul 2013
Edited: Jan on 29 Jul 2013
If you post a complete running example, finding the problem would be easier. How are x and y defined? Please explain "not satisfactory" with any details, because we cannot guess them.
y is data from velocity reading and x is distance to the water surface from bed. The equation is aimed at establishing the relationship between the two. i.e. the fitted line is no where near to the data points
By not satisfactory what I mean is there is a big difference between the fitted line and points.
Here is example for
y
1,60725893271707
1,46620242750038
1,38578253690211
1,33859904968378
1,30365908090931
1,27584042582168
1,24152386893687
1,19543575832287
1,12275575108227
1
x
0,303677531273487
0,863287893599830
1,89519546655633
3,56099365929051
6,02957555882858
9,47604464124941
14,0809364809519
20,0296314423575
27,5118938697559
36,7214997684994
Obviously your assumed fitting form won't fit the data well---just look at the plot of the initial data.
It has a double curvature; something like an exp(-ax) initially w/ then a negative curvature from about the midpoint of the data in the x direction.
You need a model that has the ability to have such different changes in characteristics over the range.
Do you have a physical process from which you might be able to derive a functional form? Or, if you only need an interpolating function to describe the data over the range, a spline would work quite nicely.
Thanks. Yes, I have a physical process which I embark on . What I really want is whether the code is ok or is there anyother alternative of doing it
dpb
dpb on 29 Jul 2013
Edited: dpb on 29 Jul 2013
The code is correct for what it is; f(x^1/3) just doesn't have the shape of your data irregardless of whether you transform x and use the polynomial or write the actual design matrix and use \ to solve.
Choose some other functional form or add terms or something.
Again, if you do have a physical process you should be able to derive a functional form for that from basic principles. It would seem unlikely that would lead to y~f(x^1/3). If it does then there's something badly amiss in the data or the model (or both).
Thank you very much
To get a grasp on what's going on, try the following...
plot(x,y)
b=polyfit(xp(6:end),y(6:end),1);
hold on, plot(x(6:end),polyval(b,xp(6:end)),'ro')
b=polyfit(xp(1:5),y(1:5),1);
plot(x(1:5),polyval(b,xp(1:5)),'go')
This separates the two sections of positive and negative curvature and fits the two regions separately.
As this clearly shows, x^1/3 is both too "weak" a correlation early on and of the opposite curvature later. There's simply no way you can adequately model these data w/ a single functional form of the type of a power relationship--they just don't follow that as a model.

Sign in to comment.

Answers (0)

Categories

Asked:

on 29 Jul 2013

Community Treasure Hunt

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

Start Hunting!