Robert Israel

6577 Reputation

21 Badges

18 years, 210 days
University of British Columbia
Associate Professor Emeritus
North York, Ontario, Canada

MaplePrimes Activity


These are answers submitted by Robert Israel

Your code was garbled because you have to use < ; (without the space) for < on this forum: otherwise your < is mistaken for the start of an html tag. Are you looking for something like this?
> animate(..., background = ...);
Or perhaps
> back := (some plotting command):
  for i from 1 to n do 
   frame[i] := (some plotting command) 
  end do:
  display([seq(display([frame[i],back]), i=1..n)],
    insequence=true);
> map(diff, A, k[1,1]);
On my Windows system, those DLL's (and the directory they are in) are automatically deleted when I do a restart in Maple 10. I don't know if there's a way to do it without a restart: the help pages don't indicate any provision for unlinking an external file.
RiemannSum and ApproximateInt which it calls) don't seem to have any provision for shading the boxes. But this kludge seems to work.
> Q:= RiemannSum(...):
  P:= select(has,Q,STYLE(LINE)):
  subs(op(P)=POLYGONS(subs([Float(undefined),0.]=NULL,
convert(op([1,1],P),listlist)),COLOUR(RGB,.7,.9,.7)),Q);
The short answer to "why" is that sum(r[i]*y[i], i=1..m) does not actually contain y[1]. See for yourself:
> sum(r[i]*y[i], i=1..m);
sum(r[i]*y[i], i=1..m) No y[1] there! One thing you could do is this:
> eval(eval(sum(r[i]*y[i],i=1..m),m=3),y[1]=2);
2*r[1]+r[2]*y[2]+r[3]*y[3] Note: I use eval rather than subs, to have the result evaluated after substitution.
Also note that a list of the RGB values (on a 0-255 scale) corresponding to colour names can be found on the help page ?plot,colornames. I wonder why the programmer of student[leftbox] chose to code the RGB colour rather than using one of the colour names.
You might try this simpler alternative:
> q1:= plot([u,v],x=-8..11,y=-9..7,color=[blue,green]):
  vf:= unapply(v,x);
  q2:= plot(u-v, x=inters[1] .. inters[3], filled=true,    
    colour="Gainsboro"):
  q3:= plottools[transform]((x,y) -> [x,y+vf(x)])(q2):
  display([q1,q3]);
Please note that to enter < in this forum, you have to use < ; (without the space), otherwise it will interpret your < as the start of an HTML tag. You seem to be working with int in the Student[VectorCalculus] package. There isn't a "built-in" Cylinder there, but you can use the generic Region.
> with(Student[VectorCalculus]):
  int(f(x,y,z),[x,y,z]=Region(-sqrt(R) .. sqrt(R),
    -sqrt(R-x^2) .. sqrt(R-x^2), 0 .. m));
Unfortunately this doesn't work well with coordinates other than cartesian. For example, I would have hoped that you could do it this way:
 SetCoordinates(cylindrical[r,theta,z]);
 int(f(r,theta,z),[r,theta,z]=Region(0 .. sqrt(R), 0 .. 2*Pi,
    0 .. m));
But that does not work: it gives you an integral of f(r,theta,z) dz dtheta dr, when what you need is f(r,theta,z) r dz dtheta dr.
If you mean settings of axes, style, etc, those can be written in the plot command rather than set with the menu. See the help page ?plot,options. The one thing that can't be set in the command is the size of the plot in the worksheet.
I assume you mean unapply, not apply. Without knowing more about your objective, it's hard to give advice, but you might find it more convenient to use x[i] rather than x||i.
Suppose L is a list of expressions A[i]*x + B[i]*y - C[i], and S is a subset of {$1..n}. Then applyop(`*`,S,L,-1) multiplies the expressions numbered by members of S by -1. Make each of the results r into an inequality r < 0, and then you can call LinearUnivariateSystem on the result. Thus:
> L := [seq](A[i]*x + B[i]*y - C[i], i=1..8);
  P:= map( t ->  
     SolveTools[Inequality][LinearUnivariateSystem](
       map(`<`, applyop(`*`,t,L,-1), 0), x),
     combinat[powerset]({$1..8}));
But to actually get a point in each region, I think linear programming (LPSolve in the Optimization package) might be better. If a region given by a set of inequalities A[i]*x + B[i]*y - C[i] < 0 is nonempty and bounded, you can find a point in it by maximizing t such that A[i]*x + B[i]*y - C[i] + t <= 0. If the region is unbounded, add a constraint t <= M for some large M (say 10^6; this might have to be adjusted). So I might try something like this:
> getpt:= proc(T)
    local R, t;
    R:= convert(map(s -> (s + t <= 0), T),set) 
      union {t <= 10^6};
    R:= Optimization[LPSolve](t, R, maximize = true);
    if R[1] <= 0 then NULL 
    else subs(R[2],[x,y])
    fi;
  end;
  
  map(t -> getpt(applyop(`*`,t,L,-1)), 
        combinat[powerset]({$1..8}));
This is a lot simpler:
> nearprime:= proc(x)
  local x1, x2;
    x1:= nextprime(x-1):
    x2:= prevprime(x):
    if x1 + x2 <= 2*x then x1 else x2 end if;
  end:
As was mentioned, black can't be obtained by a HUE number. You could do something like the following (see the help page ?plot3d,colorfunc), where the colour function is given by a list of three functions of the parameters s and t (representing red, green and blue components). When all three are 0 (at the centre of the circle), the colour is black.
> plot3d([r,t,0], r=0..1, t=0..2*Pi, orientation=[-90,0],
    colour=[r*(1+cos(t)),r*(1+cos(t+2*Pi/3)),
                  r*(1+cos(t-2*Pi/3))],
    style=patchnogrid, coords=cylindrical);
It doesn't seem to like the "min", but you can try this:
> f:= eval(p(x), min = ((a,b) -> (a + b - abs(a-b))/2)):
  Optimization[Maximize](f, x = 1 .. 2, 
    method = branchandbound);
[.600000000000000088, [x = 1.60000000000000008]]
This is not an array, it's a list.
> select(type, a, numeric);
If it really was an array (or an Array), you could convert it to a list first.
> A:= array(a);
  select(type, convert(A, list), numeric);
First 117 118 119 120 121 122 123 Last Page 119 of 138