Andiguys

65 Reputation

5 Badges

1 years, 54 days

MaplePrimes Activity


These are replies submitted by Andiguys

@vv The constraint is perpendicular to x-axis, its horizontal?? something is wrong

 

@vv What i meant is constraint C1 and C2 are lines perpendicular to x-axis, How can we draw that in plot function??
I want syntax for that? it will be region right, so how to draw plot with constraints with feasible region.

@vv Can you show syntax for adding constraints in graph?

@mmcdara is it possible to keep the image resolution above 300 dpi? If yes can you provide the syntax

@mmcdara Thankyou. Can you label the Cb point and give value where the difference between both is zero. pi(DR)-pi(DD)=0. Also in Cb axis can you provide 4.10^4 , 5 * 10^4. Or   Provide 10^4 in seperate bracket outside like Cb (10^4).

@dharr There may be some syntax to magnify it?

@mmcdara In all the cases, the solution for optimal Pc​ is showing as null. Can you please check if there's some error?

Q_Pc_KKT.mw
 

``

NULL

NULL

restart

with(Optimization); with(plots); with(LinearAlgebra)

_local(Pi)

Pi

(1)

q1 := -beta*p1+a

q2 := -beta*p2+a

r := proc (Pc) options operator, arrow; (1/3)*`ϕ`*q1-upsilon*(Pu-Pc) end proc

``

`π_m` := proc (Pc) options operator, arrow; lambda*(w*r(Pc)+Ce*r(Pc)-Pc*r(Pc)-(1/2)*eta*Ce^2+U*r(Pc)^2) end proc

proc (Pc) options operator, arrow; lambda*(w*r(Pc)+Ce*r(Pc)-Pc*r(Pc)-(1/2)*eta*Ce^2+U*r(Pc)^2) end proc

(2)

C1 := Pc <= (`&varphi;`*q1-(1/3)*`&varphi;`*q1+upsilon*Pu)/upsilon

Pc <= ((2/3)*varphi*(-beta*p1+a)+upsilon*Pu)/upsilon

(3)

C2 := Pc > -((1/3)*`&varphi;`*(-beta*p1+a)-upsilon*Pu)/upsilon

-((1/3)*varphi*(-beta*p1+a)-upsilon*Pu)/upsilon < Pc

(4)

NULL

# No equality constraints
#
# Inequality constraints must be of the form f[i](p1) <= 0
#
# Thus
#
# (1) For C1
#     so
      f[1] := (Pc) -> Pc-(varphi*q1 - varphi*q1/3 + upsilon*Pu)/upsilon:
      

      
#
# (2) C2
#     so
      f[2] := (Pc) -> -(varphi*(-beta*p1 + a)/3 - upsilon*Pu)/upsilon-Pc:

 

# Lagrangian (we want to maximize `&pi;_m` so to minimize -`&pi;_m`

L := -`&pi;_m`(Pc) + add(f[i](Pc)*mu[i], i=1..2);

-lambda*(w*((1/3)*varphi*(-beta*p1+a)-upsilon*(Pu-Pc))+Ce*((1/3)*varphi*(-beta*p1+a)-upsilon*(Pu-Pc))-Pc*((1/3)*varphi*(-beta*p1+a)-upsilon*(Pu-Pc))-(1/2)*eta*Ce^2+U*((1/3)*varphi*(-beta*p1+a)-upsilon*(Pu-Pc))^2)+(Pc-((2/3)*varphi*(-beta*p1+a)+upsilon*Pu)/upsilon)*mu[1]+(-((1/3)*varphi*(-beta*p1+a)-upsilon*Pu)/upsilon-Pc)*mu[2]

(5)

dLdPc := collect(diff(L, Pc), [Pc]);

-lambda*(2*U*upsilon^2-2*upsilon)*Pc-lambda*(w*upsilon+Ce*upsilon-(1/3)*varphi*(-beta*p1+a)+upsilon*Pu+2*U*((1/3)*varphi*(-beta*p1+a)-upsilon*Pu)*upsilon)+mu[1]-mu[2]

(6)

KKT_conditions := [
                    seq(mu[i] >= 0, i=1..2),         # Dual feasibility conditions
                    dLdPc = 0,                       # Stationarity condition
                    seq(``(f[i](Pc)) <= 0, i=1..2),  # Primal feasibility conditions
                    add(mu[i]*f[i](Pc) = 0, i=1..2)  # Complementary slackness
                  ]:

print~(KKT_conditions);

0 <= mu[1]

 

0 <= mu[2]

 

-lambda*(2*U*upsilon^2-2*upsilon)*Pc-lambda*(w*upsilon+Ce*upsilon-(1/3)*varphi*(-beta*p1+a)+upsilon*Pu+2*U*((1/3)*varphi*(-beta*p1+a)-upsilon*Pu)*upsilon)+mu[1]-mu[2] = 0

 

``(Pc-((2/3)*varphi*(-beta*p1+a)+upsilon*Pu)/upsilon) <= 0

 

``(-((1/3)*varphi*(-beta*p1+a)-upsilon*Pu)/upsilon-Pc) <= 0

 

(Pc-((2/3)*varphi*(-beta*p1+a)+upsilon*Pu)/upsilon)*mu[1]+(-((1/3)*varphi*(-beta*p1+a)-upsilon*Pu)/upsilon-Pc)*mu[2] = 0

 

[]

(7)

 

 

# dLdP1 is linear wrt p1

with(LargeExpressions):

DLDPc := collect(dLdPc, Pc, Veil[K]);

-2*K[1]*Pc-(1/3)*K[2]

(8)

# Thus dLdp1 = 0 verifies

isolate((8), Pc)
 

Pc = -(1/6)*K[2]/K[1]

(9)

i := 'i'; KS := [seq(K[i] = Unveil[K](K[i]), i = 1 .. LastUsed[K])]

[K[1] = lambda*upsilon*(U*upsilon-1), K[2] = -2*U*beta*lambda*p1*upsilon*varphi-6*Pu*U*lambda*upsilon^2+2*U*a*lambda*upsilon*varphi+beta*lambda*p1*varphi+3*Ce*lambda*upsilon+3*Pu*lambda*upsilon-a*lambda*varphi+3*lambda*upsilon*w-3*mu[1]+3*mu[2]]

(10)

beta

beta

(11)

Cs := {seq(beta[i] = subs(p1 = 0, f[i](Pc)), i = 1 .. 2)}

{beta[1] = Pc-((2/3)*a*varphi+upsilon*Pu)/upsilon, beta[2] = -((1/3)*a*varphi-upsilon*Pu)/upsilon-Pc}

(12)

infolevel[solve] := 2; sols := solve({seq(mu[i] >= 0, i = 1 .. 2), seq(Pc-beta[i] = 0, i = 1 .. 2), dLdPc = 0}, {Pc, seq(mu[i], i = 1 .. 2)})

Main: Entering solver with 5 equations in 3 variables
Main: attempting to solve as a linear system
Main: system cannot be directly solved as a linear system
Main: solving successful - now forming solutions
Main: Exiting solver returning 0 solutions
solve: Warning: no solutions found

 

(13)

Cmin_value := -((1/3)*`&varphi;`*(-beta*p1+a)-upsilon*Pu)/upsilon; Cmax_value := (`&varphi;`*q1-(1/3)*`&varphi;`*q1+upsilon*Pu)/upsilon; Cmin_name := beta[2]; Cmax_name := beta[1]; Cmin_name := LowerBound; Cmax_name := UpperBound; Complementary_Slackness := mu[1]*(Cmin_name-Pc), mu[2]*(Pc-Cmax_name); L2 := -`&pi;_m`(Pc)+add(Complementary_Slackness); dL2dp1 := diff(L2, Pc); dL2dp1 := map(simplify, %, size)

LowerBound

 

mu[1]*(LowerBound-Pc), mu[2]*(Pc-UpperBound)

 

-(2/3)*lambda*(3*U*(Pc-Pu)*upsilon^2+(U*(-beta*p1+a)*varphi+(3/2)*w+(3/2)*Ce-3*Pc+(3/2)*Pu)*upsilon-(1/2)*varphi*(-beta*p1+a))-mu[1]+mu[2]

(14)

SC_CS_sols := solve({op(`~`[`=`]([Complementary_Slackness], 0)), dL2dPc = 0}, {Pc, seq(mu[i], i = 1 .. 2)})

false

 

Main: Entering solver with 3 equations in 3 variables
Main: attempting to solve as a linear system
Main: attempting to solve as a polynomial system

Main: Polynomial solver successful. Exiting solver returning 1 solution
solve: Warning: no solutions found

 

"numelems([SC_CS_sols]);    #` And those solutions are charecterized by`    map(s -> if eval(lambda[1], s) = 0 then              if eval(lambda[2], s) = 0 then                "Pc belongs to interval (LowerBound, UpperBound)"             else               "Pc is equal to the UpperBound"              end if           else             "Pc is equal to the LowerBound"            end if           , [SC_CS_sols]);  "

0

 

[]

(15)

SC_CS_sols

"LowerBound:=:   UpperBound:= :"

NULL

NULL

SC_CS_sols[1][1]; simplify(SC_CS_sols[1][3]) > 0

SC_CS_sols[1][1]

 

0 < SC_CS_sols[1][3]

(16)

NULL

SC_CS_sols[2][1]; simplify(SC_CS_sols[2][2]) > 0

SC_CS_sols[2][1]

 

0 < SC_CS_sols[2][2]

(17)

NULL

simplify(SC_CS_sols[3][1])

SC_CS_sols[3][1]

(18)

NULL

NULL

NULL

``


 

Download Q_Pc_KKT.mw

 

@acer 
Showing error "Error, (in assuming) when calling 'solve'. Received: 'cannot solve for an unknown function with other operations in its arguments'
"

Attaching sheet:

restart

kernelopts(version)

`Maple 2019.1, X86 64 WINDOWS, May 21 2019, Build ID 1399874`

(1)

B := w+t+((3*t+3*Pc-3*Pu)*upsilon+((-t-p1)*beta+a)*`&varphi;`)/(3*eta); A := (1/3)*`&varphi;`*(-beta*(p1+t)+a)-upsilon*Pu

K1 := (A(-2*U*upsilon+1)-2*U*t*upsilon^2+(-B+2*t)*upsilon)/(2*upsilon*(U*upsilon-1))

(1/2)*((1/3)*varphi(-2*U*upsilon+1)*(-beta(-2*U*upsilon+1)*(p1(-2*U*upsilon+1)+t(-2*U*upsilon+1))+a(-2*U*upsilon+1))-upsilon(-2*U*upsilon+1)*Pu(-2*U*upsilon+1)-2*U*t*upsilon^2+(-w+t-(1/3)*((3*t+3*Pc-3*Pu)*upsilon+((-t-p1)*beta+a)*varphi)/eta)*upsilon)/(upsilon*(U*upsilon-1))

(2)

K2 := simplify(solve(K1 = Pc, Pc))

(((-t(-2*U*upsilon+1)-p1(-2*U*upsilon+1))*beta(-2*U*upsilon+1)+a(-2*U*upsilon+1))*eta*varphi(-2*U*upsilon+1)-3*upsilon(-2*U*upsilon+1)*Pu(-2*U*upsilon+1)*eta-6*((U*t*eta+(1/2)*t-(1/2)*Pu)*upsilon+(-(1/2)*t+(1/2)*w)*eta+(1/6)*varphi*(-beta*p1-beta*t+a))*upsilon)/((6*U*eta+3)*upsilon^2-6*upsilon*eta)

(3)

``

ineq := -A/upsilon-t <= K2 and K2 <= (`&varphi;`*(-beta*p1+a)-A)/upsilon-t

 

You gave us the (new, updated) information that all variables
are positive. Literally, that means p1 as well (unless you now exclude it).

extra := indets(ineq,And(name,Not(constant))) >~ 0;

{0 < Pu, 0 < U, 0 < a, 0 < beta, 0 < eta, 0 < p1, 0 < t, 0 < upsilon, 0 < varphi, 0 < w}

(4)

 

ineq1 := op(1,ineq):

R1 := op(solve({ineq1},p1)) assuming extra[];

Error, (in assuming) when calling 'solve'. Received: 'cannot solve for an unknown function with other operations in its arguments'

 

ineq2 := op(2,ineq):

R2 := op(solve({ineq2},p1) assuming extra[]);

Error, (in assuming) when calling 'solve'. Received: 'cannot solve for an unknown function with other operations in its arguments'

 

Maybe this is all you are after...

`and`(R1, R2, p1>0);

R1 and R2 and 0 < p1

(5)

Or maybe something like this...

p1>0 and p1 <= min(rhs(R1),rhs(R2));

Error, invalid input: rhs received R1, which is not valid for its 1st argument, expr

 

Or maybe something like this...
simplify(solve(`and`(R1, R2, p1>0), p1)) assuming extra[];

Error, (in assuming) when calling 'simplify'. Received: 'invalid input: simplify uses a 1st argument, s, which is missing'

 
 

``

Download Q_isolate_acc_2_me.mw

@mmcdara Hi...if possible can you verify that the substitutions i made and the interpretation on optimal p1 which i have taken in above sheet is right or not? Thankyou

@mmcdara 

I have two questions:

  1. Is my approach for finding the optimal value of p1—based on whether the solution lies at the lower bound, upper bound, or within the interior—correct as per the syntax you provided?

  2. Are the lower and upper bounds that I substituted at the end of the sheet accurate? If not, what should they be?

Question_Lower_upper.mw

Status:

  • I've already formulated the KKT conditions.

  • Now I need help in solving for p1∗ in each case, depending on which constraints are binding.

Could someone help solve for p1∗​ under different combinations of active/passive constraints?

Looking for:

  • Analytical expressions for p1∗

  • Feasibility ranges per case

  • Guidance on structuring this systematically

@mmcdara 
Can you help with below code so that solve function execute fast?

restart

kernelopts(version)

`Maple 2019.1, X86 64 WINDOWS, May 21 2019, Build ID 1399874`

(1)

A := (1/3)*`&varphi;`*(-beta*p1+a)-upsilon*Pu

``

ineq := -((1/3)*`&varphi;`*(-beta*p1+a)-upsilon*Pu)/upsilon <= (2*U*beta*eta*nu*p1*`&varphi;`+6*Pu*U*eta*nu*upsilon-2*U*a*eta*nu*`&varphi;`+beta*eta*p1*`&varphi;`-beta*nu*p1*`&varphi;`+3*Pu*eta*upsilon-3*Pu*nu*upsilon-a*eta*`&varphi;`+a*nu*`&varphi;`+3*eta*nu*w)/(6*U*eta*nu^2+6*eta*nu-6*nu*upsilon+3*upsilon^2) and (2*U*beta*eta*nu*p1*`&varphi;`+6*Pu*U*eta*nu*upsilon-2*U*a*eta*nu*`&varphi;`+beta*eta*p1*`&varphi;`-beta*nu*p1*`&varphi;`+3*Pu*eta*upsilon-3*Pu*nu*upsilon-a*eta*`&varphi;`+a*nu*`&varphi;`+3*eta*nu*w)/(6*U*eta*nu^2+6*eta*nu-6*nu*upsilon+3*upsilon^2) <= (`&varphi;`*(-beta*p1+a)-A)/upsilon

 

extra := indets(ineq,And(name,Not(constant))) >~ 0;

{0 < Pu, 0 < U, 0 < a, 0 < beta, 0 < eta, 0 < nu, 0 < p1, 0 < upsilon, 0 < varphi, 0 < w}

(2)

 

ineq1 := op(1,ineq):

R1 := op(solve({ineq1},p1)) assuming extra[];

ineq2 := op(2,ineq):

R2 := op(solve({ineq2},p1) assuming extra[]);



`and`(R1, R2, p1>0);



p1>0 and p1 <= min(rhs(R1),rhs(R2));


simplify(solve(`and`(R1, R2, p1>0), p1)) assuming extra[];

 

``

Download Q_isolate_acc_2.mw

@acer 

Apologies for the confusion earlier — I should have mentioned that all variables are positive and should have included both constraints together from the beginning.

Initially, my intent was to understand the correct syntax, and once I had that working, I tried applying it to a slightly different objective function. However, with this new function, the same syntax is now taking a very long time to solve, and I haven’t received any result yet.

Would you be able to suggest what changes or simplifications I can make to improve the computation time for this case?

@acer Taking too much time to solve? Why?

restart

kernelopts(version)

`Maple 2019.1, X86 64 WINDOWS, May 21 2019, Build ID 1399874`

(1)

B := w+Ce; A := (1/3)*`&varphi;`*(-beta*p1+a)-upsilon*Pu

ineq := (2*U*beta*eta*nu*p1*`&varphi;`+6*Pu*U*eta*nu*upsilon-2*U*a*eta*nu*`&varphi;`+beta*eta*p1*`&varphi;`-beta*nu*p1*`&varphi;`+3*Pu*eta*upsilon-3*Pu*nu*upsilon-a*eta*`&varphi;`+a*nu*`&varphi;`+3*eta*nu*w)/(6*U*eta*nu^2+6*eta*nu-6*nu*upsilon+3*upsilon^2) <= (2*`&varphi;`*(-beta*p1+a)*(1/3)+upsilon*Pu)/upsilon

(2*U*beta*eta*nu*p1*varphi+6*Pu*U*eta*nu*upsilon-2*U*a*eta*nu*varphi+beta*eta*p1*varphi-beta*nu*p1*varphi+3*Pu*eta*upsilon-3*Pu*nu*upsilon-a*eta*varphi+a*nu*varphi+3*eta*nu*w)/(6*U*eta*nu^2+6*eta*nu-6*nu*upsilon+3*upsilon^2) <= ((2/3)*varphi*(-beta*p1+a)+upsilon*Pu)/upsilon

(2)

temp := collect(ineq,p1);

(2*U*beta*eta*nu*varphi+beta*eta*varphi-beta*nu*varphi)*p1/(6*U*eta*nu^2+6*eta*nu-6*nu*upsilon+3*upsilon^2)+(6*Pu*U*eta*nu*upsilon-2*U*a*eta*nu*varphi+3*Pu*eta*upsilon-3*Pu*nu*upsilon-a*eta*varphi+a*nu*varphi+3*eta*nu*w)/(6*U*eta*nu^2+6*eta*nu-6*nu*upsilon+3*upsilon^2) <= -(2/3)*varphi*beta*p1/upsilon+((2/3)*varphi*a+upsilon*Pu)/upsilon

(3)

# lhs and rhs are both of type `+`, so select/remove make sense
new := simplify(temp - remove(depends,lhs(temp),p1) - select(depends,rhs(temp),p1));

(2/3)*p1*varphi*((1/2)*upsilon^2+((1/2)*U*nu*eta-(5/4)*nu+(1/4)*eta)*upsilon+nu*eta*(U*nu+1))*beta/(upsilon*((1/2)*upsilon^2-nu*upsilon+nu*eta*(U*nu+1))) <= (1/6)*(3*Pu*upsilon^3+((-6*Pu*U*eta-3*Pu)*nu+2*varphi*a-3*Pu*eta)*upsilon^2+(6*U*Pu*nu^2*eta+((2*U*a*varphi+6*Pu-3*w)*eta-5*varphi*a)*nu+a*eta*varphi)*upsilon+4*a*nu*eta*varphi*(U*nu+1))/(upsilon*((1/2)*upsilon^2-nu*upsilon+nu*eta*(U*nu+1)))

(4)

#Taking too much time to solve???
simplify(solve(new,p1));

Download Q_isolate_acc.mw

@acer Thankyou

1 2 3 4 5 6 7 Page 1 of 7