From: Simone on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hj46ev$s3l$1(a)fred.mathworks.com>...
> "Simone " <alfinalmefui(a)gmail.com> wrote in message <hj4328$mdm$1(a)fred.mathworks.com>...
> > "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hj3vrk$scl$1(a)fred.mathworks.com>...
> > > "Simone " <alfinalmefui(a)gmail.com> wrote in message <hj3q3d$i90$1(a)fred.mathworks.com>...
> > > > "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hj3oer$2ft$1(a)fred.mathworks.com>...
> > > > > "Simone " <alfinalmefui(a)gmail.com> wrote in message <hj3n5k$a8q$1(a)fred.mathworks.com>...
> > > > >
> > > > > > Now...how to input the conditions you kindly suggested to me?...:-)
> > > > >
> > > > > It seems lsqcurvefit cannot handle linear constraints, you should rather use lsqlin or quadprog.
> > > > >
> > > > > Bruno
> > > > Ok...but here the problem is how to use the tool....
> > > > Yes, lsqlin wants a different way of formalizing the fitting funtion...
> > > > It should be of the form: C = [x.^2 x ones(size(x))]; and not as an anonymous function, but in any case...how to force the conditions on the derivative and on the positiveness of the functions itself?...
> > > ==================
> > >
> > > This looks like it could help, if you set the knot spacing sufficiently large:
> > >
> > > http://www.mathworks.com/matlabcentral/fileexchange/24443-slm-shape-language-modeling
> >
> > Thanks!...
> ===========
>
> Just to be clear:
>
>
> > Even I would need a function and not a piecewise fit...i
> =================
>
> You do understood though that, if the knots are widely enough spaced, the piecewise fit really consists of only 1 piece, right?
>
> >n fact with your slmeval I could evaluate it...
> ==================
>
> not mine.

In fact...you're right...
I'll try...
Thanks
Simone
From: John D'Errico on
"Simone " <alfinalmefui(a)gmail.com> wrote in message <hjc43t$kfk$1(a)fred.mathworks.com>...
> "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hj46ev$s3l$1(a)fred.mathworks.com>...
> > "Simone " <alfinalmefui(a)gmail.com> wrote in message <hj4328$mdm$1(a)fred.mathworks.com>...
> > > "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hj3vrk$scl$1(a)fred.mathworks.com>...
> > > > "Simone " <alfinalmefui(a)gmail.com> wrote in message <hj3q3d$i90$1(a)fred.mathworks.com>...
> > > > > "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hj3oer$2ft$1(a)fred.mathworks.com>...
> > > > > > "Simone " <alfinalmefui(a)gmail.com> wrote in message <hj3n5k$a8q$1(a)fred.mathworks.com>...
> > > > > >
> > > > > > > Now...how to input the conditions you kindly suggested to me?...:-)
> > > > > >
> > > > > > It seems lsqcurvefit cannot handle linear constraints, you should rather use lsqlin or quadprog.
> > > > > >
> > > > > > Bruno
> > > > > Ok...but here the problem is how to use the tool....
> > > > > Yes, lsqlin wants a different way of formalizing the fitting funtion...
> > > > > It should be of the form: C = [x.^2 x ones(size(x))]; and not as an anonymous function, but in any case...how to force the conditions on the derivative and on the positiveness of the functions itself?...
> > > > ==================
> > > >
> > > > This looks like it could help, if you set the knot spacing sufficiently large:
> > > >
> > > > http://www.mathworks.com/matlabcentral/fileexchange/24443-slm-shape-language-modeling
> > >
> > > Thanks!...
> > ===========
> >
> > Just to be clear:
> >
> >
> > > Even I would need a function and not a piecewise fit...i
> > =================
> >
> > You do understood though that, if the knots are widely enough spaced, the piecewise fit really consists of only 1 piece, right?
> >
> > >n fact with your slmeval I could evaluate it...
> > ==================
> >
> > not mine.
>
> In fact...you're right...
> I'll try...
> Thanks
> Simone

SLM easily allows you to generate a SINGLE cubic
segment that spans the data. For kicks, I added a
property that would allow you to force a segment
to be quadratic.

Since this is easier to verify the quadratic nature
from a pp form for the result, here is slmengine
used on a random set of data, but returning a pp
result.

>> x = rand(10,1);
>> y = rand(10,1);
>> slm = slmengine(x,y,'knots',2,'xyppp',[x(1) 0],'result','pp','increasing','on')
slm =
form: 'pp'
breaks: [0.18687 0.7952]
coefs: [2.507e-17 -0.32686 0.39767 0.35898]
pieces: 1
order: 4
dim: 1
prescription: [1x1 struct]

Note that the function is monotone increasing as
requested. It has exactly two knots, one at each end
of the data.

As you can see from the coefficients of the single
segment, the cubic coefficient is zero to within
usable precision, so this is a quadratic polynomial as
requested.

To evaluate the function using polyval, remember to
subtract off the first break point from x!!! ppval does
this automatically.

I've just posted the new version of slm, so it will appear
later today sometime.

John
From: Bruno Luong on
"Simone " <alfinalmefui(a)gmail.com> wrote in message <hjc3iu$ghr$1(a)fred.mathworks.com>...

>
> Hi Bruno!...
> thanks for the reply!...and sorry for the late of my answer...
> Your suggestions made me understand how to use the function!...
> Thank you...
>
> The problem is that the second order polynomial does not fit very well (i thought it did but I was in error)...
>
> Hence, I have to try with higher order polynomial...
> Now the conditions for the first derivative are not enough...aren't them?
> Do I have to force the second derivative to be positive in both extreme...do I?...
>

You could try to enforce the second derivative. But that will be *sufficient* conditions and it might be too strong. But try it.

Beside John's SLM (or SML?), my free-knot spline function can do some similar tasks, admittedly the calling syntax is much less friendly and puzzled. One advantage is that my function is able to handle any spline/polynomial order - in principle.

http://www.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation

Bruno
First  |  Prev  | 
Pages: 1 2 3
Prev: sort matrix rows
Next: Marching Cube outdated?