Write a Python program to solve the following optimization problem Use scipy.opt
ID: 3836722 • 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
#!/usr/bin/python # Open a file in write mode fo = open("foo.txt", "rw+") print "Name of the file: ", fo.name # Assuming file has following 5 lines # This is 1st line # This is 2nd line # This is 3rd line # This is 4th line # This is 5th line str = "This is 6th line" # Write a line at the end of the file. fo.seek(0, 2) line = fo.write( str ) # Now read complete file from beginning. fo.seek(0,0) for index in range(6): line = fo.next() print "Line No %d - %s" % (index, line) # Close opend file fo.close()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.