Andiguys

65 Reputation

5 Badges

1 years, 79 days

MaplePrimes Activity


These are replies submitted by Andiguys

@sand15 Thankyou

@sand15 Thankyou for the syntax.

I tried adjusting the arrow direction, but it's currently pointing downward. How can I change it to point from the right or the left? Which command should I use for that? 

@acer @sand15

Thank you for the clarification and for taking the time to look into it.

I now understand that Kitonum’s procedure was part of the post and not a built-in command—I must have misunderstood earlier. If anyone has suggestions on what changes I should make to get it working without errors, I’d really appreciate the help.

Thanks again!

@janhardo I already have the results computed, but how can I fetch these values and automatically insert them into a table? What is the correct method or syntax to extract and organize the output data into a structured table format?

@sand15 Thankyou.

@mmcdara 7891 can you help with the problem above?

@sand15This isn't working on my end. I'm getting an error saying 'ContoursWithLabels is not a command in the plots package' when I use your syntax. Also, the command gridelines = false,  doesn't seem to have any effect.

S1_vs_s2_contour_plot.mw

@acer 

I would like to export this table in a document format (Word or PDF), but with the actual values substituted in place of the symbolic bounds (lower and upper).

Could you please guide me on the correct syntax or steps to perform this substitution and export?

@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

 

1 2 3 4 5 6 7 Page 2 of 9