ON USING SAGE TO SOLVE CONSTRAINED OPTIMIZATION PROBLEMS APPLYING THE LAGRANGE MULTIPLIERS METHOD

Similar documents
Method To Solve Linear, Polynomial, or Absolute Value Inequalities:

Linear Programming Notes V Problem Transformations

Linear Programming for Optimization. Mark A. Schulze, Ph.D. Perceptive Scientific Instruments, Inc.

1.7 Graphs of Functions

Lines & Planes. Packages: linalg, plots. Commands: evalm, spacecurve, plot3d, display, solve, implicitplot, dotprod, seq, implicitplot3d.

12.6 Logarithmic and Exponential Equations PREPARING FOR THIS SECTION Before getting started, review the following:

Numerical Analysis. Professor Donna Calhoun. Fall 2013 Math 465/565. Office : MG241A Office Hours : Wednesday 10:00-12:00 and 1:00-3:00

Computational Mathematics with Python

NEW YORK STATE TEACHER CERTIFICATION EXAMINATIONS

(a) We have x = 3 + 2t, y = 2 t, z = 6 so solving for t we get the symmetric equations. x 3 2. = 2 y, z = 6. t 2 2t + 1 = 0,

DERIVATIVES AS MATRICES; CHAIN RULE

x 2 + y 2 = 1 y 1 = x 2 + 2x y = x 2 + 2x + 1

Economics 2020a / HBS 4010 / HKS API-111 FALL 2010 Solutions to Practice Problems for Lectures 1 to 4

Algebra Unpacked Content For the new Common Core standards that will be effective in all North Carolina schools in the school year.

SECOND DERIVATIVE TEST FOR CONSTRAINED EXTREMA

Computational Mathematics with Python

Computational Mathematics with Python

2 Integrating Both Sides

5 Systems of Equations

This unit will lay the groundwork for later units where the students will extend this knowledge to quadratic and exponential functions.

A QUICK GUIDE TO THE FORMULAS OF MULTIVARIABLE CALCULUS

Big Ideas in Mathematics

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

Current Standard: Mathematical Concepts and Applications Shape, Space, and Measurement- Primary

Support Vector Machines Explained

Clovis Community College Core Competencies Assessment Area II: Mathematics Algebra

Using the Simplex Method to Solve Linear Programming Maximization Problems J. Reeb and S. Leavengood

Module1. x y 800.

CORRELATED TO THE SOUTH CAROLINA COLLEGE AND CAREER-READY FOUNDATIONS IN ALGEBRA

Nonlinear Algebraic Equations. Lectures INF2320 p. 1/88

Least-Squares Intersection of Lines

3.3. Solving Polynomial Equations. Introduction. Prerequisites. Learning Outcomes

Algebra I Notes Relations and Functions Unit 03a

Application. Outline. 3-1 Polynomial Functions 3-2 Finding Rational Zeros of. Polynomial. 3-3 Approximating Real Zeros of.

Math 53 Worksheet Solutions- Minmax and Lagrange

Linear Algebra Notes for Marsden and Tromba Vector Calculus

Algebra Academic Content Standards Grade Eight and Grade Nine Ohio. Grade Eight. Number, Number Sense and Operations Standard

South Carolina College- and Career-Ready (SCCCR) Algebra 1

Machine Learning and Data Mining. Regression Problem. (adapted from) Prof. Alexander Ihler

Factoring Patterns in the Gaussian Plane

Basic Use of the TI-84 Plus

1 Solving LPs: The Simplex Algorithm of George Dantzig

DRAFT. Algebra 1 EOC Item Specifications

Pre-Algebra Academic Content Standards Grade Eight Ohio. Number, Number Sense and Operations Standard. Number and Number Systems

Mathematics Curriculum Guide Precalculus Page 1 of 12

Classroom Tips and Techniques: The Student Precalculus Package - Commands and Tutors. Content of the Precalculus Subpackage

Unit 7: Radical Functions & Rational Exponents

Grade 5 Math Content 1

Matrices 2. Solving Square Systems of Linear Equations; Inverse Matrices

Microeconomic Theory: Basic Math Concepts

Quickstart for Desktop Version

Experiment #1, Analyze Data using Excel, Calculator and Graphs.

A Concrete Introduction. to the Abstract Concepts. of Integers and Algebra using Algebra Tiles

POLYNOMIAL FUNCTIONS

Increasing for all. Convex for all. ( ) Increasing for all (remember that the log function is only defined for ). ( ) Concave for all.

Course Outlines. 1. Name of the Course: Algebra I (Standard, College Prep, Honors) Course Description: ALGEBRA I STANDARD (1 Credit)

Vectors 2. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

South Carolina College- and Career-Ready (SCCCR) Pre-Calculus

Linear Algebra and TI 89

Operation Count; Numerical Linear Algebra

Linear Programming. Solving LP Models Using MS Excel, 18

Prentice Hall: Middle School Math, Course Correlated to: New York Mathematics Learning Standards (Intermediate)

24. The Branch and Bound Method

Understanding Basic Calculus

Overview. Essential Questions. Precalculus, Quarter 4, Unit 4.5 Build Arithmetic and Geometric Sequences and Series

Determine If An Equation Represents a Function

Common Core Unit Summary Grades 6 to 8

Constrained optimization.

MEMORANDUM. All students taking the CLC Math Placement Exam PLACEMENT INTO CALCULUS AND ANALYTIC GEOMETRY I, MTH 145:

FACTORING POLYNOMIALS IN THE RING OF FORMAL POWER SERIES OVER Z

MATH BOOK OF PROBLEMS SERIES. New from Pearson Custom Publishing!

Section 1. Inequalities

BookTOC.txt. 1. Functions, Graphs, and Models. Algebra Toolbox. Sets. The Real Numbers. Inequalities and Intervals on the Real Number Line

Performance Level Descriptors Grade 6 Mathematics

Guide to Using the Ti-nspire for Methods - The simple and the overcomplicated Version 1.5

In mathematics, there are four attainment targets: using and applying mathematics; number and algebra; shape, space and measures, and handling data.

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

North Carolina Math 2

Examples of Tasks from CCSS Edition Course 3, Unit 5

SCIENTIFIC COMPUTING AND PROGRAMMING IN THE CLOUD USING OPEN SOURCE PLATFORMS: AN ILLUSTRATION USING WEIGHTED VOTING SYSTEMS

Algebra I Vocabulary Cards

Algebra 1 Course Information

Sequences. A sequence is a list of numbers, or a pattern, which obeys a rule.

Creating, Solving, and Graphing Systems of Linear Equations and Linear Inequalities

1 Review of Least Squares Solutions to Overdetermined Systems

Nonlinear Programming Methods.S2 Quadratic Programming

Chapter 4 Online Appendix: The Mathematics of Utility Functions

Prentice Hall Algebra Correlated to: Colorado P-12 Academic Standards for High School Mathematics, Adopted 12/2009

The Fourth International DERIVE-TI92/89 Conference Liverpool, U.K., July Derive 5: The Easiest... Just Got Better!

6.4 Logarithmic Equations and Inequalities

The Cobb-Douglas Production Function

MATH 132: CALCULUS II SYLLABUS

8 Polynomials Worksheet

Linear Programming I

KEANSBURG SCHOOL DISTRICT KEANSBURG HIGH SCHOOL Mathematics Department. HSPA 10 Curriculum. September 2007

Constrained Optimization: The Method of Lagrange Multipliers:

Decimals and Percentages

Note on growth and growth accounting

Algebra I Credit Recovery

Mathematical goals. Starting points. Materials required. Time needed

Transcription:

ON USING SAGE TO SOLVE CONSTRAINED OPTIMIZATION PROBLEMS APPLYING THE LAGRANGE MULTIPLIERS METHOD Maria do Carmo Martins, PhD CMATI & Department of Mathematics, University of Azores, Portugal Francisco Martins, PhD LaSIGE & Department of Informatics, Faculty of Sciences, University of Lisbon, Portugal Abstract: This paper combines Calculus and Programming to solve constrained optimization problems common in many areas, notably in Economics. It uses Lagrange multipliers, a well-known technique for maximizing (or minimizing) functions, and the free open-source mathematics software system Sage to compute the maximum (minimum) automatically. Moreover, Sage can be used interactively to work out the solution and to graphically interpret the results, which we find a valuable and practical approach in teaching such techniques to the undergraduate level. In this paper we carry out an exercise describing how these three interdisciplinary areas can work together. Key Words: Constrained optimization problems; Octave programming language; Lagrange multipliers method Introduction Finding the extrema of a function subjected to some restriction is a well-studied problem in Mathematics with multiple, direct applications in Economics. For instance, it is plausible for a company to determine the amount of units of each product it must produce in order to maximizing its profits. Mathematical Analysis and Operational Research come into the rescue by providing tools for solving this kind of problems. Techniques like computing function derivatives or the Dantzig's Simplex algorithm [1] are the recurrent candidates, depending on the problem at hand (i.e., linear vs. non-linear problem). In this paper we stick to the methods provided by Mathematical Analysis, which are usually part of the undergraduate Calculus curricula. The novelty we propose is the using of mathematical software, in particular Sage, to interactively solve the problem and to help in visualizing the solution. We believe that using this approach is more appealing and enlightening for undergraduate students to grasp both the theoretical and the practical aspects of these methods. Sage [2] is a high-level, open-source programmable system targeted to symbolic computation (amongst other things). Unlike the programming languages Fortran, C, or Java, Sage positions itself at a much higher level of abstraction, providing an environment for finding the exact roots of systems of non-linear equations, compute matrix inverses, integrate and differentiate functions, or plotting solutions graph of a differential equation, to name a few of its features. We find that mastering such a tool (free of costs) can be of invaluable help, not just for the application we propose in this paper, but for many other subjects (e.g., Algebra, Statistics). We use a very simple example throughout the paper: A company wants to find its maximum production level that is modeled by the Cobb- Douglas function [3], where represents the units of labor and represents the units of capital. Each labor unit costs 150 and each capital unit costs 250. The total expenses for labor and capital cannot exceed 40 000. In this paper we recall how to solve this problem using the Lagrange multipliers [4, 5] and then illustrate how Sage becomes very handy in computing and illustrating how the method works. 49

The main text of the paper is organized as follows. The first section sets the mathematical grounds for the problem and recalls the application of the Lagrange multipliers method; the second section gives a brief introduction to Sage presenting the features needed for solving the running problem; finally, the third section illustrates the usage of Sage to solve, to visualize, and to understand the solution to the problem. Main Text Optimizing using Lagrange multipliers method In general, a problem of finding the local maximum (resp. minimum) of a function subjected to some restriction equation can be directly solved by using two systems of equations, one for and, another for its first derivatives, provided that both functions have continuous first derivatives. Then, inspecting the second derivative of both functions we can decide whether the critical points correspond to a local maximum or minimum. However, this approach is rather cumbersome. The Lagrange multipliers method presents a much more elegant solution and can easily be applied in this situation. The Lagrange function (the Lagrangian) assumes the general form, (1) where is a new variable, denoted the Lagrange multiplier. Briefly, if is a maximum of function, there exists some such that the triple is a stationary point of the Lagrangian, i.e., a point where the first partial derivatives of are zero. The multiplier represents the rate of change in with respect to. The interested reader may refer to [4, 5] for further details on the Lagrange multipliers method. For applying the Lagrange multipliers method to our running example, we start by determining the Lagrangian. The constraint in this problem comes from the fact that The total expenses for labor and capital cannot exceed 40 000 that can be captured by the equation g(x, y) defined as follows 150x + 250y = 40000 Then combining functions f and g as defined in (1), we get the Lagrangian Λ(x, y, λ) = 50x 3/4 y 1/4 λ(150x + 250y 40000) To solve the problem we need to compute the partial derivatives of Λ, provided below Λ x Λ y Λ = 150λ + 75y 1 4 2x 1 4 3 4 = 250λ + 25x = 150x 250y + 40000 λ and determine the stationary point of the Lagrangian by solving the system of non-linear equation formed by the partial derivatives (i.e., Λ/ x = Λ/ y = Λ/ λ = 0) in order to x, y, and λ. Solution to the system is when x = 200, y = 40, and λ = 0.167185. The economical interpretation of the Lagrange multiplier is that it represents the percentage of each additional Euro spent on capital that will turn into production. For example, if an additional 10 000 were spent on capital, then it would be translated into 0.167185 10 000 = 1671.85 additional units of production. If the problem has more than one constraint, then equation (1) needs to account for the additional restriction function and its multiplier. For a new constraint h(x, y) = d equation (1) would be rewritten as Λ(x, y, λ, μ) = f(x, y) + λ(g(x, y) c) + μ(h(x, y) d) Sage in a nutshell Sage convers many areas of Mathematics, namely Algebra, Calculus, Combinatorics, Numerical mathematics, and Number Theory. It is available on Linux, Windows, and Mac OS X operating systems; it is simple to install and present a clean and intuitive environment, making it ideal 2x 3 4 50

for interactive sessions. Its usage can range from a sophisticated calculator to an advanced computer algebra system. Sage is an open source alternative to, and rivals with, Magma [6], Maple [7], Mathematica [8], and MATLAB [9], commercial systems widely used in engineering, science, and economics. We cover variable and function definitions in order to be able to illustrate some symbolic manipulations, in particular for computing partial derivatives, solving systems of equations, and plotting two and three dimension graphics. Symbolic variables are introduced using the var function. For instance, xvar = var ( x ), introduces a symbolic name x and binds it to variable xvar, possibly creating xvar. Then, whenever xvar is used, it refers to the symbolic name x. We usual bind the symbolic name to a variable with the same name. The assignment, yvar = xvar, introduces a new variable yvar that is bound to the same symbolic name x. So, expression yvar + xvar evaluates to 2x. A function is a binding of a name to an expression. (More advanced functions can be created using the Python language.) The function triplesquare that computes the triple of the square of x can be defined as triplesquare = 3 * xvar ^ 2. Expression triplesquare (2) applies function triplesquare to argument 2, yielding number 12. A more interesting feature is plotting the graph of triplesquare between 0 and 5. The task can be easily achieved using plot (triplesquare, (x, 0, 5)). Many additional arguments may be supplied to function plot, like defining colors, graph title, various captions, but we omit such complexity in this paper. Function differentiation and system solving finalize out brief tour on Sage. As for the former, we simply ask Sage triplesquare.diff(xvar). This computes the derivative of triplesquare in order to xvar (symbolic name x), yielding the expected result 6x. The latter is a bit more involved; Function solve accepts as its first argument an equation to be solved. For instance, let us find when triplesquare is zero; Expression solve (triplesquare == 0, xvar) will do the trick and solve yields x = 0. There are two things to notice: the usage of == (double equal sign) to define an equation; the second argument of solve (xvar) indicates the variable in order to which the equation must be solved. In order to solve systems of equations, the first argument is a list of functions. Lists are comma-separated sequences of items (in this case of equations) enclosed in square brackets. The following example is selfexplanatory. solve([x + y == 6, x y == 4], x, y), yielding x = 5 and y = 1 Applying Sage to solve the problem using the Lagrange multipliers method Figure 1 shows an excerpt of a Sage interactive session for addressing the running example. First we introduce three symbolic names x, y, l and bind them to three variables of the same name. Thereafter, we functions f and g. Notice that we define a function for the constraint, not an equation. This way is easier for dealing with g later in the session. However, we can rewrite equation g(x,y) == 40 000 in order to y easily using the solve function. Now we are ready to define the Lagrangian L, which is straightforwardly written using f and g. This line ends with ; L. It is just a form of asking Sage to print the expression in a more convenient and standard notation. The three partial derivatives are obtained from expression L, asking Sage to derive according to some expression variable. In the present case, for instance, L.diff(y), computes L/ y. Determining the stationary point results from the direct application of the solve function. We provide the three equations involving the partial derivatives and ask for the system to be solved in order to x, y, and l. The expecting result appears clean and easy on the screen. The computation could be further condensed and written in a function that just receives L and returns the result. To additionally explore Sage we could plot graphs for the functions in order to better understand and visualize even the mathematical concepts underneath the, sometimes, not well understood notions of partial derivative, system solving, etc. 51

Figure 1: Sage interactive session to solve the running problem We present in Figure 2 a picture that, we believe, illustrates the solution to the problem. The figure is composed of four graphs: in green there is function f; function g is depicted in red; in blue there is a plane marking the 40 000 restricting; and, finally, there is a black circle spotting the maximum. Notice that the mark is in the surface of f, and in the plane that is perpendicular to the blue plane and that passes in the intersection between the red and the blue planes. More graphs could be plotted to investigate the solution, but we leave it to the interested reader. For that reason we decided to include (top of Figure 2) the source code for producing and depicted the graph we present, so the reader can further explore the tool. 52

Figure 2: Graph interpreting the solution to the running example Conclusion We conducted a small experiment to illustrate the use of a tool, notably Sage, to aid in solving a maximization problem using Lagrange multipliers method. It happens that the problem comes from yet a third area of knowledge and that the mathematical solution can be interpreted using terms from that application domain: Economics. These interdisciplinary quests happen to be important for all the involved areas, since Economics benefits from the tools, both theoretical and practical, that have been researched over the years in Mathematics and Computer Science. On the other hand, Mathematics also benefic from this joint venture, since it gets inspiration in real world problems and then can try to come up with problem drove solutions. Computer Science benefits as well: first there is the opportunity for researching these computed aided systems that tackle all sorts of things automatically; moreover, there is the opportunity to disseminate software by different areas and get actual users performing complex tasks with the tools. Often, and unfortunately, the end users discover most of the bugs, performance issues, etc. It is our conviction that this kind of tools should be used when teaching undergraduate and graduate courses, since mastering them constitutes a real benefit for expert end users. 53

References: [1] Murty, Katta G. Linear Programming. John Wiley & Sons, 2002. [2] Sage web site. http://www.sagemath.org. [3] Douglas, Paul, The Cobb-Douglas Production Function Once Again: Its History, Its Testing, and Some New Empirical Values. Journal of Political Economy, 84(5):903-916, 1976. [4] Bertsekas, Dimitri P. Nonlinear Programming (Second ed.). Athena Scientific, 1999. [5] Vapnyarskii, I. B. Lagrange multipliers, in Hazewinkel, Michiel, Encyclopedia of Mathematics, Springer, 2001. [6] Magma web site. http://magma.maths.usyd.edu.au/magma/. [7] Maple web site. http://www.maplesoft.com. [8] Mathematica web site. http://www.wolfram.com/mathematica/. [9] MatLab web site. http://www.mathworks.com/products/matlab/. 54