0

I'm trying to solve a forces equilibrium consisting of three equations as constraints (Fx=0,Fy=0,Mx=0) and maximize the variable Vb, for which I set the objective function as -Vb. There are 4 variables that I don't know [phi, beta, gamma, delta_r] which form my vector of variables that corresponds to the guess x0. Two more values are to be fixed, those are (beta,Vw)*

beta,Vw=rad(40),10

def fuerza_x(xs,beta,Vw):
    gamma,phi,Vb,delta_r = xs[0],xs[1],xs[2],xs[3]
    (beta,Vw)=args
    return Fuerzasx(phi,beta,gamma,Vb,Vw,delta_r)

def fuerza_y(xs,beta,Vw):
    gamma,phi,Vb,delta_r = xs[0],xs[1],xs[2],xs[3]
    beta,Vw=arguments
    return Fuerzasy(phi,beta,gamma,Vb,Vw,delta_r)

def momento_1(xs,beta,Vw):
    gamma,phi,Vb,delta_r = xs[0],xs[1],xs[2],xs[3]
    beta,Vw=arguments
    return mom(phi,beta,gamma,Vb,Vw,delta_r)

def objective(xs,beta, Vw):
    gamma,phi,Vb,delta_r = xs[0],xs[1],xs[2],xs[3]
    return -Vb


eq_cons = (
    {'type': 'eq', 'fun' : fuerza_x(xs,beta,Vw),'args': (beta,Vw) },
    {'type': 'eq', 'fun' : fuerza_y(xs, beta, Vw),'args': (beta,Vw) },
    {'type': 'eq', 'fun' : momento_1(xs,beta, Vw),'args': (beta,Vw) } )

x0 = np.array([ rad(4), rad(20),6, 0.2])
res = minimize(objective, x0,args=(beta,Vw), method='SLSQP',
               constraints=eq_cons, options={'ftol': 1e-9, 'disp': True})

I suppose that the mistake lies with the syntax used in the arguments tuple. I've researched lots of simmilar questions (Structure of inputs to scipy minimize function) but they don't fit for my case. Any help is greatly appreciated.

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
OIB
  • 1
  • Unless you expect us to copy and run the code, you need to be very clear about what's the problem. If you get errors, show them, with full traceback. – hpaulj Feb 11 '22 at 17:34
  • 1
    Have you tried constrains like `{'type': 'eq', 'fun' : fuerza_x}`? I'm not sure how the constraint `args` parameter relates to the one used in the main `minimize` call. But you definitely don't want `fuerza_x(....)` when setting up the constraints. – hpaulj Feb 11 '22 at 17:46
  • Search on `[scipy] minimize constraints` gives many entries. Surely there's something newer and more useful than your 2013 link. – hpaulj Feb 11 '22 at 17:52

0 Answers0