Question: import numpy as np from scipy.optimize import minimize # Objective function def objective ( x ) : x 1 , x 2 , x 3

import numpy as np
from scipy.optimize import minimize
# Objective function
def objective(x):
x1, x2, x3, x4, x5= x
return np.exp(x1* x2* x3* x4* x5)-0.5*(x1**3+ x2**3+1)**2
# Constraints
def constraint1(x):
return x[0]**2+ x[1]**2+ x[2]**2+ x[3]**2+ x[4]**2-10
def constraint2(x):
return x[1]* x[2]-5* x[3]* x[4]
def constraint3(x):
return x[0]**3+ x[1]**3+1
# Algorithm 18.1
def SQP_algorithm(objective, constraints, x0):
x = x0
while True:
# Step 1: Solve the Quadratic Programming Subproblem
result = minimize(objective, x, constraints=constraints, method='SLSQP')
# Step 2: Check for Convergence
if np.linalg.norm(result.x - x)<1e-6:
break
# Step 3: Update x
x = result.x
return result
# Initial guess and constraints
x0= np.array([-1.71,1.59,1.82,-0.763,-0.763])
con1={'type': 'eq', 'fun': constraint1}
con2={'type': 'eq', 'fun': constraint2}
con3={'type': 'eq', 'fun': constraint3}
constraints =[con1, con2, con3]
# Solve the optimization problem using Algorithm 18.1
result = SQP_algorithm(objective, constraints, x0)
# Print the solution
print("Optimal solution:")
print("x*=", result.x)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!