acer

32333 Reputation

29 Badges

19 years, 320 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Suppose that you have called dsolve/numeric without the option `listprocedure` and passed the result `sol` to plots:-odeplot, and obtained a warning about a singularity. Even though the warning itself cannot be trapped, you can still invoke `sol` at the farthest (rightmost, say, or "last") t=time point which you hoped to plot and get a trappable error.

For example, suppose that you wanted to plot from 0..1000 and have computed a result `sol` from dsolve,numeric which has a first singularity to the right of 0.0 occuring at approximately 701.02. After plotting, you can invoke,

p:=proc(dsn,val)
   try
      dsn(val); 
      "no singularity found";
   catch "cannot evaluate the solution further":
      eval(t,dsn('last'));
   end try;
 end proc:

> p(sol,500);
                            "no singularity found"

> p(sol,1000);
                               701.022570685642

Hence you can construct a programmatic mechanism for testing whether a singularity was hit, and what the value of the independent varaible `t` was. The technique is easy to adjust if you have used the output=listprocedure option.

What procedure `p` does is trap and manipulate a situation like this,

sol(1000):

Error, (in sol) cannot evaluate the solution further right of 701.02257,
probably a singularity

acer

Suppose that the Buttons have their Names as Button1, Button2...,Button6 and that the list of six values is `L`.

for i from 1 to 6 do
  DocumentTools:-SetProperty(cat(Button,i),'caption',L[i],'refresh'=true);
end do:

If you are planning on doing that repeatedly, for many different values in `L`, then you might consider assigning the button names to its own list and then accessing them without having to re-do the `cat` calls each time. Eg,

# do this just once
ButtonNameList := [seq(cat(Button,i), i=1..6)]:

# ...and then, for each different list of values L,
for i from 1 to 6 do
  DocumentTools:-SetProperty(ButtonNameList[i],'caption',L[i],'refresh'=true);
end do:

acer

Try it with,

   sprintf("C:\\Users\\Sorted_Eigenvectors_%d.txt",i)

as that first argument to ImportMatrix.

acer

With a little extra work, yes. See here for a couple of ways (or varying efficiency vs ease).

acer

Maple 17 does this.

BesselI(0,I*x);

                         BesselJ(0, x)

It's also done in Maple 12 and Maple 14. I didn't try others. Which version do you have?

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

First 249 250 251 252 253 254 255 Last Page 251 of 336