Skip to content

Instantly share code, notes, and snippets.

@terjehaukaas
Last active June 13, 2019 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terjehaukaas/5a47999453f9471253f58c73e52f2ab0 to your computer and use it in GitHub Desktop.
Save terjehaukaas/5a47999453f9471253f58c73e52f2ab0 to your computer and use it in GitHub Desktop.
1D Optimization Analysis
# ------------------------------------------------------------------------
# The following Python code is implemented by Professor Terje Haukaas at
# the University of British Columbia in Vancouver, Canada. It is made
# freely available online at terje.civil.ubc.ca together with notes,
# examples, and additional Python code. Please be cautious when using
# this code; it may contain bugs and comes without any form of warranty.
# Please see the Programming note for how to get started, and notice
# that you must copy certain functions into the file terjesfunctions.py
# ------------------------------------------------------------------------
# Import the search algorithms
import terjesfunctions as fcns
# Define the objective function
def F(x):
return 204165.5 / (330.0 - 2.0 * x) + 10400.0 / (x - 20.0)
# Specify starting and bounding values
lowerBound = 30.0
upperBound = 100.0
startPoint = 30.0
# Set convergence parameters
maxIterations = 100
tolerance = 0.01
# Plot option: negative if no plot, otherwise the plot delay
plot = 0.2
# Run line search algorithms
fcns.goldenSectionLineSearch(F, lowerBound, upperBound, maxIterations, tolerance, plot)
fcns.newtonLineSearch(F, startPoint, maxIterations, tolerance, plot)
fcns.bisectionLineSearch(F, lowerBound, upperBound, maxIterations, tolerance, plot)
fcns.secantLineSearch(F, lowerBound, upperBound, maxIterations, tolerance, plot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment