Given a quadratic function ax2 + bx + c. Find the maximum and minimum value of the function possible when x is varied for all real values possible.
Input: a = 1, b = -4, c = 4 Output: Maxvalue = Infinity Minvalue = 0 Quadratic function given is x2 -4x + 4 At x = 2, value of the function is equal to zero. Input: a = -1, b = 3, c = -2 Output: Maxvalue = 0.25 Minvalue = -Infinity
Q(x)=ax2 + bx + c. =a(x + b/(2a))2 + c-b2/(4a). first part second part
The function is broken into two parts.
The first part is a perfect square function. There can be two cases:
- Case 1: If value of a is positive.
- The maximum value would be equal to Infinity.
- The minimum value of the function will come when the first part is equal to zero because minimum value of a square function is zero.
- Case 2: If value of a is negative.
- The minimum value would be equal to -Infinity.
- Since a is negative, the task to maximize the negative square function.Again maximum value of a negative square function would be equal to zero as it would be a negative value for any other value of x.
The second part is a constant value for a given quadratic function and hence cannot change for any value of x. Hence it will be added in both the cases. Hence the answer to the problem is:
If a > 0, Maxvalue = Infinity Minvalue = c - b2 / (4a) If a < 0, Maxvalue = c - b2 / (4a) Minvalue = -Infinity
Below is the implementation of the above approach:
Maxvalue = 0.25 Minvalue = -Infinity
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find Maximum and Minimum of two numbers using Absolute function
- Sum of first N terms of Quadratic Sequence 3 + 7 + 13 + ...
- Find the quadratic equation from the given roots
- Check whether one root of the Quadratic Equation is twice of other or not
- Check if roots of a Quadratic Equation are reciprocal of each other or not
- Roots of the quadratic equation when a + b + c = 0 without using Shridharacharya formula
- Find if two given Quadratic equations have common roots or not
- Program to find the Roots of Quadratic equation
- Boundary Value Analysis : Nature of Roots of a Quadratic equation
- Program to find number of solutions in Quadratic Equation
- Check if roots of a Quadratic Equation are numerically equal but opposite in sign or not
- Number of subarrays whose minimum and maximum are same
- Find the maximum possible value of the minimum value of modified array
- Minimum and maximum possible length of the third side of a triangle
- Find maximum and minimum distance between magnets
- Maximum and Minimum Values of an Algebraic Expression
- Minimum and Maximum number of pairs in m teams of n people
- Maximum and minimum sums from two numbers with digit replacements
- Sum of Maximum and Minimum prime factor of every number in the Array
- Break a number such that sum of maximum divisors of all parts is minimum
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.