Ask Your Question

Husker's profile - activity

2019-12-12 18:44:52 +0200 received badge  Notable Question (source)
2018-03-20 22:13:56 +0200 received badge  Popular Question (source)
2012-04-09 19:14:19 +0200 received badge  Editor (source)
2012-04-09 18:45:16 +0200 answered a question Minimization with symbolic calculations in a function

I am trying to expand this solution to multiple variables, but I am having no success. What is the syntax for the problem below? I am unsure of the syntax for the minimize_constrained function, and the syntax in the return statement. Also, is there a way to add a constraint to a value returned by the function? In this case Vt? I would like to minimize Vs while forcing Vt to equal the variable Target.

P, T, Ps, Ts, yTarget = var('P, T, Ps, Ts, yTarget')
y=25+200*P-2*P^2+14*T
dP=y.diff(P)
dT=y.diff(T)
dP2=y.diff(P,2)
dT2=y.diff(T,2)
Psn=5
Tsn=10
yTarget=7000
def f(Pn,Tn):
    ya=y+(1/2)*(dP2*Psn^2+dT2*Tsn^2)
    ys=(dP^2*Ps^2+dT^2*Ts^2)^0.5
    return ys.subs(P=Pn,T=Tn,Ps=Psn,Ts=Tsn), ya.subs(P=Pn,T=Tn,Ps=Psn,Ts=Tsn)
2012-04-08 17:45:14 +0200 answered a question Minimization with symbolic calculations in a function

Thanks! That was the problem. I also moved the derivative out of the optimization loop.

a,b,c,z,dy=var('a b c z dy')

y=5*c^3

dy=y.diff(c)

def f(x):

    w=5*(c-10)^3 
    z=dy+w 
    return z.subs(c=x[0])

minimize_constrained(f, [(-10,10)],[9])

2012-04-07 01:15:58 +0200 asked a question Minimization with symbolic calculations in a function

I am a new Sage user, and I am unable to get the constrained minimization function working if I include a symbolic differentiation.

The code below works fine

c=var('c')
y=5*c^3
def f(c):
    #z=dy^2
    w=5*(c-10)^3
    z=w^2
    return z
minimize_constrained(f, [(-10,10)],[9])

This code gives an error

c=var('c')
y=5*c^3
def f(c):
    dy=y.diff(c)
    w=5*(c-10)^3
    z=dy+w
    return z
minimize_constrained(f, [(-10,10)],[9])

Any assistance would be greatly appreciated.