{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Line-search methods" ] }, { "cell_type": "code", "execution_count": 411, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pylab as pl\n", "import matplotlib.pyplot as plt\n", "plt.rcParams['figure.dpi']= 100 # parameter for resolution of graphics\n", "import time\n", "\n", "v = 2 # variant corresponding to the number of the function below\n", "Maxiter = 200 # Number of iterations\n", "x0 = 2 # Initialization\n", "a = 0 # Lower bound for the plot interval\n", "b = 4 # Upper bound for the plot interval\n", "Tol = 1e-15\n", "\n", "InitStep = 1 # initial step\n", "m1 = 0.1 #Parameters\n", "m2 = 0.7" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Various objective functions" ] }, { "cell_type": "code", "execution_count": 412, "metadata": {}, "outputs": [], "source": [ "def fun(x,v): # function definition\n", " if v==0:\n", " return 3*(1.5*x-1)**2\n", " if v==1:\n", " return x**3-5*x+1\n", " if v==2:\n", " return x**4-2*x**3-5*x\n", " if v==3:\n", " return np.cos(5*x)-8*x+2.5*x**2\n", " if v==4:\n", " return np.cos(5*x)-8*x+1.5*x**2\n", "\n", "def der(x,v): # first derivative\n", " if v==0:\n", " return 3*2*(1.5*x-1)*1.5\n", " if v==1:\n", " return 3*x**2-5\n", " if v==2:\n", " return 4*x**3-6*x**2-5\n", " if v==3:\n", " return -5*np.sin(5*x)-8+2.5*2*x\n", " if v==4:\n", " return -5*np.sin(5*x)-8+1.5*2*x\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Algorithm: Generic Line Search\n", "\n", "