Write a Python program to solve the following optimization problem Use scipy.opt
ID: 3835845 • Letter: W
Question
Write a Python program to solve the following optimization problem Use scipy.optimize.minimize ,minimize() allows you to set inequality and equality conditions. For this problem, you will need to set an equality condition of Cross-sectional Area = 8. This will force minmize() to only find solutions that result in a cross-sectional area of 8m2.
You are desiging a channel for which you want to minimize resistance to flow - this is achieved by minimizing the "wetted perimeter" of the channel, defined as wp=b+2(h/cos), for a given cross-sectional area. (this minimizes resistance to flow; see the following figure for reference):
For this problem, assume we want to maintain a cross-sectional channel area of 8m2, so you want to find the minimum wetted perimeter that maintains this cross-sectional area.
For output, report the values for b, h, and theta that minimize the wetted perimeter.
Please include a docstring for all functions you define, describing what the function does, any parameters, and what the function returns.
resistance to flow, see the following figure for reference) The cross-sectional area of this channel is given by:Explanation / Answer
from PyGMO.problem import base class my_problem(base): """ De Jong (sphere) function implemented purely in Python. USAGE: my_problem(dim = 10) * dim problem dimension """ def __init__(self, dim = 10): #First we call the constructor of the base class telling #essentially to PyGMO what kind of problem to expect (1 objective, 0 contraints etc.) super(my_problem,self).__init__(dim) #then we set the problem bounds (in this case equal for all components) self.set_bounds(-5.12,5.12) #we define some additional 'private' data members (not really necessary in #this case, but ... hey this is a theory) self.__dim = dim #We reimplement the virtual method that defines the objective function. def _objfun_impl(self,x): f = 0; for i in range(self.__dim): f = f + (x[i])*(x[i]) #note that we return a tuple with one element only. In PyGMO the objective functions #return tuples so that multi-objective optimization is also possible. return (f,) #Finally we also reimplement a virtual method that adds some output to the __repr__ method def human_readable_extra(self): return " Problem dimension: " + str(self.__dim)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.