Question
Program a function (in python) pmin(f,x,y,z,epsilon) that returns the minimum for the function f using the polytope method, given an initial simplex (triangle) described by
Program a function (in python) pmin(f,x,y,z,epsilon) that returns the minimum for the function f using the polytope method, given an initial simplex (triangle) described by points x = (x1,x2), y = (y1,y2) and z = (z1,z2). Epsilon is the desired accuracy of the solution. Note that you don't have to nd the most e cient way of doing this.
Once you are done, apply your program to the function f(x1,x2)=2(x1 4)^2 +3(x2 5)^2. Then apply it to the Rosenbbrock function (banana function)f(x1,x2) = (1 x1)^2 + 100(x2 x21)^2. Try to see what happens with di erent start values and size of the initial triangle.
Some hints: 1. Define a scripy array where each row contains a point of the simplex and the value of f at this point. Thus, you will have an array with 3 rows and 3 columns. To sort an array by one of the columns you can proceeds as follows: Import "argsort" from numpy. Then if the name of the matrix is A, you can sort the matrix by column n using the command "A-A[A[:,n].argsortO]". Of course remember, that the first column is n 0, the second column n - 1, etc. 2. Suppose we have a triangle described by points a, y, and z, and we want to mirror a across the line between y and z, then we can first find the point p that is the projection of x on the line between y and z by using the formula: where denotes the vector (dot) product of the vectors. Once you have the point p the desired mirrored point is then 3. To shrink the triangle keeping x fixed, the new point y,-x + 0.5(y-x) and similarly, z' = x + 0.5(z-z). 4. You should use dot () for the inner product. Also remember that in a division you have to make sure that the denominator is a float. Some hints: 1. Define a scripy array where each row contains a point of the simplex and the value of f at this point. Thus, you will have an array with 3 rows and 3 columns. To sort an array by one of the columns you can proceeds as follows: Import "argsort" from numpy. Then if the name of the matrix is A, you can sort the matrix by column n using the command "A-A[A[:,n].argsortO]". Of course remember, that the first column is n 0, the second column n - 1, etc. 2. Suppose we have a triangle described by points a, y, and z, and we want to mirror a across the line between y and z, then we can first find the point p that is the projection of x on the line between y and z by using the formula: where denotes the vector (dot) product of the vectors. Once you have the point p the desired mirrored point is then 3. To shrink the triangle keeping x fixed, the new point y,-x + 0.5(y-x) and similarly, z' = x + 0.5(z-z). 4. You should use dot () for the inner product. Also remember that in a division you have to make sure that the denominator is a floatStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started