Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 27 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

Here's a very clean and robust way to do it:
 

restart:

#Adjustment factors:
AdjFact:= Record(
   ':-Wmu'= 5,    ':-Wsigma'= -7, #winner's factors
   ':-Lmu'= -100, ':-Lsigma'= -60 #loser's factors
):

RC:= proc(W::record(mu,sigma), L::record(mu,sigma))
local
   t,
   dist:= evalf@unapply(Statistics:-CDF(Normal(W:-mu, W:-sigma), t), t),
   postW:= Record(
      ':-mu'= W:-mu + AdjFact:-Wmu*dist(W:-mu),
      ':-sigma'= W:-sigma + AdjFact:-Wsigma*dist(W:-mu)
   ),
   postL:= Record(
      ':-mu'= L:-mu + AdjFact:-Lmu*dist(L:-mu),
      ':-sigma'= L:-sigma + AdjFact:-Lsigma*dist(L:-mu)
   )
;
   userinfo(
      1, RC,
      sprintf(
         "Winner = %d +- %d; Loser = %d +- %d.",
         round~([postW:-mu, postW:-sigma, postL:-mu, postL:-sigma])[]
      )
   );
   postW, postL
end proc:

Update:= proc(
   Standings::table,
   Games::list([{name,string}, {name,string}]),
   {inplace::truefalse:= true}
)
local
   R:= `if`(inplace, Standings, copy(Standings)),
   G
;
   for G in Games do
      if assigned(R[G[1]]) and assigned(R[G[2]]) then
         (R[G[1]], R[G[2]]):= RC(R[G[1]], R[G[2]])
      else
         error "Player %1 or %2 not found in Standings", G[]
      end if
   end do;
   `if`(inplace, [][], R)
end proc:
      

#Example usage (using exactly the same scenario as you did):

#Initial standings ("laws"):
Standings:= table([
   A1= Record(mu= 1007, sigma= 47),
   A2= Record(mu= 806,  sigma= 42),
   B1= Record(mu= 1163, sigma= 81),
   B2= Record(mu= 816,  sigma= 44)
]):

#Account of wins\losses (in each pair, the first member defeats the second):
Games:= [[B1,A1], [A1,B2], [B1,A2], [A2,B2]]:

infolevel[RC]:= 1:

Update(Standings, Games);

RC: Winner = 1166 +- 78; Loser = 1004 +- 45.
RC: Winner = 1007 +- 42; Loser = 816 +- 44.
RC: Winner = 1168 +- 74; Loser = 806 +- 42.
RC: Winner = 808 +- 38; Loser = 757 +- 8.


#New standings:
<op(eval(Standings))>;

Vector[column]([[A1 = Record(mu = 1006.79431881513, sigma = 41.8765912890772)], [B1 = Record(mu = 1168.00000000000, sigma = 74.0000000000000)], [B2 = Record(mu = 756.590048730233, sigma = 8.3540292381394)], [A2 = Record(mu = 808.499824704434, sigma = 38.4998948226602)]])

``


 

Download UpdateStandings.mw

If x is between 0 and 1, then r(2x - 1) is between -r and r, and the transformation preserves uniformity. So the short Answer to your Question is that a correct procedure is

MyRand:= (M::posint, r::positive)-> ['r*(2*rand()/1e12 - 1)' $ M]:

But there's an easier way to use rand: When rand is passed a floating-point range, it returns a procedure that returns a random float in that range:

MyRandGenGen:= (r::positive)-> rand(-evalf(r)..evalf(r)):
MyRandGen:= MyRandGenGen(2):
#Test:
'MyRandGen()' $ 9;

1.48951387270106, -1.53779637227213, -.78650701082674, -1.93849247788427, -.50767257251262, 1.44464713288912, .80493082902846, 1.62849297809254, 1.18768745874873

If you want to generate long lists of floats, I think that the following is more efficient (but I haven't tested the efficiency):

MyRandGen:= (M::posint, r::positive)-> 
   RandomTools:-Generate(list(float(range= -r..r, method= uniform), M))
:
f:= MyRandGen(600, 2):

 

There are four dimensions to display: u, r, theta, and z. You've decided to handle u with a color range. A static (non-animated) plot can't show all the points in a three-dimensional space. We can get around this by showing an animation of a sequence of concentric cylindrical shells. So theta and z will be spatial dimensions, and r will be a time dimension.

restart:

#Example function
u:= (r, theta, z)-> r + theta + z:

#Example ranges:
Ranges:= Record(r= 0..2, theta= -Pi..Pi, z= -2..2, hue= 0..0.85):
#Use the hue range to tweak the color range. The colors are on the 
#standard visual spectrum: red = 0, violet= 1.  

#We need this module to collect the min and max of u so that the color
#scale is consistent through the whole animation.
U:= module()
export 
   umin:= infinity, umax:= -infinity,
   ModuleApply:= proc(r, theta, z)
   local ret:= u(r, theta, z);
      if not ret::realcons then return 'procname'(args) end if;
      if ret < umin then umin:= ret end if;
      if ret > umax then umax:= ret end if;
      ret
   end proc,
   Init:= proc() (umin,umax):= (1,-1)*~infinity end proc
;
end module:
 
#This first plot is simply to collect the min and max of u. 
#There's no need to see the plot.
U:-Init():
plots:-animate(plot3d, [U(r, theta, z), theta= Ranges:-theta, z= Ranges:-z], r= Ranges:-r):

plots:-animate(
   plot3d,
   [
      [r, theta, z], theta= Ranges:-theta, z= Ranges:-z, 
      color= op(2, Ranges:-hue) + `-`(op(Ranges:-hue))*(u(r,theta,z) - U:-umin)/(U:-umax - U:-umin),
      coords= cylindrical,
      #optional arguments:
      style= surface, axes= frame, labels= [``,``,'z'], grid= [36,40], lightmodel= light3,
      orientation= [45,60], thickness= 0, transparency= 0     
   ],
   r= Ranges:-r,
   #optional arguments:
   frames= 25
);

The images will be sharper and you'll be able to slow down the frame rate when you do this in a Maple worksheet. My color gradation is over the standard visual spectrum from red to blue. If you want to use strictly blends of pure red and pure blue, that can be done also. If your function u is strictly numeric (such as would be returned by pdsolve(..., numeric)), that will require a small adjustment to the above code.

If you use exact arithmetic (that means no decimal points), you'll see that the function ratio doesn't depend on its third parameter, l (ell). For example,

ratio(1, 2, L, 3, 4);

So the problem is not with the plot command. There's some mathematical reason why l cancels in your expression.

(For the sake of readability, it's probably not good to use lowercase l as a variable.)

Let's consider this block of your code:

if j-1>1 then
   if N <> Configz1[w](o, j+1) then DeltaBond:= DeltaBond+1
      if N = Configz1[w](o, j+1) then DeltaBond:= DeltaBond-1
else DeltaBond:= DeltaBond
end if:
end if:
end if:

Now let's look at it again, execpt that I'll use a logical indentation structure:

if j-1>1 then
    if N <> Configz1[w](o, j+1) then 
       DeltaBond:= DeltaBond+1
       if N = Configz1[w](o, j+1) then 
         DeltaBond:= DeltaBond-1
      else
         DeltaBond:= DeltaBond
      end if:
   end if:
end if:

Now do you see the problem? The third line needs a semicolon or colon at the end.

For BVPs, the equivalent of maxfun is maxmesh.

When or and seq or map are used togther, they can be replaced by a single command. In this case that's

ormap(`=`, R[..-2], R[i]);

This is more efficient than Kitonum's command because it aborts the processing as soon as the first true result is found.

There's also an andmap.

 

The command is

eliminate(eqns, {X,Y});

The solution may be messier than you were hoping for, with a few nasty RootOfs.

To run a .mpl file in your current Maple session, the command is simply

read "filename":

Your attempt using cmaple.exe would not run in the same Maple session (or kernel), so it would be of no use to you. However, it can occasionally be useful to run an external Maple session like you were trying. This is done with the system or ssystem commands.

A color function can be arbitrarily complicated on the inside, but its signature must be relatively simple: It must take two real arguments and return a single real result. It cannot return a list. If you want to use a 3D colorspace like HSV or RGB, then each coordinate color needs a separate function, like this:

restart:
(X,Y,Z):= (((u,v)-> sech(u)*cos(v)), ((u,v)-> sech(u)*sin(v)), ((u,v)-> u - tanh(u))):
F:= z-> z:
Ans:= proc(u,v) option remember; evalf(Re(F(v+I*exp(u)))) end proc:
`2*Pi`:= evalf(2*Pi):
ColorFunc||(H,S,V):= (
   ((u,v)-> `if`(Ans(u,v) > `2*Pi`, 0, Ans(u,v)/`2*Pi`)),
   ((u,v)-> `if`(Ans(u,v) > `2*Pi`, 0, 1)) $ 2
):
plot3d(
   [X,Y,Z], 0..3, 0..`2*Pi`, grid= [2^5 $ 2], 
   color= [ColorFunc||(H,S,V), colortype= HSV],
   lightmodel= none
);

In your specification of equ6, you've used F[1](0). This is logical, and Maple should be able to figure it out because you've specified the value of F [1](0) in Bcs21. Unfortunately, dsolve wasn't designed to take this into account. You can replace F [1](0) with a; or, a more-sophisticated treatment is 

S21:= dsolve({eval(equ6, {Bcs21}), Bcs21}, numeric);

There are many reasons in Maple why it's better to set the value of a parameter with eval rather than := (mostly, it improves the clarity of the exposition). You've stumbled upon one of them. This is doubly true when the parameter is inside an rtable (a Vector, Matrix, Array, or anything constructed with <...>). If you insist on using :=, there is a command to force the assignments to take effect inside of the rtables: rtable_eval. Thus,

z:= A*<x,y>:
A:= 1:
rtable_eval(z, inplace):
plots:-fieldplot(z, x= -1..1, y= -1..1);

Note carefully however that the rtable_eval(..., inplace) changes z from an rtable with a parameter to a purely numeric rtable. To retain the original z, don't use inplace:

restart:
z:= A*<x,y>:
A:= 1:
plots:-fieldplot(rtable_eval(z), x= -1..1, y= -1..1);

I think that it's unfortunate that Maple's rtables were designed to be used for two conflicting purposes: as containers for efficient computation, and as realizations of the mathematical concepts of vectors and matrices. The command rtable_eval exists as a bridge between those purposes. In the long run, I think that it's better to use lists to represent mathematical vectors, and listlists to represent mathematical matrices.

You can view a 3D plot as if it were a 2D plot by including the option orientation= [270,0].

Since n is a bound variable to each sum, the n in each sum is logically a different variable, although it's the same "name" (or address) as far as Maple is concerned. So, your question doesn't quite make sense to me. If the result could be expressed as a single summation, that'd be a different matter. Then you could say

eval(subs((n= 0..infinity)= (n= 2..2), %));

and get a meaningful answer. You can also give this command in the case that you presented---the syntax allows it---but as far as I'm concerned, the result is nonsense.

A meaningful question that you could ask is What is the xi^2 term in the resulting expression? This question can be answered by

coeff(eval(%, infinity= 2), xi, 2)*xi^2;

You need two sets of unevaluation quotes around each name in KeepThese:

one:= 1: two:= 2: three:= 3:
KeepThese:= {''one'',''two''}:
unassign~({anames('user')} minus KeepThese);

 

First 203 204 205 206 207 208 209 Last Page 205 of 395