# Thread: Calulating the minimum value of f(x) in a given range of x?

1. ## Calulating the minimum value of f(x) in a given range of x?

Given the function below, where a, b, c, d, e are constants.

f(x) = ax^4 + bx^3 + cx^2 + dx + e

How do I get the minimum return value given that x lies in the range 0 <= x < 1?

I know this has something to do with differentiation (maybe??), and I know that the derivative is:

df(x) = 4ax^3 + 3bx^2 + 2cx + d

But I have no idea how to get the minimum value back within a given range of x.

Any help would be appreciated!

2. f(x) = ax^4 + bx^3 + cx^2 + dx + e
f '(x) = 4ax^3 + 3bx^2 + 2cx + d
0 <= x < 1

Ok, thats all you need to solve this problem. What you want to do is solve f '(x) for zero. Find all the x coordinate points where y equals zero in that equation and you'll have the x positions in the function f(x) at which the gradient is zero.

In a quartic like f(x) the derivative will have 3 points where y=0, so 3 turning points in f(x), one will be the maximum, one will be the minimum, and another will be in between both.

Once you have the x values calculated from the derivative f '(x) you can sub the 3 values back in to the original function f(x) and find which of those is the minimum and thus which value of x is the minimum.

But!.... Since you have been given a range for x, you might find that 2 of those values of x you found in the derivative function are outside those bounds, so you can exclude those straight away.

For example:
x1 = -12.3 , x2 = 0.4 , x3 = 54.6

In this case, both x1 and x3 lie outside the bounds of zero and one (0<=x<1) so the answer would be x2.

Identify the appropriate x value, then sub it back in to the original equation and give the corresponding y value for the minimum.

-----------------------------------------

You might find that none of the 3 calculated x values lie within the boundaries specified, so simply take the lower limit (in this case "0") and sub that in as the x value in the original function f(x). Then sub in the upper limit (in this case "1") in f(x) and find which is smaller, and that will be your answer.

I haven't told you how to solve for x in this :P I can't do everything for you now can I? If you need help with that, let me know and I'll step you through solving for x in a cubic derivative.

Hope it helps, and good luck.

3. Originally Posted by Makka
f(x) = ax^4 + bx^3 + cx^2 + dx + e
f '(x) = 4ax^3 + 3bx^2 + 2cx + d
0 <= x < 1

Ok, thats all you need to solve this problem. What you want to do is solve f '(x) for zero. Find all the x coordinate points where y equals zero in that equation and you'll have the x positions in the function f(x) at which the gradient is zero. Mr F says: So you're proposing to langers2k that s/he solve a general cubic equation ......

In a quartic like f(x) the derivative will have 3 points where y=0, so 3 turning points in f(x), one will be the maximum, one will be the minimum, and another will be in between both. Mr F says: Not true. For example, $\displaystyle {\color{red}y = x^4 - 2x^3 + \frac{3}{2} x^2 - \frac{1}{2} x - \frac{15}{16} = \left(x- \frac{1}{2}\right)^4 - 1}$ has only one (minimum) turning point.

Once you have the x values calculated from the derivative f '(x) you can sub the 3 values back in to the original function f(x) and find which of those is the minimum and thus which value of x is the minimum.

But!.... Since you have been given a range for x, you might find that 2 of those values of x you found in the derivative function are outside those bounds, so you can exclude those straight away.

For example:
x1 = -12.3 , x2 = 0.4 , x3 = 54.6

In this case, both x1 and x3 lie outside the bounds of zero and one (0<=x<1) so the answer would be x2.

Identify the appropriate x value, then sub it back in to the original equation and give the corresponding y value for the minimum.

-----------------------------------------

You might find that none of the 3 calculated x values lie within the boundaries specified, so simply take the lower limit (in this case "0") and sub that in as the x value in the original function f(x). Then sub in the upper limit (in this case "1") in f(x) and find which is smaller, and that will be your answer.

I haven't told you how to solve for x in this :P I can't do everything for you now can I? Mr F wryly observes: Very glib. The devil is in the detail. Which would be why there is none .......

If you need help with that, let me know and I'll step you through solving for x in a cubic derivative. Mr F remarks: I think you're biting off more than you can chew here, sport.

Hope it helps, and good luck.
I'm certain there's more to the question that what's been posted ......

4. Thanks for that, I think most of it makes sense.

I need to find the three roots of f'(x) and use them to calculate the y values (where x is in range), I then also need to get the y values at each extreme of the specified range.

This will give me between 2 and 5 sets of values (for x, and resulting y). I can then choose the correct one by choosing the lowest y value.

So all I need to do is calculate the real roots of f'(x) which is a cubic polynomial and I am all set!

What method would you suggest using to solve f'(x)? I will be programming it into a computer so complexity isn't too much of a problem.

I have found this page which explains one method: Solving Cubic Equations.

Or I can use the Newton-Raphson method that I already have in code. My only problem is choosing a start point for the Newton-Raphson method, are there any ways to calculate a good guess to start with?

5. Originally Posted by mr fantastic
I'm certain there's more to the question that what's been posted ......
Not sure, its not technically a question that has been set. I need to make a simulator of sorts and deal with collisions, I will be using this to calculate collision times so I can model them accurately.

Originally Posted by mr fantastic
Mr F says: So you're proposing to langers2k that s/he solve a general cubic equation ......
Unfortunately it will be used in a computer program, so the values of a to e can be anything.

Assuming the rest of Makka's method is fitting to my requirements can you give me advice on how to solve the cubic? Thanks!

6. Originally Posted by langers2k
Thanks for that, I think most of it makes sense.

I need to find the three roots of f'(x) and use them to calculate the y values (where x is in range), I then also need to get the y values at each extreme of the specified range.

This will give me between 2 and 5 sets of values (for x, and resulting y). I can then choose the correct one by choosing the lowest y value.

So all I need to do is calculate the real roots of f'(x) which is a cubic polynomial and I am all set!

What method would you suggest using to solve f'(x)? I will be programming it into a computer so complexity isn't too much of a problem.

I have found this page which explains one method: Solving Cubic Equations.

Or I can use the Newton-Raphson method that I already have in code. My only problem is choosing a start point for the Newton-Raphson method, are there any ways to calculate a good guess to start with?
If a, b, c, d, e are unrestrained constants, then the minimum value of the quartic over the interval [0, 1) can be anything you want it to be!!!!

The quartic $\displaystyle {\color{red}y = x^4 - 2x^3 + \frac{3}{2} x^2 - \frac{1}{2} x + \frac{1}{16} - k = \left(x- \frac{1}{2}\right)^4 - k}$ has a minimum value of k occuring at x = 1/2. k is any real number.

The question as posted has no sensible answer.

7. Originally Posted by mr fantastic
If a, b, c, d, e are unrestrained constants, then the minimum value of the quartic over the interval [0, 1) can be anything you want it to be!!!!

The quartic $\displaystyle {\color{red}y = x^4 - 2x^3 + \frac{3}{2} x^2 - \frac{1}{2} x + \frac{1}{16} - k = \left(x- \frac{1}{2}\right)^4 - k}$ has a minimum value of k occuring at x = 1/2. k is any real number.

The question as posted has no sensible answer.
I don't know what a, b, c, d, e will be when I create the program, but at run-time they are fixed. Surely there will be a minimum value of y given a range of x values?

I may not have explained my question very well and I certainly don't even pretend to understand polynomials past the 2nd degree, but given 5 co-efficients that are known when the equation is going to be solved, we should be able to get an answer back?

If I have missing something please let me know.

8. Originally Posted by langers2k
I don't know what a, b, c, d, e will be when I create the program, but at run-time they are fixed. Surely there will be a minimum value of y given a range of x values?
I may not have explained my question very well and I certainly don't even pretend to understand polynomials past the 2nd degree, but given 5 co-efficients that are known when the equation is going to be solved, we should be able to get an answer back?

If I have missing something please let me know.
Well you didn't say that in your statement of the question. The replies you get are only going to be as good as the information you give.

There are standard numerical algorithms for finding the minimum value of a polynomial over a given domain. I believe advice along that line has already been given in one of your other posts.

9. Originally Posted by mr fantastic
Well you didn't say that in your statement of the question. The replies you get are only going to be as good as the information you give.

There are standard numerical algorithms for finding the minimum value of a polynomial over a given domain. I believe advice along that line has already been given in one of your other posts.
Sorry about the confusion, I will take more care next time I post a question to explain it completely.

Have you got any advice for solving the cubic?

Would you recommend a fully algebraic solution or using the Newton method? If I were to use the Newton method, is there any way to come up with reasonable guess to give me the roots?

10. Originally Posted by langers2k
Sorry about the confusion, I will take more care next time I post a question to explain it completely.

Have you got any advice for solving the cubic?

Would you recommend a fully algebraic solution or using the Newton method? If I were to use the Newton method, is there any way to come up with reasonable guess to give me the roots?
A numerical approach with an error tolerance is certainly the best way to go. Do you know that a graphics or CAS calculator can easily do what you're asking ....?

11. kk, Mr. F

I'll be the first to admit I'm not an expert. But I thought what I did respond with was sufficient to get him on the right track, and tbh it sounds like it at least got over the initial hurdle and outlined a basic technique to start the problem, which is what I thought his problem was... where to start?

If he doesn't include actual numbers, I'm not going to spend all day going over every possible combination or result in examples, I'll generalize a little for the sake of simplification. I'm quite aware not all cubics have 3 turning points, but that would certainly be a worst case scenario in this instance (most work).

I apologise if my response confused or was so woefully incorrect that you found it necessary to dress me down, but at least I pinged a light bulb initially.

ttyl

12. Originally Posted by mr fantastic
Do you know that a graphics or CAS calculator can easily do what you're asking ....?
Incidentally, unless you're suggesting a graphics calculator with a program thats designed to show all the working steps in solving a cubic, I don't think thats what he's after. The "user input constants" were included because the formula needs to be applied to a program, not just a one time solution with the inbuilt graphing functions of a calculator.

I use a website QuickMath Automatic Math Solutions to simplify my equations and things, as well as performing various functions, however I haven't played around with it enough to know whether it gives a descent cubic solving function. Though it does do a nice job of showing each and every step, you can leave your formula in the ax^2 + bx + c stage and see the final position of each constant in the end formula. That'll cut right past the understanding of each solving step if you're only interested in getting your program/simulator running. It will however give quite messy equations, but at least they work :S

-----------------------------------------------------

I had a quick look at some techniques for solving cubics in the material I have, your best bet is to just google around and find something that works for you if you want to understand the process, theres heaps of good stuff out there, rather than getting only 1 type of solution. The reason there are more than one way of solving things (other than being mathematically possible) is because some people find certain ways of doing things easier than others. So shop around and find something that works for you. I can give you a bunch of links to some good material on cubics and how to solve them logically, but nothing better than you'll find yourself if you google a bit. But I'm sure theres someone willing to run through one process with you here (i'm just unfortunately not one of them).

G'luck.

13. Originally Posted by Makka
[snip]I apologise if my response confused or was so woefully incorrect that you found it necessary to dress me down, but at least I pinged a light bulb initially.

ttyl
It was hardly a dressing down. But if that's how it came across to you, then here:

The missing ingredient, which we now know, was the fact that the values of a, b, c, d, and e are input data.