From: Simone on
Hi all
Maybe it is a silly question, but I really don't know how to solve it.
I need to find the best fitting function of a series of points X Y showing a quadratic-like behavior...
BUT...I need that the function is monotonically increasing and always positive.
What I know is that my points are in [0 1] domain both in X and Y.
I would like to fit a quadratic polynomial with the conditions listed before...
That is, polyfit-polyval combination do not help me.
I tried to use lsqcurvefit but i don't know how to force the tool to respect the conditions.
I noticed that lower and upper bounds conditions applied to coefficients x do not assure that their function f(x) is positive...
Moreover, I know that for monotonically increasing condition I should check the first derivative sign but i don't know how to do it.
Thanks in advance
Simone
From: Bruno Luong on
"Simone " <alfinalmefui(a)gmail.com> wrote in message <hj1ma1$r9m$1(a)fred.mathworks.com>...
> Hi all
> Maybe it is a silly question, but I really don't know how to solve it.
> I need to find the best fitting function of a series of points X Y showing a quadratic-like behavior...
> BUT...I need that the function is monotonically increasing and always positive.
> What I know is that my points are in [0 1] domain both in X and Y.
> I would like to fit a quadratic polynomial with the conditions listed before...
> That is, polyfit-polyval combination do not help me.
> I tried to use lsqcurvefit but i don't know how to force the tool to respect the conditions.
> I noticed that lower and upper bounds conditions applied to coefficients x do not assure that their function f(x) is positive...
> Moreover, I know that for monotonically increasing condition I should check the first derivative sign but i don't know how to do it.
> Thanks in advance
> Simone

1. The quadratic function has linear derivative
2. If your function f increases on [a, b], that means f'(x)>=0 on [a,b], because of (1) this is equivalent to f'(a)>0 and f'(b)>0.
3. If your function is increasing, then f(x)>=0 is equivalent to f(a)>=0

In short, you need to impose the following constraints
f'(a)>=0, f'(b)>=0 and f(a)>=0. This three conditions can be written as linear constraints of the polynomial coefficients.

Bruno
From: Simone on
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hj1n4a$kj0$1(a)fred.mathworks.com>...
> "Simone " <alfinalmefui(a)gmail.com> wrote in message <hj1ma1$r9m$1(a)fred.mathworks.com>...
> > Hi all
> > Maybe it is a silly question, but I really don't know how to solve it.
> > I need to find the best fitting function of a series of points X Y showing a quadratic-like behavior...
> > BUT...I need that the function is monotonically increasing and always positive.
> > What I know is that my points are in [0 1] domain both in X and Y.
> > I would like to fit a quadratic polynomial with the conditions listed before...
> > That is, polyfit-polyval combination do not help me.
> > I tried to use lsqcurvefit but i don't know how to force the tool to respect the conditions.
> > I noticed that lower and upper bounds conditions applied to coefficients x do not assure that their function f(x) is positive...
> > Moreover, I know that for monotonically increasing condition I should check the first derivative sign but i don't know how to do it.
> > Thanks in advance
> > Simone
>
> 1. The quadratic function has linear derivative
> 2. If your function f increases on [a, b], that means f'(x)>=0 on [a,b], because of (1) this is equivalent to f'(a)>0 and f'(b)>0.
> 3. If your function is increasing, then f(x)>=0 is equivalent to f(a)>=0
>
> In short, you need to impose the following constraints
> f'(a)>=0, f'(b)>=0 and f(a)>=0. This three conditions can be written as linear constraints of the polynomial coefficients.
>
> Bruno

Thanks Bruno!...
It is exactly what I need...
In fact I had formulated this theory in my mind but I did not formalize concretely...
Now the problem is how to input such constraints to the fitting tool.
I guess I have to use lsqcurvefit with the polynomial function written as anonymous function...
Something like
a = lsqcurvefit(yfun,[0;0;0;0],x,y),
where:
yfun is my polynomial function formetted as anonymous one:
yfun = @(a,x) (a(1)*x.^2) + (a(2)*x) + a(3)*ones(size(x))
and x,y are my points coordinates
the vector [0;0;0;0] is my arbitrary initial condition...
Now...how to input the conditions you kindly suggested to me?...:-)
Thanks in advance
Simone
From: Bruno Luong on
"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
From: Simone on
"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?...
Could you help me suggesting the syntax?...:-)
Thanks in advance
Simone
 |  Next  |  Last
Pages: 1 2 3
Prev: sort matrix rows
Next: Marching Cube outdated?