In: Computer Science
2. A rancher has set out to fence off a new rectangular pasture for her horses. She has 1000 feet of fencing to fence off as large an area as possible. She wants to give the horses some water access, so she is building the pasture along a river, which will not need fencing. (a) Write a function, P(x), that describes the area of the pasture as a function of its length, x. (Don’t need Python for this.) (b) Plot a graph of P(x) for all practical values of x. (c) In Calculus, you will learn (or review) how to find maximum and minimum values by taking the derivative (diff) and setting it equal to zero (solve). Use this idea and these commands to find the dimensions that will create the maximum pasture area. − NEEDS TO BE IN PYTHON
We need to first create a function in terms of x (length of rectangular pasture).
As the perimeter of the pasture fence is given as 1000 feet, so
perimeter of fence = l + b (Since perimeter of a rectangle is twice the sum of length and breath, So
so let's find out breadth from here in terms of length of rectangular pasture, so
Let's represent length with letter x instead of l, so that the function is in terms of x
So finally,
------------ Eq. 1
Now the area of a rectangle is length times breadth,
let area be represented by A(x), then
So this is the area A(x) of pasture in terms of length x.
Following is a python code to plot Area vs length of pasture :
Plot generated from above code :
Now to find the length which produces maximum area, we need to differentiate A(x) wrt x :
So derivative is 500 - 2*x, Now putting this derivative to zero will give the maximum for the above plotted graph.
For length 250 feet of the rectangular pasture, area would be maximum.
We can use a sympy module in python to carry out these procedures. Below is the code for the same :
The code above uses the area() function defined earlier in the answer, to calculate area corresponding to maximum length found via find_extremums() method.