How do I extrapolate the curve to x = -5 and x = 25 using an appropriate extrapolation approximation?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
%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 commentaires
Stephen23
le 21 Sep 2017
@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.
Réponses (1)
Star Strider
le 18 Oct 2016
Modifié(e) : Star Strider
le 18 Oct 2016
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 commentaires
Star Strider
le 19 Oct 2016
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.
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!