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

Exp 9 Num Using Py Code

Uploaded by

K. Vishal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Exp 9 Num Using Py Code

Uploaded by

K. Vishal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import numpy as np print("Optimization was successful.

")

from scipy.optimize import minimize print("Optimal solution:", result.x)

print("Objective function value at optimal


solution:", result.fun)
# Objective function to minimize: f(x) = x1^2 +
x2^2 else:

def objective(x): print("Optimization failed.")

return x[0]**2 + x[1]**2 print(result.message)

# Equality constraint: g1(x) = x1 + x2 - 1 = 0

def equality_constraint(x):

return x[0] + x[1] - 1

# Inequality constraint: g2(x) = x1 - x2 >= 0 (or


x1 - x2 >= 0 can be expressed as -g2(x) <= 0)

def inequality_constraint(x):

return x[0] - x[1]

# Initial guess

x0 = np.array([0.5, 0.5])

# Define the constraints in a dictionary

constraints = [

{'type': 'eq', 'fun': equality_constraint},

{'type': 'ineq', 'fun': inequality_constraint}

# Perform the optimization

result = minimize(objective, x0,


constraints=constraints)

# Print the results

if result.success:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy