Andiguys

85 Reputation

5 Badges

1 years, 168 days

MaplePrimes Activity


These are replies submitted by Andiguys

@sand15 Thankyou

@sand15 I'm encountering a scaling issue with the manufacturer axis after using your syntax. Could you please help me fix it?

Download Scalling_issue.mw

@sand15 Thankyou.

@sand15 TM1, TM2, and TM3 represent the profit outcomes under three different scenarios.
Each region shows which scenario gives the highest profit for the given values of Pn​ and w. So the plot is dividing the (Pn,w) space into areas where each scenario is profit-optimal.

@sand15 The solve command isn’t working. What might be causing the issue?

My_interpretation_M.mw

@dharr While solving KKT for a different problem, I am unable to obtain a solution for the decision variable w but getting solution for Pn. How should I incorporate it in the KKT optimization syntax? Could you help me determine the optimal w in each case?

restart

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

_local(Pi)

Pi

(1)

``

`π_m` := proc (Pn, w) options operator, arrow; (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*((((g*i2-c)*Cr-c+w+Ce)*d+g*i2-c)/(Cr*d+2)-g*i2+c)-Ce*((((g*i2-c)*Cr-c+w+Ce)*d+g*i2-c)/(Cr*d+2)-g*i2+c) end proc

proc (Pn, w) options operator, arrow; (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*((((g*i2-c)*Cr-c+w+Ce)*d+g*i2-c)/(Cr*d+2)-g*i2+c)-Ce*((((g*i2-c)*Cr-c+w+Ce)*d+g*i2-c)/(Cr*d+2)-g*i2+c) end proc

(2)

``

C1 := Pn <= (Cr*Pr*d*upsilon-Cr*d*delta*upsilon+Ce*d*delta+Cr*d*upsilon-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*upsilon+c*d+c*delta-d*w-2*delta*upsilon+g*i2-c+2*upsilon)/(upsilon*(Cr*d+2))

Pn <= (Cr*Pr*d*upsilon-Cr*d*delta*upsilon+Ce*d*delta+Cr*d*upsilon-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*upsilon+c*d+c*delta-d*w-2*delta*upsilon+g*i2-c+2*upsilon)/(upsilon*(Cr*d+2))

(3)

C2 := (Cr*Pr*d*rho0-Cr*d*delta*rho0+Ce*d*delta+Cr*d*rho0-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*rho0+c*d+c*delta-d*w-2*delta*rho0+g*i2-c+2*rho0)/(rho0*(Cr*d+2)) <= Pn

(Cr*Pr*d*rho0-Cr*d*delta*rho0+Ce*d*delta+Cr*d*rho0-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*rho0+c*d+c*delta-d*w-2*delta*rho0+g*i2-c+2*rho0)/(rho0*(Cr*d+2)) <= Pn

(4)

 

NULL

# No equality constraints
#
# Inequality constraints must be of the form f[i](p1) <= 0
#
# Thus
#
# (1) For C1
#     so
      f[1] := (Pn) -> (Cr*Pr*d*upsilon - Cr*d*delta*upsilon + Ce*d*delta + Cr*d*upsilon - c*d*delta + d*delta*w - delta*g*i2 - Ce*d + 2*Pr*upsilon + c*d + c*delta - d*w - 2*delta*upsilon + g*i2 - c + 2*upsilon)/(upsilon*(Cr*d + 2)):
#
# (2) C2
#     so
      f[2] := (Pn) -> (Cr*Pr*d*rho0 - Cr*d*delta*rho0 + Ce*d*delta + Cr*d*rho0 - c*d*delta + d*delta*w - delta*g*i2 - Ce*d + 2*Pr*rho0 + c*d + c*delta - d*w - 2*delta*rho0 + g*i2 - c + 2*rho0)/(rho0*(Cr*d + 2))-Pn:

 

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

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

dLdPn := collect(diff(L, Pn), [Pn]):

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

# print~(KKT_conditions):


Analysis of dLdp1

with(LargeExpressions):
DLDPn := collect(dLdPn, Pn, Veil[K]);

-2*Pn*K[1]+K[2]

(5)

# Thus dLdp1 = 0 verifies

isolate((5), Pn)

Pn = (1/2)*K[2]/K[1]

(6)

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

[K[1] = 1/(-1+delta), K[2] = (-delta*mu[2]+Cn+Pr-delta+mu[2]+1)/(-1+delta)]

(7)

beta

beta

(8)

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

{beta[1] = (Cr*Pr*d*upsilon-Cr*d*delta*upsilon+Ce*d*delta+Cr*d*upsilon-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*upsilon+c*d+c*delta-d*w-2*delta*upsilon+g*i2-c+2*upsilon)/(upsilon*(Cr*d+2)), beta[2] = (Cr*Pr*d*rho0-Cr*d*delta*rho0+Ce*d*delta+Cr*d*rho0-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*rho0+c*d+c*delta-d*w-2*delta*rho0+g*i2-c+2*rho0)/(rho0*(Cr*d+2))}

(9)

infolevel[solve] := 2; sols := solve({seq(mu[i] >= 0, i = 1 .. 2), seq(Pn-beta[i] = 0, i = 1 .. 2), dLdPn = 0, dLdw = 0}, {Pn, w, seq(mu[i], i = 1 .. 2)})

Main: Entering solver with 6 equations in 4 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

 

(10)

Cmin_name := (Cr*Pr*d*rho0-Cr*d*delta*rho0+Ce*d*delta+Cr*d*rho0-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*rho0+c*d+c*delta-d*w-2*delta*rho0+g*i2-c+2*rho0)/(rho0*(Cr*d+2)); Cmax_name := (Cr*Pr*d*upsilon-Cr*d*delta*upsilon+Ce*d*delta+Cr*d*upsilon-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*upsilon+c*d+c*delta-d*w-2*delta*upsilon+g*i2-c+2*upsilon)/(upsilon*(Cr*d+2)); Complementary_Slackness := mu[1]*(Cmin_name-Pn), mu[2]*(Pn-Cmax_name); L2 := -`&pi;_m`(Pn, w)+add(Complementary_Slackness); dL2dPn := diff(L2, Pn); dL2dw := diff(L2, w); dL2dPn := map(simplify, %, size)

mu[1]*((Cr*Pr*d*rho0-Cr*d*delta*rho0+Ce*d*delta+Cr*d*rho0-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*rho0+c*d+c*delta-d*w-2*delta*rho0+g*i2-c+2*rho0)/(rho0*(Cr*d+2))-Pn), mu[2]*(Pn-(Cr*Pr*d*upsilon-Cr*d*delta*upsilon+Ce*d*delta+Cr*d*upsilon-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*upsilon+c*d+c*delta-d*w-2*delta*upsilon+g*i2-c+2*upsilon)/(upsilon*(Cr*d+2)))

 

-1+(Pn-Pr)/(1-delta)+(Pn-Cn)/(1-delta)-mu[1]+mu[2]

 

alpha*((((g*i2-c)*Cr-c+w+Ce)*d+g*i2-c)/(Cr*d+2)-g*i2+c)-(Pr-w-Crm)*alpha*d/(Cr*d+2)+Ce*d/(Cr*d+2)+mu[1]*(d*delta-d)/(rho0*(Cr*d+2))-mu[2]*(d*delta-d)/(upsilon*(Cr*d+2))

 

-((c-w-Ce)*d+g*i2-c)*alpha/(Cr*d+2)+(-Pr+w+Crm)*alpha*d/(Cr*d+2)+Ce*d/(Cr*d+2)+mu[1]*d*(-1+delta)/(rho0*(Cr*d+2))-mu[2]*d*(-1+delta)/(upsilon*(Cr*d+2))

(11)

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

Main: Entering solver with 4 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

 

"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                "Pn belongs to interval (LowerBound, UpperBound)"             else               "Pn is equal to the UpperBound"              end if           else             "Pn is equal to the LowerBound"            end if           , [SC_CS_sols]);  "

2

 

["Pn is equal to the LowerBound", "Pn is equal to the LowerBound"]

(12)

SC_CS_sols

{Pn = (Cr*Pr*d*rho0-Cr*d*delta*rho0+Ce*d*delta+Cr*d*rho0-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*rho0+c*d+c*delta-d*w-2*delta*rho0+g*i2-c+2*rho0)/(rho0*(Cr*d+2)), mu[1] = -rho0*(Ce*alpha*d+Crm*alpha*d-Pr*alpha*d-alpha*c*d+2*alpha*d*w-alpha*g*i2+Ce*d+alpha*c)/(d*(-1+delta)), mu[2] = 0}, {Pn = (Cr*Pr*d*upsilon-Cr*d*delta*upsilon+Ce*d*delta+Cr*d*upsilon-c*d*delta+d*delta*w-delta*g*i2-Ce*d+2*Pr*upsilon+c*d+c*delta-d*w-2*delta*upsilon+g*i2-c+2*upsilon)/(upsilon*(Cr*d+2)), mu[1] = 0, mu[2] = upsilon*(Ce*alpha*d+Crm*alpha*d-Pr*alpha*d-alpha*c*d+2*alpha*d*w-alpha*g*i2+Ce*d+alpha*c)/(d*(-1+delta))}

(13)

"w"??????""

w

(14)

Download q_w.mw

@dharr At the moment, I am finding it difficult to interpret the parameters that appear inside the square root in the solution. Would it be possible to simplify or reorganize the expression under the root so that the individual parameters and their roles are easier to understand?

Download Inside_root.mw

@dharr Thanks a lot.

@dharr can you help with above error?? DATA substitution error

@sand15 
Showing error while substituting DATA.
"Error, invalid input: `union` received [delta = .6, tau = .6, Ce = 0.5e-1, C0 = 0.8e-1, Cn = .4, Crm = .1, Cr = 0.5e-1, rho0 = .5, i2 = 0.5e-1, alpha = .8], which is not valid for its 2nd argument"

new_Q_solve_sand15.mw

Suppose I get a numerical solution after substituting the data. How can I identify which analytical solution (Pn = …, Pr = …, and w = …) this numerical result corresponds to?

@sand15 

OOPS! I mistakenly substituted i2 in the data — that was unprofessional on my part. Sorry for the inconvenience; I’ve now corrected it.

I’d like to zoom in more on the positive side of the y-axis. Also, is it possible to make the blue objective (OBJ) line dotted for values where i2 > k? This would help visualize what happens when the condition isn’t satisfied — similar to how the example figure shows the dotted blue line after the threshold and the red line before it.

Corrected sheet: A_no_error_worksheet_sand15.mw



Need plot like below sample: 

@sand15 Thankyou made changes accordingly.

I plotted the objective function, but the line is not visible because it appears flat (a straight line) on the graph. How can I rescale or adjust the y-axis so that the variation in the line becomes visible?

Download A_no_error_worksheet_sand15.mw

@sand15 

Thank you for taking the time to review my worksheet and for sharing the corrected version. I went through your file carefully.

After modifying some substitution values and parameters in the data, I noticed that in your version, the positive part of the objective function is shown as a blue line in the plot, whereas the red line does not appear.

Once again, thank you for your guidance, I’ll also make sure to format the loops properly and switch to the 1D input mode as you suggested.

Download A_no_error_worksheet_sand15.mw

@dharr I have solved it using KKT Condition, but lamda is zero. Is it right???

restart

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

_local(Pi)

Pi

(1)

NULL

Pi := proc (Pn, Pr, w) options operator, arrow; (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)*(1-(Pn-Pr)/(1-delta))-Ce*rho0*(1-(Pn-Pr)/(1-delta)) end proc

proc (Pn, Pr, w) options operator, arrow; (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)*(1-(Pn-Pr)/(1-delta))-Ce*rho0*(1-(Pn-Pr)/(1-delta)) end proc

(2)

NULL

NULL

C1 := (((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1) <= w

(((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1) <= w

(3)

L := Pi(Pn, Pr, w)-lambda*((((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1)-w)

(Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)*(1-(Pn-Pr)/(1-delta))-Ce*rho0*(1-(Pn-Pr)/(1-delta))-lambda*((((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1)-w)

(4)

K1 := diff(L, Pn) = 0; K2 := diff(L, Pr) = 0; K3 := diff(L, w) = 0; K4 := diff(lambda*((((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1)-w), lambda) = 0

1-(Pn-Pr)/(1-delta)-(Pn-Cn)/(1-delta)+(1/2)*(Pr-w-Crm)*alpha*((Cr*i2-Cr*tau)/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))*Cr/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))^2)*(1-(Pn-Pr)/(1-delta))/tau-(Pr-w-Crm)*alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)/(1-delta)+Ce*rho0/(1-delta)-lambda*Cr*rho0/(delta-1) = 0

 

(Pn-Cn)/(1-delta)+alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)*(1-(Pn-Pr)/(1-delta))+(1/2)*(Pr-w-Crm)*alpha*((-Cr*i2+Cr*tau)/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))+((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))*Cr/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))^2)*(1-(Pn-Pr)/(1-delta))/tau+(Pr-w-Crm)*alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)/(1-delta)-Ce*rho0/(1-delta)+lambda*Cr*rho0/(delta-1) = 0

 

-alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)*(1-(Pn-Pr)/(1-delta))+(1/2)*(Pr-w-Crm)*alpha*(2*delta-2)*(1-(Pn-Pr)/(1-delta))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))+lambda = 0

 

(((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1)-w = 0

(5)

sol := solve({K1, K2, K3, K4}, {Pn, Pr, lambda, w})

{Pn = (4*alpha*rho0^2*tau+Crm*alpha*rho0-alpha*delta*rho0+alpha*i2*rho0-alpha*rho0*tau+Ce*rho0+alpha*rho0+Cn)/(alpha*rho0+1), Pr = (4*alpha*rho0^2*tau+Crm*alpha*rho0+alpha*i2*rho0-alpha*rho0*tau+Ce*rho0+Cn+delta-1)/(alpha*rho0+1), lambda = 0, w = 4*rho0*tau+i2-tau}

(6)
 

``

Download Q_1.mw

@dharr 

The above solution was obtained when I solved the following objective function with a constraint, but it appears to be incorrect.

Could you please help me solve the objective function under the condition that the constraint is binding? I would also like to know the KKT condition under which the objective function is maximized and the optimal values of Pn, Pr, and w are obtained.

restart

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

_local(Pi)

Pi

(1)

``

Pi := proc (Pn, Pr, w) options operator, arrow; (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)*(1-(Pn-Pr)/(1-delta))-Ce*rho0*(1-(Pn-Pr)/(1-delta)) end proc

proc (Pn, Pr, w) options operator, arrow; (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*(1/2+(1/2)*(((-2*delta+2)*tau^2+((-Pn+Pr-delta+1)*Cr+(2*delta-2)*(w+i2))*tau+Cr*i2*(Pn-Pr+delta-1))/((4*delta-4)*tau+Cr*(Pn-Pr+delta-1))-i2)/tau)*(1-(Pn-Pr)/(1-delta))-Ce*rho0*(1-(Pn-Pr)/(1-delta)) end proc

(2)

``

NULL

C1 := (((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1) <= w

(((Cr+4*tau)*delta-4*tau+(Pn-Pr-1)*Cr)*rho0+(delta-1)*(i2-tau))/(delta-1) <= w

(3)
 

``

Download Q_1.mw

1 2 3 4 5 6 7 Last Page 1 of 10