Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Can't minimize this simple function with constraints Alex009988 Programmer named Tim Posts: 6 Threads: 5 Joined: Aug 2019 Reputation: 0 Likes received: 0 #1 Sep-25-2019, 10:33 AM (This post was last modified: Sep-25-2019, 10:34 AM by Alex009988. Edited 2 times in total.) I want to minimize this objective funrtion: -10 000 000/100*(0*p0+100*p100) with constraints p0^56>=0.05 p0+p100=1 0<=p0<=1 0<=p100<=1 So that i used this code ```import numpy as np from scipy.optimize import minimize def objective(p): p0=p p100=p return -10000000/100*(0*p0+100*p100) def constraint1(p): return p**56-0.05 def constraint2(p): sum_p=1 for i in range(2): sum_p=sum_p-p[i] return sum_p p0=[0,0] p1=[0.94791, 0.0520895] #print(objective(p1)) b=(0.0,1.0) bnds=(b,b) con1={'type':'ineq','fun':constraint1} con2={'type':'eq','fun':constraint2} cons=[con1,con2] sol=minimize(objective,p0,method='SLSQP',bounds=bnds,constraints=cons) print(sol) ```The solution should be p0=0.94791, p100=0.0520895 and f(p)=-520 895. I've tried trust-constr,SLSQP,TNC,L-BFGS-B,COBYLA and all cant find a solution. Please, help me. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Simple Python function help needed Imran23 2 764 Jun-07-2018, 12:20 AM Last Post: Imran23 minimize with scipy.optimize tobenmoben 0 808 Feb-17-2018, 01:47 PM Last Post: tobenmoben

Forum Jump:

Users browsing this thread: 1 Guest(s)