Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fit quadratic polynomial and find minimum value and its site??

107 views
Skip to first unread message

Rajesh Acharya

unread,
May 15, 2008, 5:27:02 AM5/15/08
to
Hello,
I have a set of data
y = (say) 199 175 163 155 (142) 153 168 179 .. total 30
numbers
x= 1 2 3 4 5 ....29 30.

i fit a second order polynomial to this using polyfit and
find the coeficients in descending order.

now i want to find the 'minimum value' of 'y' and its site
with respect to x i.e. in this data y minimum is (142)
which is at x=5 but infact the polynomial may be reaching a
further minimum value between x=5 and 6 say 5.2145 etc...
how to find such a value of x at which the polynomial is
minimum using the above polynomial????
or
is there another method to find a quadratic function which
fits the above data and which i can solve easily to find
minval and minsite???

I tried 'fnmin' which requires spline/cubic fit but i did
not succeed in getting minimum value
this is what i did:
fun=spline(X,[0 Y 0]);
[minval minsite]= fnmin(fun, X); %interval-X
for the actual data that i have (not the above one) i got
minsite = 2 which was not the site for minval. the min
value was at x=13 and i wanted further refinement in x...

what could be the solution???

John D'Errico

unread,
May 15, 2008, 6:14:01 AM5/15/08
to
"Rajesh Acharya" <rv_ac...@yahoo.com> wrote in message
<g0gvl6$l97$1...@fred.mathworks.com>...

Why would fitting a spline necessarily
reproduce the shape and location of the
minimum of the least squares quadratic
polynomial?

You have the quadratic polynomial.

What do you know about the location
of the minimum of a quadratic?

John

Roger Stafford

unread,
May 15, 2008, 1:17:47 PM5/15/08
to
"Rajesh Acharya" <rv_ac...@yahoo.com> wrote in message <g0gvl6$l97
$1...@fred.mathworks.com>...
---------
In any quadratic function, y = a*x^2+b*x+c, you can complete the square:

y = a*(x+b/(2*a))^2+c-b^2/(4*a)

Hence the minimum or maximum always occurs at x = -b/(2*a), according as
the quantity a is positive or negative, respectively, and the value there is
obviously

c-b^2/(4*a)

Roger Stafford


Rajesh Acharya

unread,
May 16, 2008, 1:11:02 AM5/16/08
to
John D'Errico
I think i was not clear... initially i tried to fit a
quadratic polynomial but didnot find any direct function in
matlab to find the minimum value of the polynomial thus
whether we have such a function in matlab was my first
question...
then i tried to fit a spline(cubic curve) to the same data
because i found a function 'fnmin' which gives me the
minimum val and its site if i give a spline as input...
that was the second part of the mail (both mutually
exclusive events)
however in this second part i think i made some mistake in
the syntax and therefore got wrong results and i wanted
some help on the systax....

Roger,
thanks for the info ... I am trying to understand what you
have said there.... but not successful yet... let me think
more.

John D'Errico

unread,
May 16, 2008, 5:36:01 AM5/16/08
to
"Rajesh Acharya" <rv_ac...@yahoo.com> wrote in message
<g0j516$dnh$1...@fred.mathworks.com>...

> John D'Errico
> I think i was not clear... initially i tried to fit a
> quadratic polynomial but didnot find any direct function in
> matlab to find the minimum value of the polynomial thus
> whether we have such a function in matlab was my first
> question...

And my point was, that a quadratic
function is trivial to find the minimum of.
Use what you know about mathematics
to solve the trivial problems.

Its not even worth looking for fminbnd,
which would do what you wanted, or
fminsearch, another tool which would
have done it.


> then i tried to fit a spline(cubic curve) to the same data
> because i found a function 'fnmin' which gives me the
> minimum val and its site if i give a spline as input...
> that was the second part of the mail (both mutually
> exclusive events)
> however in this second part i think i made some mistake in
> the syntax and therefore got wrong results and i wanted
> some help on the systax....

Ok, then why not show us what you tried
that failed, instead of fishing around for
someone to give you the answer? fnmin
is perhaps the most trivial function to use
I've ever seen, so show us what you did.

John

Rajesh Acharya

unread,
May 18, 2008, 11:55:03 PM5/18/08
to
Gud morning John....
thanks for the first two functions.... as you say it is a
trivial thing but i guess that ignorance makes it a
serious problem and thats why i looked for help.... I feel
the matlab help search needs to be more powerful and more
interactive ..yeah.. well every novice will feel
that..right!! :)

i tried the spline fit problem in several ways according
to the info in help and it worked ultimately....painful!

I had given what i tried earlier in my original
post..since the curve fitting was just a small part of the
whole program thats why i dint mail the whole .m file...

fun=spline(X,[0 Y 0]);

minval minsite = fnmin(fun,X) ...this is what i was trying
for which i got starnge results...
then
fun=spline(X,Y);
minval minsite=fnmin(fun,X); ..this worked... how?..dont
know..whats the diff except [ 0 Y 0 ] nemind thanks for
your time.

0 new messages