Help with interpol1. The grid vectors are not strictly monotonic increasing

1 view (last 30 days)
Hello,
I have my StressAmp and FatigueLife -vectors that I am plotting and least Square fitting using the polyval and polyfit commands.
I only have data for Three Points as seen in my example. I am having trouble using interpol1 to get data within my least Square fit. I need to know the value on the x-axis when the value of y-axis is 6. What am I doing wrong and how can I fix it?
My error message is:
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in interp1 (line 191) F = griddedInterpolant(X,V,method);
Error in MatlabHelpSNFatigue (line 30) K1=interp1(StressAmp,10.^fity,Amp1)
My matlab code is:
StressAmp=[10 6 6];
FatigueLife=[60000 264000 330000];
%Log
X=log10(StressAmp);
Y=log10(FatigueLife);
semilogx(FatigueLife,StressAmp,'*');
ylim([0 12])
set(gca,'YTick',[0:1:12])
xlabel('N')
ylabel('F')
grid on
hold on
coef=polyfit(X,Y,1)
fity=polyval(coef,X)
semilogx(10.^fity,StressAmp,'r')
%interpol
Amp1=6
K1=interp1(StressAmp,10.^fity,Amp1)
semilogx(K1,Amp1,'*r')

Answers (1)

Guillaume
Guillaume on 26 Feb 2015
As the error message says, for interpolating, the known x must be strictly monotonically increasing. That means no duplicate (you have two 6) and in increasing order (so 6, 10).
I don't really understand what you're trying to do. What do you expect linear interpolation to do if you have twice the same x and two different y?
  3 Comments
Guillaume
Guillaume on 26 Feb 2015
The problem is not with Amp1, but with StressAmp and more importantly, your understanding of linear interpolation.
linear interpolation just finds between which two known x your query point falls and then just takes the appropriate ratio of the two corresponding known y. That is, it's just:
interpolationresult = (yafter-ybefore)*(unknownx-xbefore)/(xafter-xbefore)
If you have two ybefore for a single xbefore, what do you put in the formula above?
Anyway, since you've already performed a linear regression with polyval why don't you use polyfit to find your unknown?
logK1 = polyval(coeff, log(Amp1))
Daniel
Daniel on 26 Feb 2015
Hi, Okey. Thank you. I understand better now, but using your last line and using log10 instead of log like below gives me almost what I want. This is not spot on the least Square fit (see Picture). Why is that so?
logK1 = polyval(coef, log10(Amp1))
semilogx(10^logK1,Amp1,'*r')

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!