Max Min



The MIN function returns the smallest value of the selected column. The MAX function returns the largest value of the selected column. Verify that your result is a maximum or minimum value using the first or second derivative test for extrema. The following problems range in difficulty from average to challenging. PROBLEM 1: Find two nonnegative numbers whose sum is 9 and so that the product of one number and the square of the other number is a maximum. Brannan & Sons Digital Max Min Greenhouse Thermometer - Monitor Maximum and Minimum Temperatures for Use in The Garden Greenhouse or Home & Can Be Used Indoor or Outdoor Easily Wall Mounted. 4.2 out of 5 stars. Feb 27, 2021 Minimum element is 1 Maximum element is 3000 Time Complexity: O (n) In this method, the total number of comparisons is 1 + 2 (n-2) in the worst case and 1 + n – 2 in the best case. In the above implementation, the worst case occurs when elements are sorted in descending order and the best case occurs when elements are sorted in ascending order.

Show Mobile NoticeShow All NotesHide All Notes
You appear to be on a device with a 'narrow' screen width (i.e. you are probably on a mobile phone). Due to the nature of the mathematics on this site it is best views in landscape mode. If your device is not in landscape mode many of the equations will run off the side of your device (should be able to scroll to see them) and some of the menu items will be cut off due to the narrow screen width.

Section 4-4 : Finding Absolute Extrema

It’s now time to see our first major application of derivatives in this chapter. Given a continuous function, (fleft( x right)), on an interval (left[ {a,b} right]) we want to determine the absolute extrema of the function. To do this we will need many of the ideas that we looked at in the previous section.

First, since we have a closed interval (i.e. and interval that includes the endpoints) and we are assuming that the function is continuous the Extreme Value Theorem tells us that we can in fact do this. This is a good thing of course. We don’t want to be trying to find something that may not exist.

Next, we saw in the previous section that absolute extrema can occur at endpoints or at relative extrema. Also, from the previous section that we know that the list of critical points is also a list of all possible relative extrema. So, the endpoints along with the list of all critical points will in fact be a list of all possible absolute extrema.

Now we just need to recall that the absolute extrema are nothing more than the largest and smallest values that a function will take so all that we really need to do is get a list of possible absolute extrema, plug these points into our function and then identify the largest and smallest values.

Here is the procedure for finding absolute extrema.

Finding Absolute Extrema of (fleft( x right)) on (left[ {a,b} right])

  1. Verify that the function is continuous on the interval (left[ {a,b} right]).
  2. Find all critical points of (fleft( x right)) that are in the interval (left[ {a,b} right]). This makes sense if you think about it. Since we are only interested in what the function is doing in this interval we don’t care about critical points that fall outside the interval.
  3. Evaluate the function at the critical points found in step 1 and the end points.
  4. Identify the absolute extrema.

There really isn’t a whole lot to this procedure. We called the first step in the process step 0, mostly because all of the functions that we’re going to look at here are going to be continuous, but it is something that we do need to be careful with. This process will only work if we have a function that is continuous on the given interval. The most labor intensive step of this process is the second step (step 1) where we find the critical points. It is also important to note that all we want are the critical points that are in the interval.

Let’s do some examples.

Example 1 Determine the absolute extrema for the following function and interval. [gleft( t right) = 2{t^3} + 3{t^2} - 12t + 4hspace{0.25in}{mbox{on}}hspace{0.25in}left[ { - 4,2} right]] Show Solution

All we really need to do here is follow the procedure given above. So, first notice that this is a polynomial and so is continuous everywhere and therefore is continuous on the given interval.

Now, we need to get the derivative so that we can find the critical points of the function.

[g'left( t right) = 6{t^2} + 6t - 12 = 6left( {t + 2} right)left( {t - 1} right)]

It looks like we’ll have two critical points, (t = - 2) and (t = 1). Note that we actually want something more than just the critical points. We only want the critical points of the function that lie in the interval in question. Both of these do fall in the interval as so we will use both of them. That may seem like a silly thing to mention at this point, but it is often forgotten, usually when it becomes important, and so we will mention it at every opportunity to make sure it’s not forgotten.

Now we evaluate the function at the critical points and the end points of the interval.

[begin{align*}gleft( { - 2} right) & = 24hspace{1.0in} & gleft( 1 right) & = - 3 gleft( { - 4} right) &= - 28hspace{1.0in} & gleft( 2 right) & = 8end{align*}]

Absolute extrema are the largest and smallest the function will ever be and these four points represent the only places in the interval where the absolute extrema can occur. So, from this list we see that the absolute maximum of (gleft( t right)) is 24 and it occurs at (t = - 2) (a critical point) and the absolute minimum of (gleft( t right)) is -28 which occurs at (t = - 4) (an endpoint).

In this example we saw that absolute extrema can and will occur at both endpoints and critical points. One of the biggest mistakes that students make with these problems is to forget to check the endpoints of the interval.

Example 2 Determine the absolute extrema for the following function and interval. [gleft( t right) = 2{t^3} + 3{t^2} - 12t + 4hspace{0.25in}{mbox{on}}hspace{0.25in}left[ {0,2} right]] Show Solution

Note that this problem is almost identical to the first problem. The only difference is the interval that we’re working on. This small change will completely change our answer however. With this change we have excluded both of the answers from the first example.

The first step is to again find the critical points. From the first example we know these are (t = - 2) and (t = 1).. At this point it’s important to recall that we only want the critical points that actually fall in the interval in question. This means that we only want (t = 1) since (t = - 2) falls outside the interval.

Now evaluate the function at the single critical point in the interval and the two endpoints.

[gleft( 1 right) = - 3hspace{0.5in}gleft( 0 right) = 4hspace{0.5in}gleft( 2 right) = 8]

From this list of values we see that the absolute maximum is 8 and will occur at (t = 2) and the absolute minimum is -3 which occurs at (t = 1).

As we saw in this example a simple change in the interval can completely change the answer. It also has shown us that we do need to be careful to exclude critical points that aren’t in the interval. Had we forgotten this and included (t = - 2) we would have gotten the wrong absolute maximum!

This is the other big mistakes that students make in these problems. All too often they forget to exclude critical points that aren’t in the interval. If your instructor is anything like me this will mean that you will get the wrong answer. It’s not too hard to make sure that a critical point outside of the interval is larger or smaller than any of the points in the interval.

Max MinExample 3 Suppose that the population (in thousands) of a certain kind of insect after (t) months is given by the following formula. [Pleft( t right) = 3,t + sin left( {4t} right) + 100]

Determine the minimum and maximum population in the first 4 months.

Show Solution

The question that we’re really asking is to find the absolute extrema of (Pleft( t right)) on the interval (left[ {0,4} right]). Since this function is continuous everywhere we know we can do this.

Let’s start with the derivative.

[P'left( t right) = 3 + 4cos left( {4t} right)]

We need the critical points of the function. The derivative exists everywhere so there are no critical points from that. So, all we need to do is determine where the derivative is zero.

[begin{align*}3 + 4cos left( {4t} right) & = 0 cos left( {4t} right) & = - frac{3}{4}end{align*}]

The solutions to this are,

[begin{array}{*{20}{c}}{4t = 2.4189 + 2pi n,n = 0, pm 1, pm 2, ldots }{4t = 3.8643 + 2pi n,n = 0, pm 1, pm 2, ldots }end{array}hspace{0.25in} Rightarrow hspace{0.25in}begin{array}{*{20}{c}}{t = 0.6047 + displaystyle frac{{pi n}}{2},n = 0, pm 1, pm 2, ldots }{t = 0.9661 + displaystyle frac{{pi n}}{2},n = 0, pm 1, pm 2, ldots }end{array}]

So, these are all the critical points. We need to determine the ones that fall in the interval (left[ {0,4} right]). There’s nothing to do except plug some (n)’s into the formulas until we get all of them.

(n = 0) :

[t = 0.6047hspace{1.0in}t = 0.9661]

We’ll need both of these critical points.

(n = 1)

Min [t = 0.6047 + frac{pi }{2} = 2.1755hspace{1.0in}t = 0.9661 + frac{pi }{2} = 2.5369]

We’ll need these.

(n = 2)

[t = 0.6047 + pi = 3.7463hspace{1.0in}t = 0.9661 + pi = 4.1077]

In this case we only need the first one since the second is out of the interval.

There are five critical points that are in the interval. They are,

[0.6047,0.9661,2.1755,2.5369,3.7463]

Finally, to determine the absolute minimum and maximum population we only need to plug these values into the function as well as the two end points. Here are the function evaluations.

[begin{align*}Pleft( 0 right) & = 100.0hspace{1.0in} & Pleft( 4 right) & = 111.7121 Pleft( {0.6047} right) & = 102.4756hspace{1.0in} & Pleft( {0.9661} right) & = 102.2368 Pleft( {2.1755} right) & = 107.1880hspace{1.0in} & Pleft( {2.5369} right) & = 106.9492 Pleft( {3.7463} right) & = 111.9004 & & end{align*}]

From these evaluations it appears that the minimum population is 100,000 (remember that (P) is in thousands…) which occurs at (t = 0) and the maximum population is 111,900 which occurs at (t = 3.7463).

Make sure that you can correctly solve trig equations. If we had forgotten the (2pi n) we would have missed the last three critical points in the interval and hence gotten the wrong answer since the maximum population was at the final critical point.

Also, note that we do really need to be very careful with rounding answers here. If we’d rounded to the nearest integer, for instance, it would appear that the maximum population would have occurred at two different locations instead of only one.

Example 4 Suppose that the amount of money in a bank account after (t) years is given by, [Aleft( t right) = 2000 - 10t{{bf{e}}^{5 - frac{{{t^2}}}{8}}}]

Determine the minimum and maximum amount of money in the account during the first 10 years that it is open.

Show Solution

Here we are really asking for the absolute extrema of (Aleft( t right)) on the interval (left[ {0,10} right]). As with the previous examples this function is continuous everywhere and so we know that this can be done.

We’ll first need the derivative so we can find the critical points.

[begin{align*}A'left( t right) & = - 10{{bf{e}}^{5 - frac{{{t^2}}}{8}}} - 10t{{bf{e}}^{5 - frac{{{t^2}}}{8}}}left( { - frac{t}{4}} right) & = 10{{bf{e}}^{5 - frac{{{t^2}}}{8}}}left( { - 1 + frac{{{t^2}}}{4}} right)end{align*}]

The derivative exists everywhere and the exponential is never zero. Therefore, the derivative will only be zero where,

[ - 1 + frac{{{t^2}}}{4} = 0hspace{0.25in}, Rightarrow hspace{0.25in},{t^2} = 4hspace{0.5in} Rightarrow hspace{0.25in},t = pm 2]

We’ve got two critical points, however only (t = 2) is actually in the interval so that is only critical point that we’ll use.

Let’s now evaluate the function at the lone critical point and the end points of the interval. Here are those function evaluations.

[Aleft( 0 right) = 2000hspace{0.5in}Aleft( 2 right) = 199.66hspace{0.5in}Aleft( {10} right) = 1999.94]

So, the maximum amount in the account will be $2000 which occurs at (t = 0) and the minimum amount in the account will be $199.66 which occurs at the 2 year mark.

In this example there are two important things to note. First, if we had included the second critical point we would have gotten an incorrect answer for the maximum amount so it’s important to be careful with which critical points to include and which to exclude.

All of the problems that we’ve worked to this point had derivatives that existed everywhere and so the only critical points that we looked at were those for which the derivative is zero. Do not get too locked into this always happening. Most of the problems that we run into will be like this, but they won’t all be like this.

Let’s work another example to make this point.

Example 5 Determine the absolute extrema for the following function and interval. [Qleft( y right) = 3y{left( {y + 4} right)^{frac{2}{3}}}hspace{0.5in}{mbox{on}}hspace{0.5in}left[ { - 5, - 1} right]] Show Solution

Again, as with all the other examples here, this function is continuous on the given interval and so we know that this can be done.

First, we’ll need the derivative and make sure you can do the simplification that we did here to make the work for finding the critical points easier.

[begin{align*}Q'left( y right) & = 3{left( {y + 4} right)^{frac{2}{3}}} + 3yleft( {frac{2}{3}} right){left( {y + 4} right)^{ - frac{1}{3}}} & = 3{left( {y + 4} right)^{frac{2}{3}}} + frac{{2y}}{{{{left( {y + 4} right)}^{frac{1}{3}}}}} & = frac{{3left( {y + 4} right) + 2y}}{{{{left( {y + 4} right)}^{frac{1}{3}}}}} & = frac{{5y + 12}}{{{{left( {y + 4} right)}^{frac{1}{3}}}}}end{align*}]

So, it looks like we’ve got two critical points.

[begin{align*}y & = - 4hspace{0.5in} & & {mbox{Because the derivative doesn't exist here.}} y & = - frac{{12}}{5} hspace{0.5in} & & {mbox{Because the derivative is zero here.}}end{align*}]

Both of these are in the interval so let’s evaluate the function at these points and the end points of the interval.

[begin{align*}Qleft( { - 4} right) & = 0 & hspace{0.5in} & & Qleft( { - frac{{12}}{5}} right) & = - 9.849 Qleft( { - 5} right) & = - 15 & hspace{0.5in} & & Qleft( { - 1} right) & = - 6.241end{align*}]

The function has an absolute maximum of zero at (y = - 4) and the function will have an absolute minimum of -15 at (y = - 5).

So, if we had ignored or forgotten about the critical point where the derivative doesn’t exist ((y = - 4)) we would not have gotten the correct answer.

In this section we’ve seen how we can use a derivative to identify the absolute extrema of a function. This is an important application of derivatives that will arise from time to time so don’t forget about it.

This chapter is dedicated to min and max function in R. min function in R – min(), is used to calculate the minimum of vector elements or minimum of a particular column of a dataframe. minimum of a group can also calculated using min() function in R by providing it inside the aggregate function. max(), is used to calculate the maximum of vector elements or maximum of a particular column of a dataframe. maximum of a group can also calculated using max() function in R by providing it inside the aggregate function. row wise maximum and minimum is calculated using max() and min() function with the help of dplyr package. we also calculates column wise maximum and column wise minimum. lets see an example of each.

Max Minelli

  • min() function in R computes the minimum value of a vector or data frame.
  • max() function in R computes the maximum value of a vector or data frame.
  • column wise maximum and minimum of the dataframe using max() and min() function.
  • Row wise maximum and minimum of the dataframe in R using max() and min() function.
  • maximum and minimum value of the group is calculated using max() and min() along with aggregate() and dplyr packages.

Syntax for min and Max function in R:

min(x, na.rm = FALSE)

max(x, na.rm = FALSE)

  • x – is numeric or character vector
  • na.rm – a logical indicating whether missing values should be removed.

Example of Max function in R:

output:

Example of Max function in R with NA:

Max function doesn’t give desired output, If NAs are present in the vector. So it has to be handled by using na.rm=TRUE in max() function

output:
[1] 12.345

Example of Max function in R with character vector:

output:

Example of max() function in R dataframe:

Lets create the data frame to demonstrate max function – max() in r

so the resultant dataframe will be

maximum value of a column in R data frame using max() function :

Max Min Hackerrank Solution

max() function takes the column name as argument and calculates the maximum value of that particular column

so the resultant maximum value of the “Price” column will be

output:

[1] 120

column wise maximum using max() function:

max() function is applied to the required column through mapply() function, so that it calculates the maximum value of required columns as shown below.

so the resultant maximum value of “Price” and “Tax” columns will be

Maximum value of the column by group using max() function

aggregate() function along with the max() function calculates the maximum value of a group. here maximum of “Price” column, for “Item_Group” is calculated.

Item_group has three groups “Dairy”,”Fruit” & “Vegetable”. maximum price for each group is calculated as shown below

Row wise maximum using max() function along with dplyr

Row wise maximum is calculated with the help rowwise() function of dplyr package and max() function as shown below

row wise max of “Price” and “Tax” is calculated and populated for each row as shown below

Example of Min function in R:

output:

Example of Min function in R with NA:

Min function doesn’t give desired output, If NAs are present in the vector. so it has to be handled by using na.rm=TRUE in min() function

output:
[1] -14.567

Example of Min function in R with character vector:

output:

Example of min() function in R dataframe:

Lets create the data frame to demonstrate min function – min() in r

so the resultant dataframe will be

minimum value of a column in R data frame using min() function :

min() function takes the column name as argument and calculates the minimum value of that particular column

so the resultant minimum value of the “Price” column will be

output:

[1] 25

column wise minimum using min() function:

min() function is applied to the required column through mapply() function, so that it calculates the minimum value of required columns as shown below.

so the resultant minimum value of “Price” and “Tax” columns will be

Minimum value of the column by group using min() function

aggregate() function along with the min() function calculates the minimum value of a group. here minimum of “Price” column, for “Item_Group” is calculated.

Item_group has three groups “Dairy”,”Fruit” & “Vegetable”. minimum price for each group is calculated as shown below

Row wise minimum using min() function along with dplyr

Row wise minimum is calculated with the help rowwise() function of dplyr package and min() function as shown below

row wise min of “Price” and “Tax” is calculated and populated for each row as shown below

For further understanding of min() and max() function in R using dplyr one can refer the dplyr documentation

Min

Other Related Topics: