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!