Home

Solving a maximization problem with R - User

image

Contents

1. partial derivatives in order to draw the zero level sets that will show us precisely through their X intersections where the stationary points are located The partial derivative with respect to x in R is 00 02 04 0 2 0 4 SHE CS Pe UC Ie oa a O OO ie EI ye ae oe 7 Ia This describes the incremental ratio We shock x by adding to it an arbitrarily small value h 0 001 In this way we compute the rate of change of the function The same applies to y as follows Spy lt dwneielem bx OL GE Gx yRla oie be a We now re use the other function to compute the z values corresponding to the partial derivatives Thus zfx and Zfy are matrices 400 rows and 400 columns with values of fx and fy respectively PT ex ee Oe O TAA SAIN lt OUND SIR NOR Nin Ine Now we are perfectly able using the contour function This command draws lines that show the level sets of the function you insert as an input If we use it with respect to both partial derivatives at the zero level it becomes possible to see the stationary points which are Saddle points where the lines cross Maxima and minima where we observe small circles gt contour x y zf x Llevel 0 PCOMnwoulk XG Any Levieil O5 e col tea When giving the command we write t the two variables x and y the function for which we want to see the level sets level 0 because we are not interested just in the other
2. z value 3 CompTools a a 2011 2012 Maria Corina Greab 832579 Laura Montenovo 832617 Maria Pugliesi 835310 To find the coordinates of the saddle points algebraically we should solve a system where we set both partial derivatives equal to zero This is not possible in R We minimize the sum of the square partial derivatives with optim This sum is always non negative The points where it is equal to zero are exactly where both second order considering the very initial objective function partial derivatives are equal to zero then the system is solved Let s define the partial derivatives plugging x 1 and x 2 instead of x and y Sb lon Fe Ulin 1s Oa eh toe IE 2 ENO R PUA Ola ee ae Wee eee 2 Call sumssq the function of the vector x made of the sum of the squares of the two partial derivatives SSUMSSc E 261d lt EOL eZ EO se 2 Now we can find the coordinates of the saddle points through optim We do exactly the same thing for all three points just changing the guess of their locations according to the graphs Soo im ue 10 1 sulin stop Spar 1 1 910525e 06 1 277307e 05 clas 1s se llimocic 0 0 OQOie aC yay Oey SMS cen Spar Pol sS0 R01 CeO 4 4S Se e 0G ene a eligostc 04 SU opcim c 0 1 074 Sums sa Spar e T e a a aE E sel Limes ta a0 One S Now please recall what is written at about half of the second page We should make sure that the function increases or d
3. Solving a maximization problem with R User guide By Maria Corina Greab Laura Montenovo and Maria Pugliesi 1 Introduction The aim of this user guide is to solve an optimization problem to display graphically the solutions and to suggest to users some helpful commands and tricks The guide is intended for those users having at least a little bit of grasp with the basics of R 2 Inputing the data Consider a function f such that f x y 2 x y7 2 x 7 y x y We must find the coordinates of the stationary points and then classify them The first thing to do is to define our 2 variable function paying attention to brackets and signs and call it f Sake S Ue eo 7 DER T OU NT Ae in R performs computations in the following order powers multiplications and divisions sums and subtractions Now we want R to assign values to x and y we assign y values only in the two variable case through seq x is a sequence of 200 components len 200 going from 0 5 up to 0 5 Such high choice of sequence length will allow us to produce a sufficiently precise and detailed graph The same procedure is applied to define the variabley Since we have a two variables function we need to define the variable z f x y which corresponds to the values of the function for each pair of x and y that satisfies f x y i t Peta Vp The outer command computes a matrix with all the values of f for all pairs of x andy To see the proper structure
4. ecreases to infinity at the angles of the pictures in ensure that we have found ALL the stationary points of the function and that none is hidden beyond the boarder of our graphs We maximize the white angle and minimize the other three to understand what angle we are working on just have a look at the vector c that indicates approximately where we place our initial guess gt optim c 0 4 0 4 fbb The values are 5 457516e 53 and 5 399318e 53 gt x gt and y gt 00 gt optim c 0 4 0 4 f b The values are 4 804367e 54 and 4 727385e 54 gt x gt 00 and y gt O POpiewim CO Oech o Cc Omer l lisence ake ik The values are 4 727385e 54 and 4 804367e 54 gt x gt and v gt gt optim c 0 4 0 4 b The values are 1 185271e 54 and 6 367610e 54 gt x gt 00 and y gt o These results imply that there are no points of our interest outside our pictures 4 CompTools a a 2011 2012 Maria Corina Greab 832579 Laura Montenovo 832617 Maria Pugliesi 835310
5. of the matrix we can use str z structure of z We are now ready to plot the graph of this 3 dimensional function 3 Graphs To take a look at the 3 dimensional image we can use the command persp perspective gt persp x y z theta 30 ph1i 15 ticktype detailed x y z are our three variables theta 30 phi 15 are the coordinates of the angles from which we look at the graph and ticktype detailed displays the numerical values of the variables on the 3 axes The persp command gives us an accurate overview of the shape of our function but this is not enough to find optimizers For this purpose we can use the image command with x y z being the three variables of the functionf a Montenovo 832617 Maria Pugliesi 835310 a maige yy 2 This command allows us to detect minima and maxima by showing us the height of the function at different points lighter colors yellow white indicate high regions while darker red indicates that the function decreases Here we notice that the angle at the upright boundary of the picture is almost white while the remaining three are more red However this is not enough to conclude that these points are optimizers since the function can grow or decrease to infinity Instead we can observe on the picture some bright red parts that meet forming a cross This allows us to identify three saddle points 04 02 00 02 04 Now we must obtain the
6. s To the command that draws the zero level sets of zfy we add add T to impose this graph over the previous one a _col red to change the colors of the line to distinguish z properly the contours for fx and fy x Afterwards it is straightforward to observe the 4 stationary points at the four crossing points We can read the coordinates of the points directly on the axis of the pictures 04 02 00 02 04 From the image picture we have found just three saddle points Montenovo 832617 Maria Pugliesi 835310 and no maxima or minima while here we see the zero level sets crossing in 4 points This means that we still do not know the nature of one stationary point To understand what kind of optimizer it is we must zoom on its area changing the proportions of the axis We do this through seq choosing a shorter interval for x and y and defining Z correspondingly Px seq 022 07 ken 240 0 gt y lt seq 0 2 0 len 400 7 eo ie tal eens mien Looking at the picture of both colors and contours we will identify the misterious point gt image X Y Z Concour yy Z ad E Finally we can spot a circle in a very bright area This is precisely where am a our maximum lies io Algebraic solution It is possible to find the exact coordinates of the stationary points of a 5 function using the command optim In principle the optim command does not read mul
7. tivariate functions However it is possible to transform our bivariate function into a univariate one by changing the names of the two variables x and y into x 1 and Q x 2 a The new function therefore is 0 20 0 15 0 10 0 05 0 00 e a 18 ilove a a 6 e ES 2 The logic behind this transformation is that means extraction So x 1 and x 2 are viewed by R as elements belonging to the same vector x Here we simply plug the values x 1 and x 2 into the function f so that x 1 x and x 2 y Next we use optim to find the coordinates of our maximizer Remember is that R finds one stationary point at a time Moreover by default R just givesthe coordinates of the minima Two parameters are needed an approximate guess of where the critical point might be and the name of the function Since we have a maximizer the best way to overcome the minimizer default of R is to reverse the function down so that the original minimizer becomes now a maximizer This is done by changing the sign of the value corresponding to the parameter fnscale OPET a O oir a eho a En a Here the vector is our guess of where we expect to find the point just look at the previous graph gb is the function we need to maximize and the last part of the command is to the maximizing trick Here is what we get Spar LE S07 Lioese6s4 0 sees ios the coordinates of the point Svalue LI O COSZso255 the corresponding

Download Pdf Manuals

image

Related Search

Related Contents

Nederlands ..Pagina 51  この製品のカタログをダウンロード(PDF)  COBAS Ampliscreen HBV Test  VM-800 取扱説明書 - 株式会社アイ・ティー・オー  fr Manuel d`utilisation Système guide-bande SWA  

Copyright © All rights reserved.
Failed to retrieve file