Robert Israel

6492 Reputation

21 Badges

16 years, 151 days
University of British Columbia
Associate Professor Emeritus
North York, Ontario, Canada

MaplePrimes Activity


These are replies submitted by Robert Israel

@Fei Wang : actually I did this by hand, using the fact that cos(x)^2 + sin(x)^2 = 1.  But you could try something like this.  Since your y(x) is singular at x=0, I'll look for a linear equation with polynomial coefficients for x*y(x) = Y(x).  It's not guaranteed to work, but it does in this case.

> F:= x*(1/x + sin(x));
   L:= [seq(coeftayl(F, x=0, n), n=0 .. 20)];
   gfun[guesseqn](L,Y(x));
 

> Yde:= %[1][1];

Now the differential equation for y(x) is obtained by substituting Y(x) = x*y(x) here.

> yde:= simplify(eval(Yde, Y(x) = x*y(x))) = 0;

To check that this works:

> odetest(y(x) = 1/x + sin(x), yde);

0

@Fei Wang : actually I did this by hand, using the fact that cos(x)^2 + sin(x)^2 = 1.  But you could try something like this.  Since your y(x) is singular at x=0, I'll look for a linear equation with polynomial coefficients for x*y(x) = Y(x).  It's not guaranteed to work, but it does in this case.

> F:= x*(1/x + sin(x));
   L:= [seq(coeftayl(F, x=0, n), n=0 .. 20)];
   gfun[guesseqn](L,Y(x));
 

> Yde:= %[1][1];

Now the differential equation for y(x) is obtained by substituting Y(x) = x*y(x) here.

> yde:= simplify(eval(Yde, Y(x) = x*y(x))) = 0;

To check that this works:

> odetest(y(x) = 1/x + sin(x), yde);

0

Nearly all of Maple is based on the principle that things that are not known to be equal can be assumed to be unequal.  Thus Maple will let you divide x by a symbolic variable y without requiring you to assume y <> 0.  The geometry package is fundamentally different: it won't let you make a line through two points without knowing that the two points are distinct (and similarly for other geometric constructions).  I find that this makes the geometry package very frustrating to work with.  It would be nice if there were a way to tell the package that a variable is "generic", and thus algebraically independent of all other variables.

@PatrickT : See the help page ?$ for more on $,  It's not quite equivalent to seq because of issues with evaluation rules.
For that reason, I'd recommend only using $ in certain stereotypical situations where it is safe: one is x $ n where n is an integer, to repeat x n times (used especially in diff), another is [$ a .. b ] where a and b are integers, to get [a, a+1, ..., b].

M := Matrix(1..20000,1..3,rand(-100..100)):
Keep:= remove(t -> (M[t,1]<0), [$1..20000]):
M2:=M[Keep,..]:

@VuThanhLoc : As Laurent mentioned, that's not possible yet.

@Bruce Scranton : which page or section of the Programming Guide has a semicolon in that position?

The bug that started this thread is fixed.  In Maple 15.01 (2-D Math input):

> proc (a::integer)::integer; local k; a+k end proc;

proc(a::integer)::integer;  ...  end;

The other case mentioned by acer:

> proc(a::integer); local k; a+k end proc;

is not a bug, as pchin explained.  The semicolon before the "local" does not belong.  However, the error message could be more informative.

@maple : it might be possible to help if we could have a look at your actual Maple program.  There are often ways to reduce the amount of memory a program uses.

@maple : it might be possible to help if we could have a look at your actual Maple program.  There are often ways to reduce the amount of memory a program uses.

@brian bovril : Here's my modification for raw widths 4300 and 3000. 

Data:= [
 [138,    22],
 [152,    25],
 [156,    12],
 [171,    14],
 [182,    18],
 [188,    18],
 [193,    20],
 [200,    10],
 [205,    12],
 [210,    14],
 [214,    16],
 [215,    18],
 [220,    20]];
 N:= nops(Data);  # number of final widths
 W:= map(t -> t[1],Data):      # list of final widths
 need := Vector(map(t -> t[2],Data)):
       # numbers of each width needed
 R:= [430,300]: # widths of raw rolls
 Rmin:= R - [min(W)$2];
 selector:= proc(t,k) local i,s; s:= add(W[i]*t[i],i=1..N);
   evalb(s >= Rmin[k] and s <= R[k]) end proc;
for k from 1 to 2 do patterns[k]:= select(selector,map(t -> t - [1$N],
combinat:-composition(N+1,N) union combinat:-composition(N+2,N)
union combinat:-composition(N+3,N) union combinat:-composition(N+4,N)),k)
end do:
npatterns:= map(nops,patterns);
obj:= add(add((R[k]- add(W[j]*patterns[k][i][j],j=1..N))*x[k,i],i=1..npatterns[k]),k=1..2);
cons:= {seq(add(add(patterns[k][i][j]*x[k,i],i=1..npatterns[k]),k=1..2)>=need[j], j=1..N)}:
lpsol:=Optimization:-Minimize(obj,cons,assume=nonnegative);


It turns out that the linear programming solution is already integer-valued.


Raw 1: 1 of [215, 215], waste 0
Raw 1: 16 of [214, 215], waste 1
Raw 1: 14 of [210, 220], waste 0
Raw 1: 12 of [205, 220], waste 5
Raw 1: 10 of [200, 220], waste 10
Raw 1: 20 of [193, 220], waste 17
Raw 1: 18 of [188, 220], waste 22
Raw 1: 18 of [182, 220], waste 28
Raw 1: 14 of [171, 220], waste 39
Raw 1: 25 of [138, 138, 152], waste 2
Raw 2: 12 of [138, 156], waste 6




@brian bovril : Here's my modification for raw widths 4300 and 3000. 

Data:= [
 [138,    22],
 [152,    25],
 [156,    12],
 [171,    14],
 [182,    18],
 [188,    18],
 [193,    20],
 [200,    10],
 [205,    12],
 [210,    14],
 [214,    16],
 [215,    18],
 [220,    20]];
 N:= nops(Data);  # number of final widths
 W:= map(t -> t[1],Data):      # list of final widths
 need := Vector(map(t -> t[2],Data)):
       # numbers of each width needed
 R:= [430,300]: # widths of raw rolls
 Rmin:= R - [min(W)$2];
 selector:= proc(t,k) local i,s; s:= add(W[i]*t[i],i=1..N);
   evalb(s >= Rmin[k] and s <= R[k]) end proc;
for k from 1 to 2 do patterns[k]:= select(selector,map(t -> t - [1$N],
combinat:-composition(N+1,N) union combinat:-composition(N+2,N)
union combinat:-composition(N+3,N) union combinat:-composition(N+4,N)),k)
end do:
npatterns:= map(nops,patterns);
obj:= add(add((R[k]- add(W[j]*patterns[k][i][j],j=1..N))*x[k,i],i=1..npatterns[k]),k=1..2);
cons:= {seq(add(add(patterns[k][i][j]*x[k,i],i=1..npatterns[k]),k=1..2)>=need[j], j=1..N)}:
lpsol:=Optimization:-Minimize(obj,cons,assume=nonnegative);


It turns out that the linear programming solution is already integer-valued.


Raw 1: 1 of [215, 215], waste 0
Raw 1: 16 of [214, 215], waste 1
Raw 1: 14 of [210, 220], waste 0
Raw 1: 12 of [205, 220], waste 5
Raw 1: 10 of [200, 220], waste 10
Raw 1: 20 of [193, 220], waste 17
Raw 1: 18 of [188, 220], waste 22
Raw 1: 18 of [182, 220], waste 28
Raw 1: 14 of [171, 220], waste 39
Raw 1: 25 of [138, 138, 152], waste 2
Raw 2: 12 of [138, 156], waste 6




@Markiyan Hirnyk : Plotting is pretty straightforward.  Of course, we actually plot surfaces rather than volumes.  For the first case (triangles):

> with(plots):
   display([plot3d(min(a+b,1),a=0..1,b=0..1),
               plot3d([a,min(a+c,1),c],a=0..1,c=0..1),
               plot3d([min(b+c,1),b,c],b=0..1,c=0..1)],
style=patchnogrid, lightmodel=light3, axes=box,labels=[a,b,c]);

For the second,

 display([plot3d(min(sqrt(b^2+c^2),1),b=0..1,c=0..1),
               plot3d([a,min(sqrt(a^2+c^2),1),c],a=0..1,c=0..1),
               plot3d([min(sqrt(b^2+c^2),1),b,c],b=0..1,c=0..1)],
style=patchnogrid, lightmodel=light3, axes=box,labels=[a,b,c]);

 

@Markiyan Hirnyk : Plotting is pretty straightforward.  Of course, we actually plot surfaces rather than volumes.  For the first case (triangles):

> with(plots):
   display([plot3d(min(a+b,1),a=0..1,b=0..1),
               plot3d([a,min(a+c,1),c],a=0..1,c=0..1),
               plot3d([min(b+c,1),b,c],b=0..1,c=0..1)],
style=patchnogrid, lightmodel=light3, axes=box,labels=[a,b,c]);

For the second,

 display([plot3d(min(sqrt(b^2+c^2),1),b=0..1,c=0..1),
               plot3d([a,min(sqrt(a^2+c^2),1),c],a=0..1,c=0..1),
               plot3d([min(sqrt(b^2+c^2),1),b,c],b=0..1,c=0..1)],
style=patchnogrid, lightmodel=light3, axes=box,labels=[a,b,c]);

 

@Markiyan Hirnyk : There's a subtle bug in your code: sorting a named list changes the value of the list, but sorting a sublist does not.  Consider:



> LL:= [[1,3,2],[2,3,1]];
   for i from 1 to 2 do sort(LL[i],`>`) end do;
   LL;

What you want to do instead is

> LL:= map(sort, LL, `>`);
3 4 5 6 7 8 9 Last Page 5 of 187