Andiguys

85 Reputation

5 Badges

1 years, 168 days

MaplePrimes Activity


These are questions asked by Andiguys

I'm getting an error while executing the for loop after adding a constraint. Could you please help me identify and fix the syntax issue?

restart

C1 := (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+a*delta+c*d-d*w-2*delta*rho0+g*i2-a+2*rho0)/(rho0*(Cr*d+2)) <= Pn; C11 := 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+a*delta+c*d-d*w-2*delta*upsilon+g*i2-a+2*upsilon)/(upsilon*(Cr*d+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+a*delta+c*d-d*w-2*delta*rho0+g*i2-a+2*rho0)/(rho0*(Cr*d+2)) <= Pn

 

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+a*delta+c*d-d*w-2*delta*upsilon+g*i2-a+2*upsilon)/(upsilon*(Cr*d+2))

(1)

`&Pi;m` := (Pn-Cn)*(1-(Pn-Pr)/(1-delta))+(Pr-w-Crm)*alpha*((((-a+0.4e-1*g)*Cr-c-(0.6e-1*alpha*d*rho0^2+2*d*delta*rho0-2*Pr*d*rho0+2*alpha*c*rho0^2-0.8e-1*alpha*g*rho0^2-2*a*d*delta+2*c*d^2*delta+2*Cn*d*rho0+0.3e-1*Cr*d^2*rho0^2-Cr*d^2*rho0+0.8e-1*d*delta*g+0.6e-1*d^2+0.3e-1*Cr*alpha*d^2*rho0^2+Cn*Cr*d^2*rho0-Cr*Pr*d^2*rho0+Cr*d^2*delta*rho0+2*Crm*alpha*d*rho0^2-2*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*d+2)+0.12e-2*g-0.3e-1*a

(2)

DATA := [delta = .7, a = .2, d = .9, g = .3, c = 0.2e-1, sigma = .5, Cn = .35, Crm = .1, Cr = 0.1e-1, rho0 = .4, Pr = .6, alpha = .9, s = .21, upsilon = .95]

TRC := proc (Pn, w) options operator, arrow; eval(`&Pi;m`, DATA) end proc; C2 := subs(DATA, C1); C22 := subs(DATA, C11)

-.3359880537*Ce+.1119960179*i2-.3359880537*w+.8320557491 <= Pn

 

Pn <= -.1414686542*Ce+0.4715621807e-1*i2-.1414686542*w+.8713918944

(3)

C3 := isolate(C2, w); C33 := isolate(C22, w)

-.3359880537*w <= Pn+.3359880537*Ce-.1119960179*i2-.8320557491

 

w <= 6.159611112-7.068703704*Pn-.9999999999*Ce+.3333333333*i2

(4)

t := {0.3e-1, 0.5e-1, 0.7e-1, 0.9e-1}; ts := {0.4e-1, 0.8e-1, .12}

M := Matrix(nops(t)*nops(ts), 3); rr := 0; for Ce in t do for i2 in ts do C4 := eval(C3, [Ce = t, i2 = ts]); C44 := eval(C33, [Ce = t, i2 = ts]); s := Optimization:-Maximize(TRC(Pn, w), `union`(C4, C44), Pn = 0 .. 1, w = 0 .. 1, assume = nonnegative); stemp := s[1]; Pntemp := s[2][1]; wtemp := s[2][2]; rr := rr+1; M[rr, 1 .. 3] := `<|>`(Ce, i2, stemp); print(Ce, i2, stemp, Pntemp, wtemp) end do end do

Error, invalid input: `union` received -.3359880537*w <= Pn-.8264559482, which is not valid for its 1st argument

 

R := Array(ArrayTools:-Reshape(M,[3,4,3]),datatype=float[8]):

func := Interpolation:-SplineInterpolation([[0.04, 0.08, 0.12],[0.03, 0.05, 0.07, 0.09]],R[..,..,3]):

conts := [seq(min(R[..,..,3])..max(R[..,..,3]),(max(R[..,..,3])-min(R[..,..,3]))/8)];

[HFloat(0.0)]

(5)

``

 

ContoursWithLabels:= proc(

ContoursWithLabels(func(x, y), x = 0.3e-1 .. .15, y = 0.2e-1 .. .1, contours = conts, decplaces = 4, Coloring = [colorstyle = HUE, colorscheme = ["Blue", "Gold"], style = surface], TextOptions = [font = [HELVETICA, BOLD, 9], color = black], GraphicOptions = [thickness = 0], ImplicitplotOptions = [gridrefine = 3], size = [700, 600], labels = [':-C__e', ':-i__2'])

Download Q_Constraint_error.mw

I currently have a 3D plot where the axes are Pn​, w, and the objective value (TM1, TM2, TM3 are all positive). I want to convert this into a 2D regional plot with Pn on the x-axis and w on the y-axis. How do I write the syntax for generating such a 2D region plot?

restart

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

_local(Pi)

Pi

(1)
 

TM1 := (Pn-.35)*(3.000000000-3.333333333*Pn)+.1115859938-.2510684861*w

(Pn-.35)*(3.000000000-3.333333333*Pn)+.1115859938-.2510684861*w

(2)

TM2 := (Pn-.348)*(2.996666666-3.333333333*Pn)+.1017286174-.2299240474*w

(Pn-.348)*(2.996666666-3.333333333*Pn)+.1017286174-.2299240474*w

(3)

TM3 := (Pn-.348)*(2.996666666-3.333333333*Pn)+.1018208882-.2301325952*w

(Pn-.348)*(2.996666666-3.333333333*Pn)+.1018208882-.2301325952*w

(4)

S1 := plot3d(TM1, Pn = 0 .. 1, w = 0 .. 1, orientation = [165, 75, 0], color = "SkyBlue"); S2 := plot3d(TM2, Pn = 0 .. 1, w = 0 .. 1, orientation = [165, 75, 0], color = "Yellow"); S3 := plot3d(TM3, Pn = 0 .. 1, w = 0 .. 1, orientation = [165, 75, 0], color = "Red")

display({S1, S2, S3})

 

``

Download Plot_3D_to_2D.mw

 

I would like to combine all the plots into a single figure. The curves S1, S2, and S3 represent the manufacturer’s profit as Ce​ varies, and S12, S22, and S33 represent the retailer’s profit for the same changes in Ce​. I want all of these displayed together in one plot using a dual y-axis: one axis for the manufacturer’s profit and the other for the retailer’s profit, with Ce on the x-axis. How to create such a dual-axis plot with appropriate scaling so that the differences between the curves are also clearly visible.

restart

with(Optimization); with(plots); with(Student[VectorCalculus]); with(LinearAlgebra)

``

_local(Pi)

Pi

(1)

`&Pi;_12` := (0.1455251030e-2*Ce+.5352049476)*(0.369876310e-1-0.3638127575e-2*Ce)+(.8*(-.1671790360+1.121361872*Ce))*(0.1849381518e-1-0.1819063782e-2*Ce)-Ce*(0.1849381518e-1-0.1819063782e-2*Ce)

(0.1455251030e-2*Ce+.5352049476)*(0.369876310e-1-0.3638127575e-2*Ce)+(-.1337432288+.8970894976*Ce)*(0.1849381518e-1-0.1819063782e-2*Ce)-Ce*(0.1849381518e-1-0.1819063782e-2*Ce)

(2)

`&Pi;_22` := (0.1455251030e-2*Ce+.5356096675)*(0.355258312e-1-0.3638127575e-2*Ce)+(.8*(-.1184158360+1.121361872*Ce))*(0.1776291535e-1-0.1819063782e-2*Ce)-Ce*(0.1776291535e-1-0.1819063782e-2*Ce)

(0.1455251030e-2*Ce+.5356096675)*(0.355258312e-1-0.3638127575e-2*Ce)+(-0.9473266880e-1+.8970894976*Ce)*(0.1776291535e-1-0.1819063782e-2*Ce)-Ce*(0.1776291535e-1-0.1819063782e-2*Ce)

(3)

`&Pi;_32` := (0.1455251030e-2*Ce+.5356038465)*(0.355403838e-1-0.3638127575e-2*Ce)+(.8*(-.1179012835+1.121361872*Ce))*(0.1777019161e-1-0.1819063782e-2*Ce)-Ce*(0.1777019161e-1-0.1819063782e-2*Ce)

(0.1455251030e-2*Ce+.5356038465)*(0.355403838e-1-0.3638127575e-2*Ce)+(-0.9432102680e-1+.8970894976*Ce)*(0.1777019161e-1-0.1819063782e-2*Ce)-Ce*(0.1777019161e-1-0.1819063782e-2*Ce)

(4)

S12 := plot(`&Pi;_12`, Ce = 0 .. 0.9e-1, color = [red], labels = ["Ce", "Manufacturer Profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("m"),mn("W"));`]); S22 := plot(`&Pi;_22`, Ce = 0 .. 0.9e-1, color = [green], labels = ["Ce", "Manufacturer profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("m"),mn("D"));`]); S32 := plot(`&Pi;_32`, Ce = 0 .. 0.9e-1, color = [blue], labels = ["Ce", "Manufacturer profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("m"),mn("S"));`])

 

 

 

`&Pi;_1` := (-0.60726413e-1*Ce+.6173851967)*(0.1849381518e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1849381518e-1-0.1819063782e-2*Ce)^2

(-0.60726413e-1*Ce+.6173851967)*(0.1849381518e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1849381518e-1-0.1819063782e-2*Ce)^2

(5)

`&Pi;_2` := (-0.60726413e-1*Ce+.5929853242)*(0.1776291535e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1776291535e-1-0.1819063782e-2*Ce)^2

(-0.60726413e-1*Ce+.5929853242)*(0.1776291535e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1776291535e-1-0.1819063782e-2*Ce)^2

(6)

`&Pi;_3` := (-0.60726413e-1*Ce+.5932282299)*(0.1777019161e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1777019161e-1-0.1819063782e-2*Ce)^2

(-0.60726413e-1*Ce+.5932282299)*(0.1777019161e-1-0.1819063782e-2*Ce)-0.2500000000e-1*(0.1777019161e-1-0.1819063782e-2*Ce)^2

(7)

S1 := plot(`&Pi;_1`, Ce = 0 .. 0.9e-1, color = [yellow], labels = ["Ce", "Retailer profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("r"),mn("W"));`]); S2 := plot(`&Pi;_2`, Ce = 0 .. 0.9e-1, color = [black], labels = ["Ce", "Retailer  profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("r"),mn("D"));`]); S3 := plot(`&Pi;_3`, Ce = 0 .. 0.9e-1, color = [grey], labels = ["Ce", "Retailer profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("r"),mn("S"));`])

 

 

 

dualaxisplot(plot(`&Pi;_22`, Ce = 0 .. 0.9e-1, color = ["red"], labels = ["Ce", "Manufacturer profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("m"),mn("D"));`]), plot(`&Pi;_2`, Ce = 0 .. 0.9e-1, color = ["green"], labels = ["Ce", "Retailer profit"], labeldirections = ["horizontal", "vertical"], legend = [`#msubsup(mi("Pi"),mi("r"),mn("D"));`]), title = "fairnes cost Comparison")

 

display({S1, S12, S2, S22, S3, S32})

 
 

``

Download All_plots_Combined.mw

How can I isolate the positive terms on one side and the negative terms on the other? Is there a systematic way to split and rearrange the expression so that I can determine the conditions under which L is positive or negative?

restart

``

L := simplify(-rho0*(-Cn*Cr*alpha*d*rho0+Cr*Pr*alpha*d*rho0-Cr*alpha*d*delta*rho0+Ce*alpha*d*delta+Cr*alpha*d*rho0-Crm*alpha*d*delta+Pr*alpha*d*delta-alpha*c*d*delta-alpha*delta*g*i2-Ce*alpha*d-Ce*d*delta-2*Cn*alpha*rho0+Crm*alpha*d-Pr*alpha*d+2*Pr*alpha*rho0+2*a*alpha*delta+alpha*c*d-alpha*c*delta-2*alpha*delta*rho0+alpha*g*i2+Ce*d-2*a*alpha+alpha*c+2*alpha*rho0)/(Cr*alpha*d*delta*rho0^2-Cr*alpha*d*rho0^2+2*alpha*delta*rho0^2-2*alpha*rho0^2-d*delta^2+2*d*delta-d)) = 0

-2*((((-(1/2)*rho0*Cr-(1/2)*Crm-(1/2)*c+(1/2)*Ce+(1/2)*Pr)*delta-(1/2)*Cr*(Cn-Pr-1)*rho0+(1/2)*Crm+(1/2)*c-(1/2)*Ce-(1/2)*Pr)*d+(-(1/2)*i2*g+a-rho0-(1/2)*c)*delta+(-Cn+Pr+1)*rho0+(1/2)*i2*g-a+(1/2)*c)*alpha-(1/2)*d*Ce*(delta-1))*rho0/((rho0^2*(Cr*d+2)*alpha-d*(delta-1))*(delta-1)) = 0

(1)
 

``

Download Positive_Negative_Isolation.mw

How can I use an if statement inside a do - loop in maple and then plot a figure based on the conditional results? I need help with the correct syntax for combining the do-loop, `if` condition, and plotting command.

Sheet attached below:
Algorithmm.mw

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