Prev: importing geometry to PDEtool
Next: help with the code
From: John D'Errico on 10 Jul 2010 14:42 "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i1a9n2$ac$1(a)fred.mathworks.com>... > "Alex Pereira" <alexlopespereira(a)gmail.com> wrote in message <i197t5$jki$1(a)fred.mathworks.com>... > > > > Given a spline model, the extrema must occur at zeros > > > of the second derivative, or at the end points of the spline. > > > So differentiate the curve twice, and look for zero crossings > > > of that piecewise linear function. Then check each end of > > > the spline. > > > > > > John > > Dear John, > > Thank you for your relply. I understood the math theory about the second derivative. But I don't know how to differentiate this spline. Do you know it ? > ============ > > I guess if more than 1 person has heard of this 2nd derivative result, it must be true in some sense, but I'm not finding it to be true in the obvious sense for cubic B-splines. A cubic B-spline basis function on the interval [-1 1] is > > f(x) = 2/3 - x.^2 +abs(x).^3/2 > > which has an extrema (maximum) at x=0, but the 2nd derivative there is -2. Yes, you need to check the endpoints of the knot intervals. Is there any other obvious fact you wish to add to this conversation? John
From: us on 10 Jul 2010 14:45 "Alex Pereira" <alexlopespereira(a)gmail.com> wrote in message <i18h5j$smb$1(a)fred.mathworks.com>... > I've fit some data to a spline function. Now, I need to find all maximum and minimum points of this function. Does any one knows how to do it? > Here follows a simple test code that I'm using. > Thank you very much. > Alex > > a=[0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ]; > b=[1:size(a)]; > b = b(:); > a = a(:); > fo_ = fitoptions('method','SmoothingSpline','SmoothingParam',0.10000000000000000555); > ft_ = fittype('smoothingspline'); > cf_ = fit(b,a,ft_,fo_); > h_ = plot(cf_,'fit',0.95); %% this line only plots the result no reason to discuss this as your code does not work... us
From: Bruno Luong on 10 Jul 2010 14:54 "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i18pur$5nj$1(a)fred.mathworks.com>... > "Alex Pereira" <alexlopespereira(a)gmail.com> wrote in message > > Given a spline model, the extrema must occur at zeros > of the second derivative, or at the end points of the spline. > John John, do you mean the zeros of the *first* derivative? Bruno
From: Matt J on 10 Jul 2010 15:37 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <i1afkd$mv8$1(a)fred.mathworks.com>... > "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i18pur$5nj$1(a)fred.mathworks.com>... > > "Alex Pereira" <alexlopespereira(a)gmail.com> wrote in message > > > > Given a spline model, the extrema must occur at zeros > > of the second derivative, or at the end points of the spline. > > John > > John, do you mean the zeros of the *first* derivative? ====== It's got to be. I can definitely show examples of splines in which the 2nd derivative is non-zero at non-knot extrema %Cubic spline B3=@(x) (x>-1 & x<1).*(2/3 - x.^2 +abs(x).^3/2)+ (abs(x)>=1 & abs(x)<2).*((2-abs(x)).^3/6) %Cubic spline 1st derivative dB3= @(x) (x>-1 & x<1).*( - 2*x +3/2*sign(x).*x.^2)+ (abs(x)>=1 & abs(x)<2).*((2-abs(x)).^2/2).*(-sign(x)) %2nd derivative ddB3 = @(x) (x>-1 & x<1).*(- 2 + 3*abs(x))+ (abs(x)>=1 & abs(x)<2).*(2-abs(x)) %Derivatives of a spline combination dg=@(x) dB3(x) + dB3(x-1) %first deriv. ddg=@(x) ddB3(x) + ddB3(x-1) %2nd deriv. >> dg(0.5) %an extremum, not a knot ans = 0 >> ddg(0.5) %2nd deriv not zero ans = -1
From: Alex Pereira on 10 Jul 2010 15:48
"us " <us(a)neurol.unizh.ch> wrote in message <i1af4l$nmh$1(a)fred.mathworks.com>... > "Alex Pereira" <alexlopespereira(a)gmail.com> wrote in message <i18h5j$smb$1(a)fred.mathworks.com>... > > I've fit some data to a spline function. Now, I need to find all maximum and minimum points of this function. Does any one knows how to do it? > > Here follows a simple test code that I'm using. > > Thank you very much. > > Alex > > > > a=[0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ]; > > b=[1:size(a)]; > > b = b(:); > > a = a(:); > > fo_ = fitoptions('method','SmoothingSpline','SmoothingParam',0.10000000000000000555); > > ft_ = fittype('smoothingspline'); > > cf_ = fit(b,a,ft_,fo_); > > h_ = plot(cf_,'fit',0.95); %% this line only plots the result > > no reason to discuss this as your code does not work... > > us Sorry. Now it works. a=[0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ]; b=[1:size(a,2)]; b = b(:); a = a(:); fo_=fitoptions('method','SmoothingSpline','SmoothingParam',0.10000000000000000555); ft_ = fittype('smoothingspline'); cf_ = fit(b,a,ft_,fo_); h_ = plot(cf_,'fit',0.95); |