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

Someone can likely improve on the thresholding.

restart:
randomize():

R:=proc() local g, P;
      g:=6*(rand(100)/100.0-0.5):
      P:=add(mul(sqrt((x-g())^2+(y-g())^2),i=1..j)/
          mul(sqrt((x-g())^2+(y-g())^2),i=1..j),j=1..5);
      plots:-display([
        z->plots:-densityplot(z,x=-5..5,y=-5..5,
                    colorstyle=HUE,grid=[30,30],style=patchnogrid),
        z->plots:-contourplot(max(1,min(60,z)),x=-5..5,y=-5..5,
                    contours=40,grid=[100,100],thickness=0)](P),
                axes=none,view=[-5..5,-5..5]);
   end proc:

R();

R();

acer

The Matrix/Vector/Array option datatype=complex(float) may be what you are after. That will produce something whose datatype is either complex[8] or complex(sfloat), according to the values of UseHardwareFloats and Digits.

If you want to force the complex hardware (double precision) restriction then you could pass the option datatype=complex[8].

If you want to force the complex "software float" restriction then you could pass the option datatype=complex(sfloat).

acer

First note that you are trying to add a subexpression with unit m^3 to one with with m^2. I don't see how it can make sense to make that unitless without knowing where the "hidden unit" is in the expression, that allows it be regarded as nondimensional.

If the units are compatible, you can use combine,units and then convert,unit_free.

V[dis]:=(3/100000)*Unit('m')^3
        +0.1e-2*Pi*Unit('m')^3*(.112-0.28e-1*cos(theta)
                 -sqrt(0.7e-2-0.1e-2*sin(theta)^2)):

convert(combine(V[dis],units),'unit_free');

                            /                        
            3               |                        
          ------ + 0.001 Pi \0.112 - 0.028 cos(theta)
          100000                                     

                                          (1/2)\
               /                        2\     |
             - \0.007 - 0.001 sin(theta) /     /

acer

1) Try `eval` instead of `showstat`. The former returns something, while the latter merely displays something (and returns NULL).

2) See senior Maple Kernel developer Darin's comment here, perhaps, where he seems to state pretty clearly that what you've asked about cannot work in then current Maple. You cited that very same thread in the earlier post from which you branched off this Question. Do you expect that it might have all changed, for Maple 17?

acer

Yes it is possible, but there are restrictions, and it is tricky. You cannot specify any arbitrary position for the insertion (think of how plots follow plotting commands, as output, as an analogy).

But perhaps that's not what you really need. (Details would help on your goal, please.) Would it suffice to use and re-use a single TextArea that you had inserted earlier at a single location of choice, which you can repeatedly programmatically hide/reveal and clear/populate?

acer

It appears that the global bindings are present in what gets constructed by the 2D Math input inserted by the Matrix palette. This may be a hint that the problem is in parsing, or something related.

In other words, the global name is getting used, even when the name is supposed to have been rebound to the module export. That's a bug, but not a bug in your module package.

The following is just an example of how it might go wrong. It may well be that some other intermediate form is used, or some other mechanism. I'm just trying to illustrate that the "localness" can get lost.

restart:

m:=module() option package; export f;
     f:=proc(x) x^2; end proc:
   end module:

with(m):

f(3);

                               9

str := sprintf("%m",'f(3)'):

sscanf(str,"%m")[];

                              f(3)

eval(%); # this contains the global name :-f and not m:-f

                              f(3)

% - :-f(3);

                               0

You might want to consider just assigning your procedures to the global names :-Cos and :-Sin, and leaving them out of a module for now.

acer

For some examples you may wish to ensure that the objective depends upon the names, and remove constant names.

Below, `t` is a dummy variable, and likely not wanted.

> restart:

> expr := Pi*x*y+Int(sin(cos(x+t)),t=0..1);

                                       1
                                      /
                                     |
                   expr := Pi x y +  |   sin(cos(x + t)) dt
                                     |
                                    /
                                      0

> indets(expr,name);

                                 {Pi, t, x, y}

> depnames := indets(expr,And(And(name,Non(constant)),          
>                             'satisfies'(u->depends(expr,u))));

                              depnames := {x, y}

> seq(u=-1..1, u in depnames);

                           x = -1 .. 1, y = -1 .. 1

acer

restart:
with(LinearAlgebra):

A:=Matrix([[-2,-1],[9/5,4/5]]);

                                     [-2  -1]
                                     [      ]
                                A := [ 9   4]
                                     [ -   -]
                                     [ 5   5]

Apownodd:=simplify(MatrixPower(A,2*k+1)) assuming k::posint:

map(limit,Apownodd,k=infinity);

                                  [-9  -5]
                                  [--  --]
                                  [4   4 ]
                                  [      ]
                                  [ 9   5]
                                  [ -   -]
                                  [ 4   4]

map(identify,evalf(A^61));

                                  [-9  -5]
                                  [--  --]
                                  [4   4 ]
                                  [      ]
                                  [ 9   5]
                                  [ -   -]
                                  [ 4   4]

Apowneven:=simplify(MatrixPower(A,2*k)) assuming k::posint:

map(limit,Apowneven,k=infinity);

                                  [ 9   5]
                                  [ -   -]
                                  [ 4   4]
                                  [      ]
                                  [-9  -5]
                                  [--  --]
                                  [4   4 ]

map(identify,evalf(A^60));

                                  [ 9   5]
                                  [ -   -]
                                  [ 4   4]
                                  [      ]
                                  [-9  -5]
                                  [--  --]
                                  [4   4 ]

You may also be able to get there, with insight, by diagonalizing.

acer

Look at that exp^(-s)

acer

If rsolve succeeds then you can try and use `limit`.

eqs := { a(n)*(a(n-1)+3) = a(n-1)+2, a(1) = 2 }:

R:=rsolve(eqs, a(n) );

   /  /            n                      n       
 - |  |/     (1/2)\   (1/2)   /     (1/2)\   (1/2)
   \2 \\2 - 3     /  3      - \2 + 3     /  3     

                    n                 n\\//            n       
        /     (1/2)\      /     (1/2)\ || |/     (1/2)\   (1/2)
    + 2 \2 - 3     /  + 2 \2 + 3     / // \\2 - 3     /  3     

                  n                      n               n\
      /     (1/2)\   (1/2)   /     (1/2)\    /     (1/2)\ |
    - \2 + 3     /  3      + \2 - 3     /  + \2 + 3     / /

limit(R,n=infinity);

                                 (1/2)
                          4 - 2 3     
                          ------------
                            (1/2)     
                           3      - 1 

expand(rationalize(%));

                            (1/2)    
                           3      - 1

evalf(%);

                          0.7320508060

If rsolve fails (and if there is no easy fix-up to a workable polynomial form) then you might still be able to use `evalf/Limit` on the result of passing the `makeproc` option to `rsolve`. If that in turn succeeds then you might even get lucky with `identify`.

eqs := { a(n) = (a(n-1)+2)/(a(n-1)+3), a(1) = 2 }:

h:=rsolve(eqs, a, makeproc ):

evalf(Limit('h'(x),x=infinity));

                          0.7320508076

identify(%);

                            (1/2)    
                           3      - 1

acer

Did you mean that you tried it on the 2D Math output from evaluating expand((x+y)^19);

I tried that with exponent 18, and then 19. Ie. I selected the whole output (without right-clicking) and waited to see if the Smart Popup menu appeared. It did, for exponent 18, but not for 19.

Then I issued stopat(SubexpressionMenu); and tried again. The debugger popped up for 18, but not for 19. This indication that Library code is not getting called on the larger example seems like a hint that there may be some kind of size cutoff in the GUI. Your problematic example doesn't look overly large to me.

In trying to discover whether there was a size cutoff I looked at the length of dotm (sprintf to "%m" format) of a call to Typesetting:-Typeset of the output expression, and tried a few other expressions, but that didn't seem to be the key metric. Maybe something else? This might be the wrong tack.

acer

Below I use i, i+2, and i^2 for your "point" P(1,2,3), so that it depends on the value of `i`.

Another possibility for referring to such a "point" might be to use a Vector, V, in which case its entries might be referenced instead as V[1], V[2], V[3].

Using expressions,

restart:
F:=6*x^2 + 3*x*y^2 - 1.5*z^3;
H:=VectorCalculus:-Hessian(F,[x,y,z]);
for i from 1 to 3 do
   eval(F,[x=i,y=i+2,z=i^2]);
   eval(H,[x=i,y=i+2,z=i^2]);
end do;

Using operators (procedures),

restart:
F:=(x,y,z)->6*x^2 + 3*x*y^2 - 1.5*z^3:
H:=unapply(VectorCalculus:-Hessian(F(x,y,z),[x,y,z]),[x,y,z]):
for i from 1 to 3 do
   F(i,i+2,i^2);
   H(i,i+2,i^2);
end do;

acer

restart:

T:=sqrt(2/3)*Matrix([[cos(omega*t),cos(omega*t-(2/3)*Pi),cos(omega*t+(2/3)*Pi)],
                     [-sin(omega*t),-sin(omega*t-(2/3)*Pi),-sin(omega*t+(2/3)*Pi)],
                     [1/sqrt(2),1/sqrt(2),1/sqrt(2)]]):

q:=T . map(diff,T^%T,t):

map(expand,map(convert,q,expln));

                             [  0    -omega  0]
                             [                ]
                             [omega    0     0]
                             [                ]
                             [  0      0     0]

acer

The problem is numeric (floating-point) evaluation error. Under the fast (hardware float) `evalhf` interpreter your `L` evaluates to Float(undefined) for values of `k` closer to 100.

Even under regular (software float) `evalf` there are numeric issues when done at lower working precision (ie. Digits).

There are several ways around this. The attached worksheet shows three related and relatively simple ways of getting around it by avoiding evalhf mode computation.

Download error1.mw

acer

How about having `f` return unevaluated if its arguments are not of type numeric.

restart:                                          

simp:=plot(sin(x), x=0..2*Pi):                    

f:=(xx,yy)->`if`(yy::numeric and xx::numeric,     
                 `if`(yy > 0, [xx,4*yy], [xx,yy]),
                 'procname'(xx,yy)):              

trns:=plottools:-transform(f):                                               

trns(simp);    

acer

First 252 253 254 255 256 257 258 Last Page 254 of 336