0% found this document useful (0 votes)
187 views

Prog Exerc Sheet - Copie 6

The document shows code for reading lines from a file into lists and performing nonlinear optimization by minimizing an objective function and its derivative. It contains code to open a file, read lines into four lists, define an objective function and its derivative, and find the minimum of the function.

Uploaded by

Ruben Kempter
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views

Prog Exerc Sheet - Copie 6

The document shows code for reading lines from a file into lists and performing nonlinear optimization by minimizing an objective function and its derivative. It contains code to open a file, read lines into four lists, define an objective function and its derivative, and find the minimum of the function.

Uploaded by

Ruben Kempter
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#EXERCICE 13 LEC 1 (ouvrir un doc, lire les lignes et les stocker dans un liste)

a1 = []
a2 = []
a3 = []
a4 = []

with open('data.txt') as f:
for line in f:
data = line.split()
a1.append(int(data[0]))
a2.append(int(data[1]))
a3.append(int(data[2]))
a4.append(int(data[3]))

print(a1, a2, a3, a4)

f.close()

#NON LIN LEC 1

import numpy as np
from scipy.optimize import minimize

def func(x, sign=1.0):


""" Objective function """
return sign*(2*x[0]*x[1] + 2*x[0] - x[0]**2 - 2*x[1]**2)

def func_deriv(x, sign=1.0):


""" Derivative of objective function """
dfdx0 = sign*(-2*x[0] + 2*x[1] + 2)
dfdx1 = sign*(2*x[0] - 4*x[1])
return np.array([ dfdx0, dfdx1 ])

You might also like