Items tagged with constraint



Tour2:=[[[1, 2, 3, 4]], [[1, 2], [1, 3, 4]], [[1, 3], [1, 2, 4]], [[1, 4], [1, 2, 3]], [[1, 2], [1, 3], [1, 4]]]:

Kitonums code

seq(max(seq(add(d[s[i]]*x[s[i],s[i+1]], i=1..nops(s)-1) , s=t))<=K, t=Tour2); produces

18*x[1, 2]+26*x[2, 3]+11*x[3, 4] <= K, max(18*x[1, 2], 26*x[1, 3]+11*x[3, 4]) <= K, max(26*x[1, 3], 18*x[1, 2]+11*x[2, 4]) <= K, max(11*x[1, 4], 18*x[1, 2]+26*x[2, 3]) <= K, max(18*x[1, 2], 26*x[1, 3], 11*x[1, 4]) <= K

correctly. The problem is I want to pass this through LPSolve and it doesn't like it. So what I need is to convert it to a constraint it will accept. I found a method on stackexchange,

i'm not sure it even works.i would be great if a procedure could could convert the max's in the above expression, or change the code in bold.

max(6*x[1, 4],4*x[1, 2]+3*x[2, 3]), where x[i,j] are binary vars.
x4 >= 6*x[1, 4];
x4 >= 4*x[1, 2]+3*x[2, 3];
Objective:= x4;



Probably a brain fade, but I cant seem to code what i want.

Tour2:=[[[1, 2, 3, 4]], [[1, 2], [1, 3, 4]], [[1, 3], [1, 2, 4]], [[1, 4], [1, 2, 3]], [[1, 2], [1, 3], [1, 4]]];M:=nops(Tour2):

[[[1, 2, 3, 4]], [[1, 2], [1, 3, 4]], [[1, 3], [1, 2, 4]], [[1, 4], [1, 2, 3]], [[1, 2], [1, 3], [1, 4]]]


  Tours_Distances := Matrix
                     ( maxEnt,
                       [ seq
                         ( [ seq
                             ( `if`( numelems(Tour2[i])>=j,

Tours_Distances := Matrix(3, 5, {(1, 1) = d[1]*x[1, 2, 3, 4] <= K, (1, 2) = d[2]*x[1, 2] <= K, (1, 3) = d[3]*x[1, 3] <= K, (1, 4) = d[4]*x[1, 4] <= K, (1, 5) = d[5]*x[1, 2] <= K, (2, 1) = 0, (2, 2) = d[2]*x[1, 3, 4] <= K, (2, 3) = d[3]*x[1, 2, 4] <= K, (2, 4) = d[4]*x[1, 2, 3] <= K, (2, 5) = d[5]*x[1, 3] <= K, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = d[5]*x[1, 4] <= K})


convert( (2), 'list', 'nested' );

[[d[1]*x[1, 2, 3, 4] <= K, d[2]*x[1, 2] <= K, d[3]*x[1, 3] <= K, d[4]*x[1, 4] <= K, d[5]*x[1, 2] <= K], [0, d[2]*x[1, 3, 4] <= K, d[3]*x[1, 2, 4] <= K, d[4]*x[1, 2, 3] <= K, d[5]*x[1, 3] <= K], [0, 0, 0, 0, d[5]*x[1, 4] <= K]]



But what I want is:

d[1]*x[1,2]+d[2]*x[2,3]+d[3]*x[3,4]<=K,d[1]*x[1,2]<=K,d[1]*x[1,3]+d[3]*x[3,4]<=K;      #.....etc.






d[1]*x[1, 2]+d[2]*x[2, 3]+d[3]*x[3, 4] <= K, d[1]*x[1, 2] <= K, d[1]*x[1, 3]+d[3]*x[3, 4] <= K







In the context of solving mechanical constraint equations, I often need to simplify trigonometric equation. In mathematica, the FullSimplify function makes the simplification I need. But, i'm using Maple for a long time and I would rather contnue my calculation with Mathematica.

May you see if so can help me to simplify this equation ?

Here the equation I would like to simplify with Maple :

Here the result obtained with mathematica


Thanks a lot for your help

Hi everybody;

In the following attached file, I am trying to solve a system of nonlinear equations with one equality constraint. I have 9 equations and 9 unknowns. Attached file has composed of 3 main parts, first is input data, second is the 9 nonlinear equations from E_1 to E_9 and finally third part is constraint equation called C_1. My unknowns are "phi, theta, p, q, r, T, L, M and N". My question is that: Can Maple solve this problem?? Is there any solution to this problem or I have to change input data?? If Maple can solve this problem, how can I do that?? 

I appreciate your help in advance.

Hi I'm not really sure how to phrase this but I'm doing projectile motion and I'm try to graph the solutions for v_0 by theta_0.













Ab  = Required bearing area, sq in. (mm2)

As  = Required shear area at hole, sq in. (mm2)

Aw = Required cheek plate weld area, sq in. (mm2)

b     = Distance from center of eye to the cross section, in. (mm)

C    = Percentage distance of element from neutral axis

D    = Diameter of lifting pin, in. (mm)

e     = Distance between edge of cheek plate and edge of main plate, in. (mm)

Fa   = Allowable normal stress, ksi (kN/mm2)

Fv   = Allowable shear stress, ksi (kN/mm2)

Fw  = Allowable shear stress for weld electrodes, ksi (kN/mm2)

Fy   = Yield stress, ksi (kN/mm2)

fa   =  Computed axial stress, ksi (kN/mm2)

fb   =  Computed bending stress, ksi (kN/mm2)

fmax = Maximum principal stress, ksi(kN/mm2)

fv    = Computed shear stress, ksi (kN/mm2)

g     = Distance between edge of cheek plate and main structure, in. (mm)

h    = Length of lifting eye at any cross section between A-A and C-C, in. (mm)

n   = Total number of lifting eyes used during the lift

P  = Design load per lifting eye, kips (kN)

R  = Radius to edge of lifting eye, in. (mm)

Rh  = Radius of hole, in. (mm)

r    = Radius of cheek plate, in. (mm)

S   = Safety factor with respect to allowable stresses

s  = Cheek plate weld size, in. (mm)

T  = Total plate thickness, in. (mm)

Tp  = Main plate thickness, in (mm)

t    = Thickness of each cheek plate, in (mm)

te  = Cheek plate weld throat, in. (mm)

W  = Total lift weight of structure, kips (kN)

α  =  Angle of taper, deg.

β  =  Angle between vertical and lifting sling, deg.

θ  =  Angle between attaching weldment and lifting sling, deg.



The design load for each lifting eye is given by:


P := W*S/(n*cos(beta));

In the above equation, n refers to number of lifting eyes to used for the lift, S is the safety factor with respect to allowable stresses, W is the total weight to be lifted, and β is the angle between the vertical direction and the lifting sling.This analysis applies only to lifting eyes shaped like the one in Fig. 1. For other shapes, the designer should re-evaluate the equations.

Radius of liftimg eye hole will depend upon the diameter of the pin, D, used in the lifting shackle. It is recommeded that the hole diameter not greater than 1 / 16 in. (2 mm) larger than tha pin diameter. The required bearing area for the pin is

A__b >= P/(.9*F__y);

where Fy is the yield stress. This equation is based on allowable stresses as definde in Ref. 1, which considers stress concentrations in the vicinity of the hole. The designer may choose to use a technique which determines the stresses at the hole and should appropriately adjust the allowable stresses. The total plate thickness is then given by

T >= A__b/D;

At this point, if the thickness, T, is too large to be economically feasible, it may be desirable to use cheek plates (Fig.2) around the hole in order to sustain the bearing stresses. In this case, the above thickness, T, is divided into a main plate of thickness Tp and two cheek plates each of thickness t:

eqn1 := T = T__p+2*t;

It is recommended that t be less than Tp to avoid excessive welding. The radius to the edge of lifting eye plate and the radii of the cheek plates, if they are used, are governed by the condition that the pin cannot shear through these plates. The required area for shear is

A__s >= P/(.4*F__y);

It is possible to compute the required radii by equating the shaering area of the cheek plates plus the shearing area of the main plate to the total shear area. Theis a degree of uncertianty in choosing the appropriate shearing area. Minimum areas are used in the following equation, therefore, leading to conservative values for the radius of the main plate, R, and the radius of the cheek plate, r,

equ2 := (4*(r-R__h))*t+(2*(R-R__h))*T__p = A__s;

equ3 := R = r+e__cheek;

where Rh is the radius of the hole and e is the distance between the edge of the cheek plate and the edge of the main plate (Fig. 2). This difference should be large enough to allow space for welding the cheet plate to the main plate. A reasonable value for e is 1.5*t. It should be noted that the above equations assume there are two cheek plates. If cheek plates are not used, then simply let t equal zero and use Eq. 6 to determine R.

It is not necessary to check tension on this net section, since the allowable stress for shear is 0.4*Fy (Eq. 5); whereas the allowable stress for tension on a net section at a pin hole is given as 0.45*Fy (Ref. 1) which is greater than for shear. Size of weld between the cheek plates and the main plate can be determined as follows. The necessary weld area per cheek plate is

equ4 := A__w = P*t/(F__w*T);

where Fw is the allowable shear stress for the welding electrodes. The weld thickness, te is given by

equ5 := t__e = A__w/(2*Pi*r);

For a manual weld the size, s is given by

s := t__e*sqrt(2);

To assure that this weld size is large enough to insure fusion and minimize distortion, it should be greater than the AISC suggested Minimum Fillet Weld Sizes (Ref. 1).

The axial stress due to uniform tension along a section is

equ6 := f__a = P*sin(theta)/(T__p*h);

where h is the length of the section. The elemental bending stress which is distributed linearly along the section may be expressed as

equ7 := f__b = 12*P*C*(b*cos(theta)-.5*h*sin(theta)+R*sin(theta))/(T__p*h^2);

where C represents the distance of an element from the neutral axis and b is the distance from the center of the eye to the cross section. The shearing stress varies parabolically for section between A-A and B-B and is given as

equ8 := f__v = 1.5*P*cos(theta)*(-4*C^2+1)/(T__p*h);

It is felt that Eq. 13 (i.e., parabolic shear stress distribution) is applicable to the cross sections between A-A and B-B and does not apply to the cross sections between B-B and C-C in the area of the taper. The taper creates discontinuities on the shear plane, which result in significantly large shear stress concentratons along the edge of the taper coincident to point of maximum bending stress. This problem will be addressed ina subsequent section of this article.

The maximum principal stress that exists on an element is given by

f__max := .5*(f__a+f__b)+(((f__a+f__b)*(1/2))^.5+f__v^2)^.5;

or after dividing by the maximum allowable normal (i.e., tension) stress, Fa, gives a ratio that must be less than unity, where Fa has been taken as 0.6*Fy. A similar analysis for the maximum shear stress on the element yields

f__vmax := ((f__a+f__b)*(1/2))^2+f__v^2;

F__a := .6*F__y;

F__v := .4*F__y;

Ratio__tension := f__max/F__a;

Ratio__shear := f__vmax/F__v;

The designer should now select several critical elements throughout the plate and apply the restrains of Eq. 16 and 17 to obtain a required minimum length for the selected cross section. Eq 18 through 21 apply for an element at the neutral axis of the section. C will be zero and Eq. 11, 13 and 16 reduce to

P*sin(theta)/(.6*F__y*h*T__p)+(1.5*P*cos(theta)/(.6*F__y*h*T__p))^2 <= 1.0;

h >= P*(sin(theta)+(1+8*cos(theta)^2)^.5)/(1.2*F__y*T__p);

An element at the end of the section will be subjected to bending stresses but not shearing stresses.

For this case C = 0.5 and Eq. 16  becomes

P*sin(theta)/(.6*F__y*h*T__p)+6*P*(b*cos(theta)-.5*h*sin(theta)+R*sin(theta)) <= 1.0;

Using the quadratic formular to solve for h yields

h >= .5*(-2*P*sin(theta)/(.6*F__y*T__p)+(2*P*sin(theta)^2/(.6*F__y*T__p)+24*P*(b*cos(theta)+R*sin(theta))/(2*P*sin(theta)/(.6*F__y*T__p)))^.5);

The largest value of h predicted by Eqs. 19, 21 and 23 can be used as a first estimate for the length of the cross section; however, intermediate elements, that is, between the edge and the center of the cross section, should also be checked to determine the appropriate length, h, of the section under consideration.

Cross sections A-A and B-B should be analyzed using the above approach. The designer should use his own discretion to select other cross sections for analysis.At cross section A-A, the lifting eye is assumed to be welded with complete penetration to the support structure. Once length, h, is determined, the angle of taper, α, should be investigated. It can be shown that normal stress and shear stress are related by

equ9 := f__a+f__b = f__v*tan(alpha);

Minimum required length, h, for cross sections between B-B and C-C can be computed by calculating the maximum shear stress for the most critical element of the cross section, which occurs at the tapered surface. It can be shown that the maximum principal stress would not control the required length, h. Using Eqs. 11 and 12 in conjunction with Eq 24, the maximum shear stress yields the following:

(P*sin(theta)/(.4*F__y*h*T__p)+6*P*(b*cos(theta)-.5*h*sin(theta)+R*sin(theta))/(.4*F__y*T__p*h^2))*(.5^2+cot(alpha)^2)^.5 <= 1.0;


If the above inequality is not satisfied, the angle of the taper, α, must be adjusted.

The adequacy of the structure to which the lifting eye is to be attached should be checked to verify that it is capable of sustaining the loads from the lifting eye.

In some instances, it may be justifiable to use a more sophisticated technique for analyzing the lifting eye as well as the supporting structure.



Input Variables


W := 120;

n := 6;

P := W/n;

S := 3;

F__y := 300;

F__w := 450;

R := 90;

R__h := 89;

alpha := evalf(convert(45*degrees, radians));

beta := evalf(convert(30*degrees, radians));

theta := evalf(convert(20*degrees, radians));

d__pin := 100;

b := 200;

g := 50;





solve({equ1, equ2, equ3, equ4, equ5, equ7, equ8, equ9}, {A__s, A__w, C, T, T__p, h, r, t, e__cheek});












Good Evening Everybody,

Could any one help me with the attached file. I'm trying to solve 9 equations with 9 unknowns with many constraints, I'm getting no output from Maple. Please help.






I have still some difficulties to conduct some specific trigonometric simplications but which are very common in mechanism study.

The equations are in the form :

sin(gamma0(t))*cos(beta0(t)) = -(sin(psi[1](t))*cos(theta[1](t))*cos(gamma[1](t))+sin(psi[1](t))*sin(theta[1](t))*sin(gamma[1](t))-cos(theta[1](t))*cos(psi[1](t))*sin(gamma[1](t))+cos(psi[1](t))*sin(theta[1](t))*cos(gamma[1](t)))*cos(beta[1](t))

I would like to obtain this equation after simplifications :

sin(gamma0(t))*cos(beta0(t)) = cos(beta[1](t))*sin(gamma[1](t)-theta[1](t)-psi[1](t))

I try to make a procedure to automatize the simplification of this kind of trigonometric equation.

Strangely, I noticed that the simplification is done only if there is a minus before the combine function. The simplification works but the result is wrong because i didn't obtain the good sign.

For you information, I try to make these simplifications with MMA and the FullSimplify function of MMA gives directly the expected result that is to say :

I'm sure that it shoud exist a good way to conduct this kind of simplications in Maple.

Can you help me to correct my procedure so to obtain the good result and be enough general, adaptative ? 

Code here and attached in this post :

constants:= ({constants} minus {gamma})[]:
`evalf/gamma`:= proc() end proc:
`evalf/constant/gamma`:= proc() end proc:
Angular Constraint equations
eq_liaison:=sin(gamma0(t))*cos(beta0(t)) = -(sin(gamma[1](t))*sin(psi[1](t))*sin(theta[1](t))-sin(gamma[1](t))*cos(theta[1](t))*cos(psi[1](t))+cos(gamma[1](t))*sin(psi[1](t))*cos(theta[1](t))+cos(gamma[1](t))*cos(psi[1](t))*sin(theta[1](t)))*cos(beta[1](t)); 
TrigoTransform2:= proc(Eq)
local S,S1,tt,pp,Eq2,ListVariables,ListVariablesMod,Subs,size,rhsEq2,lhsEq2;
#Construit une liste à plat#
ListVariables:=indets(Eq, function(identical(t)));
#Variables Changement#
print("Equation traitée=",Eq2): 
Eq2:=subs(Subs, Eq2);
print("Equation après subs=",Eq2): 
#Trigonometric transformations#
cos(u::anything)*sin (v::anything)+sin(u::anything)*cos(v::anything)=sin(u+v), 
-sin(v::anything)*cos(u::anything)-sin(u::anything)*cos(v::anything)=-sin(u+v)], simplify(lhs(Eq2), size));
print("Equation lhsEq2 première analyse=",lhsEq2):
cos(u::anything)*sin (v::anything)+sin(u::anything)*cos(v::anything)=sin(u+v), 
-sin(v::anything)*cos(u::anything)-sin(u::anything)*cos(v::anything)=-sin(u+v)], simplify(rhs(Eq2), size));
print("Equation rhsEq2 première analyse=",rhsEq2):
print("Equation lhsEq2=",lhsEq2):
end try;
print("Equation rhsEq2=",rhsEq2):
end try;
Eq2:= lhsEq2=rhsEq2;
#Variables Changement#
end proc:


Thanks a lot for your help.

Hi everyone...!

Can somebody tell me how to express this equation in Maple? 

xij <= zkl ; ∀ i ∈ I: S(i)=k, ∀ j ∈ B: R(j)=l; 

Currently I'm dealing with containerization problem and have 4 indexes in the constraints (namely: i for item, j for container, k for shipment, l for route, S for Set of Shipment, and R for Set of Route) while x and z are binary variables. What I want to express is: (for example), item 1,2,3 are in shipment 1, item 4,5 are in shipment 2, etc etc. SO, if i = 1,2,3 then the value of k will be 1. If i = 4,5 then the value of k will be 2, etc. Same thing goes to j and l, (for example) if j = 1,2 then the value of l will be 1, etc etc. Further depcition is more or less like this:

S(i) = k

S(1) = 1

S(2) = 1

S(3) = 1

S(4) = 2

S(5) = 2


Thank you very much for the help.

Wonder if this can be accomplished in Maple.

so I have a list of 100 items labeled {1..100} of various value {$100, $160, $220, ......  , }

the task is to distribute these items among 3 people A,B,C so they get an approximately equal share.

Adding the values and dividing by 3 gives the dollar total to aim for. 

This post has C.Love procedure for evenly sized groups

but what i want is a method for different sized groups. ie 25 items for A, 35 for B and 40 for C (user defined).

additionally there is a fixed constraint: A has been bequeathed items 1,4,8; B items 2 and 20; C item 50.


S:= {3, 4, 5, 6, 8, 9, 28, 30, 35}:
SL:= [A,B,C,D,E,F,G,H,I]:
assign(Labels ~ (S) =~ SL); #Create remember table.
AllP:= [seq(P, P= Iterator:-SetPartitions(S, [[3,3]], compile= false))]:
lnp:= evalf(ln((`*`(S[]))^(1/3))):

Var:= proc(P::({list,set}(set)))
local r:= evalf(`+`(map(b-> abs(ln(`*`(b[]))-lnp), P)[]));
end proc:

Min:= proc(S::{list,set}, P::procedure)
local M:= infinity, X:= (), x, v;
     for x in S do
          v:= P(x);
          if v < M then  M:= v;  X:= x  end if
     end do;
end proc:

ans:= Min(AllP, Var);
              [{3, 9, 35}, {4, 8, 28}, {5, 6, 30}]
subsindets(ans, posint, Labels);
               [{I, A, F}, {B, E, G}, {C, D, H}]



Hi all

Assume that we have a cost functional, namely J, which we want to be minimized but we have to set of constraint CC1 and CC2.

what should we do it?

The code which I have written is attached(Minimize J under CC1[i]=0 and CC2[i]=0)

 any suggestion or guide is praiseworthy.

Thanks in advance


Mahmood   Dadkhah

Ph.D Candidate

Applied Mathematics Department

I have a linear problem with 4 variables (p0, p1,p2, p3) and a list of inequality constraints (shown below).  I would like to plot a polyhedral in 3 dimensions (p1,p2, p3 and omitting p0) showing the region that satisfies the inequalities.  That is, something similar to plots[inequal] but in 3d.  Any pointers would be appreciated.

/* Constraints */
+p0 <= 60;
-p0 +p1 >= 4;
-p0 +p2 >= 5;
-p0 +p3 >= -12;
+p0 -p2 >= -33;
+p1 -p2 >= -36;
+p2 <= 67;
-p2 +p3 >= -35;
+p0 -p3 >= 2;
+p1 -p3 >= 0;
+p2 -p3 >= 11;
+p3 <= 57;
+p0 -p1 >= -7;
+p1 <= 43;
-p1 +p2 >= 0;
-p1 +p3 >= -9;


Hi all,

Hope all to be in good health.

I have written following program to obtain minimum  under som constraints but it doesn't work due to some unknown error.

can any one help me?



best wishes

Mahmood   Dadkhah

Ph.D Candidate

Applied Mathematics Department


     I an trying to plot a function of a single variable, which is an implicit function of another variable, i.e. I want to plot F(x(t)), given that x and t are related through the implicit constraint equation f(x,t) = 0. Is there any plot stuctures in Maple that would easily let me do this? I tried implicit plot but this seems insufficient. 

     As an example, consider plotting F = x + x^2 subject to f = x + sin(x) + ln (t) = 0. I could also write this as  a function subject o a differential constraint, as is f = diff(x(t), t) + 1/t + (diff(x(t), t))*cos(x(t)) = 0 and try to use some sort of implicit DE plotting routine. 

     Any ideas?


I've got a set

E:={(x,y,z): x^2+y^2=-2*z-x, z^2+y^2=1} and need to find points of E which have minimal or maximal distance from (0,0,0). I've set up the Lagrangian as F:=sqrt(x^2+y^2+z^2) + L1(x^2+y^2+2z+x)+L2(z^2+y^2-1)

and consequently obtained the equations:

x/sqrt(x^2+y^2+z^2) + 2*x*L1+L1=0

y/sqrt(x^2+y^2+z^2) + 2*y*L1+2*y*L2=0


for which I've set up
eqn1,eqn2,eqn3 as the three equations and vars:=x,y,z

and used solve() but I'm not getting the right answer( I need to first express x,y,z in terms of L1, L2 and then get values for L1 and L2 by substituting in the constraints and eventually get values of x,y,z.)

How should I implement that?

Hi all,

I have lots of contstraint equations group and I want to fund a group of parameters which can fit them. 

For example, these are a simple constraint eqqations group:
eqs:{x1>0, x2>0 x1<1000, x2<1000, x1+x2>300,x1+x2<700}

Through SolveTools library, I can determine whether there is a group of parameters.


LinearMultivariateSystem({x1 > 0, x1+x2 > 300, x2 < 1000, x1+x2 < 700, x2 > 0*x1 and 0*x1 < 1000}, [x1, x2]);

{[{x1 <= 300, 0 < x1}, {x2 < -x1 + 700, 300 - x1 < x2}],[{300 < x1, x1 < 700}, {0 < x2, x2 < -x1 + 700}]}


Then, if I want to find a group of parameter a group of parameters (ex, x1=300, x2=200 in this case), how should I do?

1 2 Page 1 of 2