How do I extrapolate the curve to x = -5 and x = 25 using an appropriate extrapolation approximation?
2 次查看(过去 30 天)
显示 更早的评论
%This is what I have so far, and I am to plot the extrapolated data points once I get it correctly. Thanks for the help!
%The file "curves.xlsx" is just a 21x2 matrix in excel.
curve = xlsread('curve.xlsx');
day = curve(:,1);
hairBalls = curve(:,2);
steps = (0:.2:20);
interSpline = interp1(day,hairBalls,steps,'spline');
extrapoSpline = interp1(day,hairBalls,steps,'spline','extrap');
plot(day, hairBalls,'ko',steps,interSpline,'rx:');
3 个评论
Stephen23
2017-9-21
@Snooping Poppet: it is not appreciated when you edit away the text of your question. Imagine if everyone did that, then this entire forum would be useless for anyone else as it would only consist of thousands of threads all reading "This post was taken down". Would you find that useful?
By deleting your question you unilaterally decided that Star Stider's volunteered time helping you shall not be useful to anyone else. Does Star Strider get a say in this decision? Do you think this is why we volunteers come here and write our advice and comments?
If you want a consulting service then you will find plenty of them on them internet. This is a community forum with answers provided by volunteers.
回答(1 个)
Star Strider
2016-10-18
编辑:Star Strider
2016-10-18
Extrapolation to this extent is hazardous. You may be assuming much more about the data outside the region-of-fit than are appropriate.
That aside, the way to extrapolate it from -5 to +25 is to add those values to your ‘query’ vector:
extrapoSpline = interp1(day,hairBalls, [-5, steps, 25], 'spline','extrap');
If you want it to extrapolate continuously to include those limits, change your interpolation ‘query’ vector to include them as limits:
steps2 = (-5:0.2:25);
extrapoSpline = interp1(day,hairBalls,steps2,'spline','extrap');
Good luck!
4 个评论
Star Strider
2016-10-19
This works for me:
steps2 = (-5:0.2:25);
extrapoSpline2 = interp1(day,hairBalls,steps2,'spline','extrap');
figure(2)
plot(day, hairBalls,'ko', steps2,extrapoSpline2,'gx:')
If it doesn’t produce the result you are expecting (and I have no idea what they are), it serves to illustrate the hazards of extrapolating beyond the region-of-fit. Consider a different extrapolation method (such as 'linear' or 'pchip'), or perhaps a simple linear fit to get the result you want.
For example:
B = [ones(size(day)) day]\hairBalls;
LinearFit = [[1; 1] [-5; 25]]*B;
figure(3)
plot(day, hairBalls,'ko', [-5 25],LinearFit,'--g')
The polyfit and polyval functions also provide different fitting and extrapolation options you may want to explore.
What you want and what the relevant mathematics can provide may not exactly match.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!