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

Perhaps you're interested in the expected number of rolls to obtain at least those.

Let u(m1, m2, ..., m6) is the expected number of rolls to obtain at least m1 1's, m2 2's, ..., m6 6's.
By a "first-step" analysis, I get approximately 43.46441578, if I haven't made a mistake.

> E:= convert(LinearAlgebra[IdentityMatrix](6),listlist):
  u:= proc(n1,n2,n3,n4,n5,n6) 
    option remember;
    # expected number of rolls starting at (n1,...,n6) 
    # to get to at least (1,2,3,4,5,6)
    local B,R,nR,i;
    B:= [seq(evalb(args[i]<i), i=1..6)];
    R:= select(i -> B[i], [$1..6]);
    nR:= nops(R);
    6/nR+1/nR*add(u(op([n1,n2,n3,n4,n5,n6]+E[i])),i=R); 
  end proc:
  u(1,2,3,4,5,6):= 0:
  u(0,0,0,0,0,0);

 9461257251462568030549639/217678233600000000000000

RootOf does not imply anything about the number of solutions. 

In this case, there will be infinitely many solutions whenever there is one, because eq is periodic in sr1 with period 2*Pi.  On the other hand, arctanh (which in Maple is the principal branch of arctanh) is one-to-one, so that doesn't introduce any more non-uniqueness.

If you want to see the periodicity, you should use the AllSolutions option in solve.

> solve(eq - eval(eq,sr1=0)-s0,sr1,AllSolutions);

2.*arctan(RootOf(3630444634*arctanh(5616816483/10000000000*_Z+8023282641/ 10000000000)-4012053071+50000000000*s0))+6.283185307*_Z1

It works fine for me using Maple Notation input in Standard GUI.  I just highlight the code I want to copy, press Ctrl-C, and then Ctrl-V to paste in here.  Click in the pasted code, and change Format to Formatted.

Your equation doesn't work because it has non-matching parentheses.  But you could try this central difference operator.  It should transform every derivative (expressed using diff) in an expression into a central difference.

> CD := proc(Q,h)
     local f, x;
     if type(Q, atomic) then Q
     elif type(Q, {`+`,`^`,`*`, `=`, list, set, rtable}) then map(procname,Q,h)
     elif type(Q, specfunc(anything,diff)) then
       f:= procname(op(1,Q),h);
       x:= op(2,Q);
       normal((eval(f,x=x+h) - eval(f,x=x-h))/(2*h))
     elif type(Q, function) then map(procname,Q,h)
     else error "I don't know what to do with %1",Q
     end if
  end proc;

For example:

> CD(diff(f(x,y), x), h);

1/2*(f(x+h,y)-f(x-h,y))/h

> CD(diff(u(x,t), t) = K*diff(u(x,t), x$2) + v(t), h);

1/2*(u(x,t+h)-u(x,t-h))/h = 1/4*K*(u(x+2*h,t)-2*u(x,t)+u(x-2*h,t))/h^2+v(t)

1)  Do you mean want a Matrix of 3 entries, of which the first is integer[2], the second and third float[8]? 

You could have a Matrix with datatype {float[8], integer[2]}, i.e. each entry can be either of type float[8] or integer[2], but I don't know of any way to have a Matrix where different entries are restricted to have different datatypes.  You could have your procedure check that specific entries are of specific types, e.g. using type or ::.

2) Perhaps more reliable is round(q): that should always give an integer, while convert(q, rational) might return a fraction.

3) if M is your Matrix,

> map(round, M);

 

If you don't need to store all the eigenvalues, only an eigenvalue of least absolute value for each Matrix, you can do something like this.

> smallev:= proc(M)
     uses LinearAlgebra;
     local E, absE, minv, mini;
     E:= Eigenvalues(M);
     absE:= map(abs, E);
     minv:= min(absE);
     member(minv, convert(absE, list), mini);
     E[mini];
   end proc;
 
   SmallestEvs:= map(smallev, muset);

   

You could try using match, something like this:

> pattern := c * f^a * ln(f);
  if match(A = pattern, f, 'S') then
    thec := eval(c, S);  
    thepower := eval(a, S); 
  else
    error "%1 doesn't match the pattern", A
  end if;

Note that, e.g., ln(f) will match the pattern with c = 1 and a = 0.

I don't think you're quoting your actual code, because set is a reserved word: you can't assign a value to it.

The problem ocurs when you assign

> set[k] := A;

Your code didn't define A, so by default A is a table, but the same problem would occur if A was an Array or  Matrix. What is stored in set[k] is not a copy of A, but A itself.  So then in the next iteration when you change A, that affects set[k] as well.  What you should assign to set[k] is a copy of A, not the original.  Thus try it with

> set[k] := copy(A);

Your system is not a PDE system in the sense that pdsolve understands it.  In a  PDE system, all the unknowns would be functions of the same independent variables, and the equations would relate these functions and their partial derivatives at the same values of the independent variables.  For example, you could have equations involving RR(rh, tau) and csh(rh, tau) and their partial derivatives.  If you want RR not to depend on rh, you could include the equation diff(RR(rh,tau), rh) = 0.  However, your equations also involve csh(RR(tau), tau).  I guess that makes them functional partial differential equations.  But whatever you call them, pdsolve can't handle them.

Scott's method will work, but do you really need to use odeplot?  dsolve(..., numeric) is the normal way to get the numerical solution of a differential equation or system, and with the output=<Array> option you get a Matrix containing the numerical values at specified points.  In Scott's example, suppose you want the solution at all multiples of .001 from x=-5 to 2.

> X:= Array([seq(x, x = -5 .. 2, 0.001)]);
  S:= dsolve({y(0) = 1, (D(y))(x) = y(x)}, type = numeric, output=X);
  M:= S[2,1];
  ExportMatrix("C:\\Test\\Mydata.txt", M, target = delimited, delimiter="\t");

 

If L is your list,

> convert(L, `+`);
 

Or if you didn't mean literally that you generated a list, but just that you produced solutions one at a time in the loop, you could add them as they are generated, something like this:

> Total := 0:
  for ... while ... do
      # generate solution s 
      Total := Total + s;
  end do:

 

Are you the same person as Jabz?  You seem to have the same Miller-Rabin procedure (www.mapleprimes.com/forum/primalitytesting).

Besides the problem Scott pointed out, note that your procedure calculates a number w for each i from 0 to q but doesn't do anything with it.  You're only testing w after this loop completes (so the value of w that will be tested is the one for i = q).

You could do it more easily without any do loops, but I suppose this is homework.

I'm also guessing (not that it makes much difference here) that you mean Array rather than array.

Hint: First define your Array.  Then have each iteration of your loop (or the inner loop in the second question) assign a value to one element of the Array.

 

This "feature", that only the value on the right side of an assignment statement appears in output, occurs, as far as I can tell, in Document mode with Maple Standard typesetting level.  If you change the typesetting level to Extended, it should not occur.  I don't think it has anything to do with numeric formatting.

If you're computing your values in a loop, the simplest way is to keep track of the best so far.  Something like

>  bestv:= infinity:
   for n from 1 to N do
     # obtain combination a 
     v := f(a);
     if v < bestv then
        bestv:= v;
        besta:= a;
     end if
   end do:

The minimum value is now bestv, corresponding to combination besta.

On the other hand, if you're producing a list L of combinations and want the one where the value of f is minimal, you might do something like this:

> V := map(f, L):
  bestv := min(V);
  member(bestv, V, 'p'):
  besta := L[p];

First 55 56 57 58 59 60 61 Last Page 57 of 138