Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1

LAB 4 FINDING ABSOLUTE EXTREMA OF FUNCTIONS

Matlab can be effectively used to discover or locate the absolute extrema that is
absolute maximum and minimum values of a function.

In Matlab we have a built-in function fminbnd for figuring out the absolute
maximum and minimum values of a function on a given interval. This function also
reveals or identifies the points in the domain of function, where a function has
absolute maximum and absolute minimum values. Let us demonstrate this by
writing a program in Matlab.

In this program the user is asked to input a function as inline function of which we
want to find the absolute maximum and minimum values. The user is also asked
to input the initial and final points of an interval.

So open the Matlab editor and write the following program.

clc;
clear all;

% Create symbolic variable x

syms x

f = input('Enter the function of which we want to find max and min values as
inline function \n f = ');

xi = input('Enter the initial point of interval \n xi = ');

xf = input('Enter the final point of interval \n xf = ');

% Find the minimum value of function


% And the point where function takes the minimum value

[xmin, fminval] = fminbnd(char(f(x)),xi , xf);

% Find the maximum value of function.


% And the point where function takes the maximum value.

[xmax, fmaxval] = fminbnd(char(-f(x)),xi,xf);

% Display the maximum and minimum values of function.


% Also display the points at which maximum and minimum value of function
2

% occurs.

fprintf('The absolute minimum value of function is at the point %.3f\n',


xmin);
fprintf('The absolute minimum value of function at this point is %.3f\n',
fminval);

fprintf('The absolute maximum value of function is at the point %.3f\n',


xmax);
fprintf('The absolute maximum value of function at this point is %.3f\n',
abs(fmaxval));

Let us run the above program for finding the absolute maximum and minimum
values of function f(x) = x2 – 2*x -3 on the interval [-2 3]

Run the program as follows and get the desired output.

Enter the function of which we want to find max and min values as inline function

f = inline(char(x^2 -2*x -3))

Enter the initial point of interval

xi = -2

Enter the final point of interval

xf = 3

The output of the program is the following

The absolute minimum value of function is at the point 1.000

The absolute minimum value of function at this point is -4.000

The absolute maximum value of function is at the point -2.000

The absolute maximum value of function at this point is 5.000

PRACTICAL APPLICATIONS
3

There are many practical applications in which we need to find the maximum and
minimum values of a certain function.

A few examples are

1. A manufacturing company needs to find out what quantity of production


will give the maximum profit?
2. A farmer wants to know, what is the appropriate quantity of fertilizer which
will give the maximum crop production?

We take an example of practical application as maximizing profit of a company.

Suppose a company manufactures laptops. The total profit (in dollars) from
manufacturing and selling x laptops is given by the following profit function.

P(x) = -0.02x2 + 300x -200000 (0 ≤ x ≤ 20000)

Now the question is how many laptops company should produce to maximize its
profit?

This implies we have to find the absolute maximum of profit function on the
interval [0 20000] . And at what value of x the maximum profit occurs.

So open the Matlab editor and write the following program.


clc;
clear all;

% Create Symbolic Variable x

syms x

P = input('Enter the profit function as inline function \n P(x) = ');

xi = input('Enter the initial point of interval \n xi = ');

xf = input('Enter the final point of interval \n xf = ');

% Find the maximum value of function.


% And the point where function takes the maximum value.

[xmax, fmaxval] = fminbnd(char(-P(x)),xi,xf);


4

fprintf('The absolute maximum value of profit function is at the point %.3f\


n', xmax);
fprintf('The absolute maximum value of profit function at this point is %.3f\
n', abs(fmaxval));

Run the program as follows and get the desired output

Enter the profit function as inline function

P(x) = inline(char(-0.02*x^2 + 300*x -200000))

Enter the initial point of interval

xi = 0

Enter the final point of interval

xf = 20000

The output of the program is the following.

The absolute maximum value of profit function is at the point 7500.000

The absolute maximum value of profit function at this point is 925000.000

Thus, by producing 7500 laptops, company will realize the maximum profit of
925000 dollars.

You might also like