Find the absolute maximum and the absolute minimum of the function. f(x, y) = 3x + 4y. g(x, y) = x 2 + y 2 = 25.

Similar documents
LESSON 25: LAGRANGE MULTIPLIERS OCTOBER 30, 2017

Let f(x) = x, but the domain of f is the interval 0 x 1. Note

2015 Math Camp Calculus Exam Solution

Partial Fractions. June 27, In this section, we will learn to integrate another class of functions: the rational functions.

8.1 Solutions of homogeneous linear differential equations

CHALLENGE! (0) = 5. Construct a polynomial with the following behavior at x = 0:

Lecture 10: Powers of Matrices, Difference Equations

Math 115 Spring 11 Written Homework 10 Solutions

26. LECTURE 26. Objectives

3 Algebraic Methods. we can differentiate both sides implicitly to obtain a differential equation involving x and y:

Lecture 2e Row Echelon Form (pages 73-74)

Math 2 Variable Manipulation Part 6 System of Equations

Lesson 26 MA Nick Egbert

Math 5a Reading Assignments for Sections

Calculus Example Exam Solutions

DEPARTMENT OF MATHEMATICS AND STATISTICS UNIVERSITY OF MASSACHUSETTS. MATH 233 SOME SOLUTIONS TO EXAM 2 Fall 2018

MATH 1130 Exam 1 Review Sheet

4.4 Graphs of Logarithmic Functions

Math101, Sections 2 and 3, Spring 2008 Review Sheet for Exam #2:

Section 3.1: Definition and Examples (Vector Spaces), Completed

Chapter 1 Review of Equations and Inequalities

MATH 320, WEEK 6: Linear Systems, Gaussian Elimination, Coefficient Matrices

MATH Midterm 1 Sample 4

Math Fundamentals for Statistics I (Math 52) Unit 7: Connections (Graphs, Equations and Inequalities)

LIMITS AND DERIVATIVES

ES.1803 Topic 13 Notes Jeremy Orloff

Algebra. Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

Algebra I - Study Guide for Final

Preface.

Lagrange Multipliers

Cryptography and Network Security Prof. D. Mukhopadhyay Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Math 210 Midterm #2 Review

Algebra Exam. Solutions and Grading Guide

A FLOW DIAGRAM FOR CALCULATING LIMITS OF FUNCTIONS (OF SEVERAL VARIABLES).

Key Point. The nth order linear homogeneous equation with constant coefficients

Math 163: Lecture notes

Rational Functions. Elementary Functions. Algebra with mixed fractions. Algebra with mixed fractions

Some Review Problems for Exam 2: Solutions

Definition of a Logarithm

General Technical Remarks on PDE s and Boundary Conditions Kurt Bryan MA 436

MITOCW watch?v=rf5sefhttwo

Sec. 1 Simplifying Rational Expressions: +

MA 123 September 8, 2016

Slope Fields: Graphing Solutions Without the Solutions

base 2 4 The EXPONENT tells you how many times to write the base as a factor. Evaluate the following expressions in standard notation.

Implicit Differentiation Applying Implicit Differentiation Applying Implicit Differentiation Page [1 of 5]

Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Note 7

MATH 250 TOPIC 13 INTEGRATION. 13B. Constant, Sum, and Difference Rules

CS 542G: Robustifying Newton, Constraints, Nonlinear Least Squares

Computability Crib Sheet

CALCULUS II - Self Test

Math Lecture 4 Limit Laws

Mathematics for Intelligent Systems Lecture 5 Homework Solutions

Definition of a Logarithm

Maple for Math Majors. 3. Solving Equations

Bob Brown Math 251 Calculus 1 Chapter 4, Section 1 Completed 1 CCBC Dundalk

ter. on Can we get a still better result? Yes, by making the rectangles still smaller. As we make the rectangles smaller and smaller, the

Getting Started with Communications Engineering

Algebra Review. Finding Zeros (Roots) of Quadratics, Cubics, and Quartics. Kasten, Algebra 2. Algebra Review

Solving Equations by Adding and Subtracting

Some facts you should know that would be convenient when evaluating a limit:

Exam 2 Study Guide: MATH 2080: Summer I 2016

Eigenvalues and eigenvectors

Investigating Limits in MATLAB

A Level Maths summer preparation work

Solving Linear Equations (in one variable)

Intersecting Two Lines, Part Two

STEP Support Programme. Pure STEP 1 Questions

Definition 8.1 Two inequalities are equivalent if they have the same solution set. Add or Subtract the same value on both sides of the inequality.

MITOCW ocw-18_02-f07-lec02_220k

Finding Limits Graphically and Numerically

Economics 101. Lecture 2 - The Walrasian Model and Consumer Choice

What is proof? Lesson 1

No Solution Equations Let s look at the following equation: 2 +3=2 +7

Math Lab 10: Differential Equations and Direction Fields Complete before class Wed. Feb. 28; Due noon Thu. Mar. 1 in class

Regina Algebra 1 and A

Exploring and Generalizing Transformations of Functions

Polynomials; Add/Subtract

1.3 Limits and Continuity

Section 1.x: The Variety of Asymptotic Experiences

Jane and Joe are measuring the circumference of a dime with a string. Jane' s result is: 55 mm Joe's result is: 58 mm

CHAPTER 1: Functions

MATH 1910 Limits Numerically and Graphically Introduction to Limits does not exist DNE DOES does not Finding Limits Numerically

Math 2 Variable Manipulation Part 7 Absolute Value & Inequalities

3.5 Quadratic Approximation and Convexity/Concavity

Section 0.6: Factoring from Precalculus Prerequisites a.k.a. Chapter 0 by Carl Stitz, PhD, and Jeff Zeager, PhD, is available under a Creative

Chapter 6: Rational Expr., Eq., and Functions Lecture notes Math 1010

HOMEWORK 7 SOLUTIONS

Properties of Arithmetic

Notes for Lecture 15

Finite Differences TEACHER NOTES MATH NSPIRED

Section 1.8 Matrices as Linear Transformations

Math 2163, Practice Exam II, Solution

Math 121 (Lesieutre); 9.1: Polar coordinates; November 22, 2017

Stephen F Austin. Exponents and Logarithms. chapter 3

Lecture for Week 2 (Secs. 1.3 and ) Functions and Limits

1.4 Mathematical Equivalence

February 13, Option 9 Overview. Mind Map

Chapter 3 ALGEBRA. Overview. Algebra. 3.1 Linear Equations and Applications 3.2 More Linear Equations 3.3 Equations with Exponents. Section 3.

Math 10C Practice Final Solutions

Transcription:

MATLAB assignment Math 222, Fall 2011 ROOT FINDING AND OPTIMIZATION!!! Part I: The Mathematical Prelude So the goal of this part of the assignment is to approximate solutions to nonlinear systems of equations and approximate solutions to optimization problems. We start with an example that we can solve by hand. Find the absolute maximum and the absolute minimum of the function subject to the constraint f(x, y) = 3x + 4y g(x, y) = x 2 + y 2 = 25. Attacking this problem with Lagrange multipliers leads to something like this: { 3 = λ2x f = λ g 4 = λ2y. Together with our constraint equation (x 2 +y 2 = 25), we have three equations for our three unknowns: x, y, and λ. Now proceeding without the use of MATLAB, we observe that neither x nor y can equal zero, so we can divide the first equation above by x and the second by y to get to: 3 x = 2λ = 4 y. Cross-multiplying and ignoring λ henceforth we arrive at the equations: or if you prefer 3y = 4x x 2 + y 2 = 25, 3y 4x = 0 x 2 + y 2 25 = 0.

Now we can crank through these equations without too much difficulty (I hope), to get two possibilities: Either x = 3 & y = 4, or x = 3 & y = 4. Plugging into our original function f(x, y) we get f(3, 4) = 25 and f( 3, 4) = 25. The first case gives us our absolute maximum, and the second case gives us our absolute minimum. OK, that is fine, but it was a somewhat contrived example. Let s try a very similar but slightly less contrived example. Find the absolute maximum and the absolute minimum of the function subject to the constraint f(x, y) = 3x + 4y + 0.001e x g(x, y) = x 2 + y 2 = 25. Now intuitively, since we have taken a teeny tiny function (namely 0.001e x ), and added to what we were optimizing before, we expect that the new max and min will be close to the old max and min. On the other hand, if we wish to find the exact solutions the algebra is now intractable. Ignoring my pessimism, let us see what happens. Lagrange multipliers leads to something like this: { 3 + 0.001e x = λ2x f = λ g 4 = λ2y. So, by solving for 2λ in each equation and equating the result, we get to: 3 + 0.001e x = 4 x y.

A little bit of algebraic manipulation (multiply by xy and subtract 4x from both sides), together with the constraint equation and now we have the system of equations: 3y + 0.001ye x 4x = 0 x 2 + y 2 25 = 0. Now in order to solve this system, we need something with some computing power. Part II: The Rootfinding Approach Using fsolve We turn to our first and most straightforward approach to solving the system above. In my first attack on this problem, I made two m-files. My first m-file was called myfun.m and its contents were: function F = myfun(w) F = [3 w(2) +.001 w(2) exp(w(1))-4 w(1), w(1) 2 + w(2) 2-25]; Now as I stated above, this file was named myfun.m and you will notice that on the first line I wrote [blah blah] myfun(w). Now if I had named the file cheeseburger.m, then on the first line where it says myfun(w) I would need it to say cheeseburger(w). In terms of what this m-file does, I guess it may help to figure out what is going on by typing in the main window: myfun([3,4]) Now hopefully you will see something like this: ans =

0.080342147692750 0 (If you saw an error message like this: Undefined function myfun for input arguments of type double, then you need to make sure that the window that has the current folder is set to the place where your myfun.m file is located.) So... What is going on? Well, you are feeding myfun the vector [3, 4], and so within the function it is setting w = [3,4], and more specifically, it is letting w(1) = 3, and w(2) = 4. After that it computes the two pieces of what it is calling F, and it is then spitting these out for you. In particular, you will notice that w(1) 2 + w(2) 2 25 = 3 2 + 4 2 25 = 9 + 16 25 = 0, and that is indeed exactly what MATLAB gave you for the second component of F. Now if you compare myfun with the system of equations that you found at the end of Part I, then you will hopefully recognize that solving that system, amounts to finding a vector (probably close to [3,4] or [-3, -4]) which makes myfun spit out 0, 0. Well, now it is time to get MATLAB to do some root finding for us. I wrote a file named examplewfsolve.m and it contents are: w0 = [3,4]; [w,fval] = fsolve(@myfun,w0); w w0 = [-3,-4]; [w,fval] = fsolve(@myfun,w0); w So... what is going on is MATLAB looks for a point near w0 which makes myfun equal to zero, and, indeed, it finds a point very close to [3,4] and then it finds a point very close to [-3,-4] which do indeed make myfun = [0, 0].

Assignment! Problem 1: Change the function f(x, y) by altering the tiny function 0.001e x to a different (but also tiny) nonpolynomial function of x and y. Use MATLAB to solve the corresponding Lagrange Multiplier problem by altering my function myfun above. Submit the code and the output. Part III: The Optimization Approach Using fminsearch Another way to try to get a solution to the system: 3y + 0.001ye x 4x = 0 x 2 + y 2 25 = 0 which has the benefit of forcing you to learn about minimization is to try to find minimums of the function created by adding up the squares of the left hand sides. In other words, let Θ(x, y) := (3y + 0.001ye x 4x) 2 + (x 2 + y 2 25) 2 and then let MATLAB hunt for a minimum of Θ using fminsearch. To this end I wrote the following code: I wrote a file named Cartman.m with the contents: function F = Cartman(y) F = ((3 y(2) +.001 y(2) exp(y(1)) - 4 y(1)) 2 + (y(1) 2 + y(2) 2-25) 2); and then I wrote a file named examplewfminsearch.m with the contents: y0 = [3,4]; [y,fval] = fminsearch(@cartman,y0,optimset( TolX,1e-15)); y Cartman(y)

y0 = [-3,-4]; [y,fval] = fminsearch(@cartman,y0,optimset( TolX,1e-15)); y Cartman(y) I guess it is worth mentioning that the part involving optimset is just used to tell MATLAB to work harder to get really close to the minimum, and by plugging the values I find into the function Cartman I can see that I do indeed get a number which is incredibly close to zero. Assignment! Problem 2: Alter the definition of Cartman above so that fminsearch can be used to find the roots of the same Lagrange Multiplier problem that you solved in Problem 1. Submit the code and the output.