How can I apply a polynomial to a set of data?

2 views (last 30 days)
Stephen
Stephen on 14 Jul 2014
Answered: Star Strider on 14 Jul 2014
I am somewhat of a beginner, so please bear with me!
I generated a series of curves for different situations based on a set of data I was given. Now, I have a new curve for one of the situations. I want to take the difference between the new and old, and then apply that difference to all of the old curves.
Essentially, I want to find an equation for the difference between the old and new curves, and then apply that equation to the remaining curves that I was not given new data for to extrapolate all of my new data.
For example, here is my code:
newdata=[1003 270; 2482 690; 3977 1140];
olddata=[994 290; 1459 420; 2452 740; 3444 1070; 3959 1250];
newpoly=polyfit(newdata(:,1),newdata(:,2),2);
oldpoly=polyfit(olddata(:,1),olddata(:,2),2);
x=400:50:8250;
oldval=polyval(oldpoly,x);
newval=polyval(newpoly,x);
plot(x,oldval,'m',x,newval,'b')
I essentially want to find the equation describing the difference between the two curves and apply it to my other old curves, to generate a new series of curves.
Does that make sense? Please let me know, and I will elaborate if necessary.

Answers (2)

dpb
dpb on 14 Jul 2014
Carrying on from where you left off...
>> hold on
>> plot(x,oldval-newval) % see what diff actually looks like--pretty smooth
>> difpoly=polyfit(x,oldval-newval,2);
>> difval=polyval(difpoly,x);
>> plot(x,newval+difval,'rx')

Star Strider
Star Strider on 14 Jul 2014
From a statistical perspective, that is a very bad idea, especially if you want to extrapolate, which itself is generally not a good idea. You have no idea what your data actually do beyond the region-of-fit. The extrapolation could be spot-on or wildly inaccurate. You will never know. This is especially the case if you are using polynomial curve fitting. Polynomial curve fitting is useful to see if there are any trends in your data, but not beyond that.
If you have a model of your data that you want to fit, use that model. You are on somewhat firmer footing if you want to extrapolate in that situation. Even then, taking the difference between two curves (by taking the differences between the parameters?) is not statistically appropriate.

Categories

Find more on Interpolation 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!