acer

32505 Reputation

29 Badges

20 years, 11 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Your code uses `int`, and `is` which are not thread-safe.

btw, it's very inefficient to have that call to `unapply` be inside the for-do-loop.

acer

Maybe it is related to 0 as the lower index value on the Sum.

> T:=1/(6*0+1)!+Sum(1/(6*k+1)!, k=1..infinity):

> evalf(T);

                                  1.000198413

> simplify(combine(radnormal(value(T))));

    /                   1/2                  1/2
    | 1/2              3                    3
1/6 |3    exp(3/2) sin(----) + exp(3/2) cos(----) + exp(2)
    \                   2                    2

                          1/2                  1/2     \
        1/2              3                    3        |
     + 3    exp(1/2) sin(----) - exp(1/2) cos(----) - 1| exp(-1)
                          2                    2       /

> evalf(%);

                                  1.000198414

acer

I'm not sure which dictionary you mean.

One can easily adjust this code to look for uppercase "FL" and "S" only, or to allow both uppercase and lowercase.

restart:

with(StringTools): with(PatternDictionary):
bid:= Create(`ospd3`): # Create(`builtin):
words:= [seq](Get(bid,i),i=1..Size(bid)-1):

select(proc(s) s[1..2]="fl" and s[-1]="s"; end proc, words);

acer

Depending on the nature of your code it might be possible to parallelize it with the Grid or Threads packages.

acer

Embedded components are great for this kind of thing. You can make it simple, or very fancy.

Here's something simple.

sliderlabel.mw

acer

restart:
with(Statistics):

nu:=0.34:
dist:=RandomVariable(StudentT(nu)):
St:=PDF(dist,t):

X:=2.1;

                                  X := 2.1
p:=evalf(Int(St,t=-infinity..X));

                              p := 0.7364606401

CDF(dist,X);

                                0.7364606401

Quantile(dist,p);

                              2.09999999964824

See the Quantile help-page (which is also mentioned on the CDF help-page). In some other products, such as Matlab, the inverse CDF function is called something like `icdf` (and searching this site for that name gets some related hits of similar queries).

acer

When trying to plot your procedure `q`, make sure that you call it like,

plot( q, 1..2);

or

plot( 'q'(y), y=1..2);

and not like,

plot( q(y), y=1..2);

the latter of which is open to premature evaluation if (as in your case) `q` does not return unevaluated for nonnumeric arguments. To illustrate that problem, try calling q(y) for unassigned symbolic `y`, even outside of any plotting call.

acer

with(Statistics):
dummy1 := sqrt(1/(1+y*e)):
R := RandomVariable(Normal(y*e*z/(1+y*e), dummy1)):
y := 1: b := .3: a := 1.25:  z := 1: e := .2:
with(Optimization):

sol := Maximize(-(int(exp(-a*b*j*r)*PDF(R, r),
                r = 0 .. infinity))-(int(PDF(R, r), r = -infinity .. 0)));

            sol :=  [-0.427566070299999990, [j = 28.7853892758708]]

t := eval(j, sol[2]);

                            t := 28.7853892758708

acer

Here is... something...  See the recursive Sum returned as output by executing the call RR(n) below.

I'm not sure what you want to accomplish, while keeping a(..) unspecified.

restart:

M := proc(n)
  if not type(n,integer) then return 'procname'(args); end if;
  if n=0 then return Matrix([[1]]) end if;
  Matrix(n, n, proc(i,j)
                 if j >= i and (j-i)::even then
                   F(i,j);
                 elif i-j = 1 then -1;
                 else 0; end if;
               end proc):
end proc:

#M(6);

MM := proc(n)
  if not type(n,integer) then return 'procname'(args); end if;
  if n=0 then return Matrix([[1]]) end if;
  Matrix(n, n, proc(i,j)
                 if j >= i and (j-i)::even then
                   (j-i+1)*(j-1)!/(i-1)!*a(j-i+1)*x;
                 elif i-j = 1 then -1;
                 else 0; end if;
               end proc):
end proc:

#MM(6);

DetM:= proc(n)
  if not type(n,integer) then return 'procname'(args); end if;
  LinearAlgebra:-Determinant(M(n));
end proc:

F:=proc(i,j) 
  if not ( type(i,integer) and type(j,integer) ) then
    return 'procname'(args); end if;
  if j >= i and (j-i)::even then
    (j-i+1)*(j-1)!/(i-1)!*a(j-i+1)*x;
  elif i-j = 1 then -1;
  else 0; end if;
end proc:

R:=proc(n)
   piecewise(n::even, Sum(F(2*j,n)*DetM(2*j-1),j=1..n/2),
             n::odd, Sum(F(2*j-1,n)*DetM(2*j-2),j=1..n/2+1) );
end proc:

#R(n);

RR:=proc(n)
   piecewise(n::even,
             Sum((n-(2*j)+1)*(n-1)!/((2*j)-1)!*a(n-(2*j)+1)*x*DetM(2*j-1),
                  j=1..n/2),
             n::odd,
             Sum((n-(2*j-1)+1)*(n-1)!/((2*j-1)-1)!*a(n-(2*j-1)+1)*x*DetM(2*j-2),
                  j=1..n/2+1) );
end proc:

RR(n);

         /         1/2 n 
         |         ----- 
         |          \    
         |           )   
piecewise|n::even,  /    
         |         ----- 
         \         j = 1 

  (n - 2 j + 1) factorial(n - 1) a(n - 2 j + 1) x DetM(2 j - 1)  
  -------------------------------------------------------------, 
                       factorial(2 j - 1)                        

          1/2 n + 1
           -----   
            \      
             )     
  n::odd,   /      
           -----   
            j = 1  

                                                               \
                                                               |
                                                               |
  (n - 2 j + 2) factorial(n - 1) a(n - 2 j + 2) x DetM(2 j - 2)|
  -------------------------------------------------------------|
                       factorial(2 j - 2)                      |
                                                               /

# some checks
#with(LinearAlgebra):
#Determinant(M(17))-expand(value(RR(17))), Determinant(M(18))-expand(value(RR(18)));
#Determinant(MM(17))-expand(value(RR(17))), Determinant(MM(18))-expand(value(RR(18)));
#Determinant(M(17))-expand(value(R(17))), Determinant(M(18))-expand(value(R(18)));
#Determinant(MM(17))-expand(value(R(17))), Determinant(MM(18))-expand(value(R(18)));
#Determinant(MM(17))-DetM(17), Determinant(MM(18))-DetM(18);

RecurDetM:=proc(n) option remember, system;
  if not type(n,posint) then 'procname'(args); end if;
  if n<1 then return 1; end if;
  if type(n,even) then
     expand(
       add((n-(2*j)+1)*(n-1)!/((2*j)-1)!*a(n-(2*j)+1)*x*procname(2*j-1),
                  j=1..n/2)
            );
  else # type(n,odd)
     expand(
       add((n-(2*j-1)+1)*(n-1)!/((2*j-1)-1)!*a(n-(2*j-1)+1)*x*procname(2*j-2),
                  j=1..ceil(n/2))
            );
  end if;
end proc:

RecurDetM( 27 ) - LinearAlgebra:-Determinant(MM(27));
                               0

RecurDetM( 32 ) - LinearAlgebra:-Determinant(MM(32));
                               0

acer

With the storage=sparse option to the Vector/Matrix/Array constructors you can tell Maple to store only the nonzero entries' values.

> restart:
> V:=Vector(2^62):
Error, (in Vector) not enough memory to allocate rtable

> restart:
> V:=Vector(2^62,storage=sparse):
> for i from 1 to 2^20+1 do V[i]:=i; end do:

> kernelopts(bytesalloc);

                            71704576

By using a hardware datatype you can cut down the memory allocation further.

> restart:
> V:=Vector(2^62,storage=sparse,datatype=float[8]):
> for i from 1 to 2^20+1 do V[i]:=i; end do:
> kernelopts(bytesalloc);

                            34492416

acer

This looks like a question asked here a few days ago.

ee:=2/3*37^(1/2)*sin(1/6*Pi+1/3*arccos(55/1369*37^(1/2)))+2/3:
radnormal(expand(convert(ee,expln)));

                                         4

acer

Do you think that your original attempt did not work? You did not reassign to `u` in that last line. But otherwise, why isn't the rhs of the last line's output not what you want?

You may wish to achieve that without having to explicitly enter all the substitutions.

evalc(u);

subsindets(u,specfunc(anything,conjugate),z->op(z));

acer

It looks like some strange bug, that `subs` or 2-argument `eval` are not mapping automatically across M.

It seems to depend on the line,

M:=M(2..,..);

right after the call to `myM`.

One of the effects of the programmer (round bracket) indexing here is that the chopped Array has its indices start from 1. So the first index starts from 1 rather than from 2.

The following gets an Array similarly indexed from 1..4,1..3, using regular square bracket indexing following by redimensioning. And it does not seem to exhibit the bug.

M:=M[2..,..];
rtable_redim(M,1..4,1..3);

But this is also a little strange, maybe, since the entries of the result from the final subs(ans,M) now print as if there were fully evaluated. And, as discussed a few weeks ago, this is just an artefact of `rtable/print`, since lprinting reveals that the final entries still contain unevaluated `exp` calls as expected.

Of course, Alejandro's suggestion to map  `subs` also gets it done. Note the expected display of the unevaluated `exp` calls in the final result of the `map2` call.

(A wild guess is that the flag normally only toggled by rtable_eval(...,inplace) might have been set on the offending Array M, perhaps somehow interfering with subsequent evaluation of it.)

acer

Maple does a better job with simplifying these as expressions involving radicals, and one way to get such here is via intermediate conversion to `expln` and expanding.

restart;
poly:=2*x^3-4*x^2-22*x+24:

{solve(poly,x)};

                           {-3, 1, 4}

r1:=2/3*37^(1/2)*sin(1/6*Pi+1/3*arccos(55/1369*37^(1/2)))+2/3:
r2:=-1/3*37^(1/2)*(sin(1/6*Pi+1/3*arccos(55/1369
    *37^(1/2)))+3^(1/2)*sin(1/3*Pi-1/3*arccos(55/1369*37^(1/2))))+2/3:
r3:=-1/3*37^(1/2)*(sin(1/6*Pi+1/3*arccos(55/1369*37^(1/2)))-3^(1/2)
    *sin(1/3*Pi-1/3*arccos(55/1369*37^(1/2))))+2/3:

map( p-> radnormal(expand(convert(p,expln))), {r1,r2,r3} );

                           {-3, 1, 4}

acer

Would it suffice for your purposes to have a wrapping procedure which itself calls plot?

Eg,

sine:=(Amp,freq,phase,t)->Amp*sin(2*Pi*freq*t+phase):
makeit:=freq->plot(sine(1,freq,0,t),t=0..1,title=cat(freq," sine wave cycles")):
makeit(2);

I don't know what exactly you want to do with it, but one possibility in Maple 17 is,

Explore(makeit(freq),parameters=[freq=1..5]);

You of course change the (dummy) parameter name in that last example to something else. Or you could make a wrapping procedure which also accepted aditional arguments for, say, amplitude and phase.

ps. apologies to Carl, who answered similarly during the time I was writing this...

acer

First 251 252 253 254 255 256 257 Last Page 253 of 337