acer

32405 Reputation

29 Badges

19 years, 346 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

The entries in a list can be rotated using ListTools:-Rotate.

The order of entries in a set is not something you'd control.

acer

A few years ago I would have tried implementing this kind of thing using an appliable module with its own overloading exports for arithmetic, etc. It's a pretty good approach, but it has its drawbacks. One issue (which is seen with Units, say) is that the rebound arithmetic operators and other exports only have an effect when used at the top-level. System commands saved in the system library archives have the original global names bound for those operators, and so they don't utilize the redefined or overloaded versions.

Some of these kinds of issues can be alleviated by using the newer objects in Maple. In the attached Document I put a preliminary definition of a phasor-style object in the Startup Code region.

I named my class of phasor objects using the name `∠` so that that entry in the Operators Palette would work. (I suspect that could be similarly useful as the name of Carl's appliable module as well.)

Please let me know if I didn't get some of the math right, or if you have a suggestion. I'm sure that this could be improved.

I used the palette to enter the prettyprinted angle symbol in 2D Input mode. I'd have to investigate whether I could teach it to command-completion also, for pure typing input.

 

``

a := `∠`(30)

module `∠` () local ModulePrint, larg, labs; option object; end module

argument(a)

30

abs(a)

1

b := -`∠`(270)

module `∠` () local ModulePrint, larg, labs; option object; end module

b := `∠`(-1, 270)

module `∠` () local ModulePrint, larg, labs; option object; end module

a+b

module `∠` () local ModulePrint, larg, labs; option object; end module

`∠`(4, 45.0)+`∠`(5, 30.0)

module `∠` () local ModulePrint, larg, labs; option object; end module

`∠`(4, 45)+`∠`(5, 30)

module `∠` () local ModulePrint, larg, labs; option object; end module

evalf[20](%)

module `∠` () local ModulePrint, larg, labs; option object; end module

`∠`(2, 180)+3

module `∠` () local ModulePrint, larg, labs; option object; end module

x*b

module `∠` () local ModulePrint, larg, labs; option object; end module

6.0*b

module `∠` () local ModulePrint, larg, labs; option object; end module

``

 

Download phasorobject1.mw

Here's that first shot at the code for it, from that document's Startup Code region. Sorry if any of the angle names in this 1D plaintext code get rendered like the typeset entity -- it's a problem with this site for code within pre-tags. (I already see something to improve, the case when it gets called with no arguments.)

module `∠`()
  option object, `Copyright (c) 2015 by R. Acer. All rights reserved.`;
  local ModulePrint, larg, labs;
  export ModuleApply::static:=proc()
    Object(`∠`, _passed);
  end;
  export ModuleCopy::static:=proc(new::`∠`,proto::`∠`,
                                  v::scalar)
    if nargs=3 then (new:-labs,new:-larg):=1,v;
    elif nargs=4 then (new:-labs,new:-larg):=args[3],args[4];
    else error "invalid arguments"; end if;
  end proc;
  export argument::static:=proc(a) a:-larg; end proc;
  export abs::static:=proc(a) a:-labs; end proc;
  export `+`::static:=proc()
    local a,o,R,z;
    (a,o):=selectremove(type,[args],`∠`);
    if nargs=1 then return args[1];
    else
      R:=add(abs(z)*exp(argument(z)*Pi*I/180),z=a) + add(z,z=o);
      `∠`(simplify(radnormal(:-abs(R)),size),
                simplify(radnormal(:-argument(R)*180/Pi),size));
    end if;
  end proc;
  export `*`::static:=proc()
    local a,o,R,z;
    (a,o):=selectremove(type,[args],`∠`);
    R:=mul(abs(z)*exp(argument(z)*Pi*I/180),z=a) * mul(z,z=o);
      `∠`(simplify(radnormal(:-abs(R)),size),
                simplify(radnormal(:-argument(R)*180/Pi),size));
  end proc;
  export evalf::static:=proc(a)
    `∠`(:-evalf(a:-labs,_rest),:-evalf(a:-larg,_rest));
  end proc;
  ModulePrint:=proc(a)
    '`∠`'(a:-labs,a:-larg);
  end proc:
end module:

acer

Your current approach does all the work of recomputing the transformation Matrix for each of the M*N entries, when used in constructing the new Array. So for XYZ_D50_to_D65, say, it does the same two Matrix-Matrix multiplications and the Matrix-inversion each of M*N times. It's more efficient to just compute those just once.

Here's one way to do the first of those constructions, in your document. Instead of using the Array() constructor I'll just map onto the input Array a procedure which applies the transformation Matrix to a Vector entry.

F := XYZ_to_LMS^(-1) . LMS_D50_to_D65 . XYZ_to_LMS;

map( v -> F . v, CCXYZ_D50 );

Alternatively, if you want it as a named operator,

XYZ_D50_to_D65 := subs(_OP = XYZ_to_LMS^(-1) . LMS_D50_to_D65 . XYZ_to_LMS, v -> _OP . v):

map(XYZ_D50_to_D65, CCXYZ_D50);

acer

Use the form,

if is( 2 < sqrt(5) ) then
  ...
end if;

Note that is can also return FAIL, in the case that it cannot determine whether the result is true or false. So for more complicated examples you might use the variant  if is(....)=true then ... and perhaps also have an elif case to for FAIL.

In your example is will utilize shake to test the result in floating point. So for your simple example you could also do,

if evalf( 2 < sqrt(5) ) then ...

acer

int(exp(-t^2-x^2*t^(-2)), t = 0 .. infinity) assuming x::real;

                                     (1/2)   
                                   Pi        
                                -------------
                                            2
                                2 (exp(|x|)) 

 

If the table tells you that the expected answer depends on a special condition or restriction then you could try using that as an assumption.

Also, without the restriction but with a particular method forced,

restart;

simplify(int(exp(-t^2-x^2*t^(-2)), t = 0 .. infinity, method=meijerg));

                    1        2   (1/2)                  
                    - csgn(x)  Pi      exp(-2 csgn(x) x)
                    2       

See also the results from various methods of definite integration,

simplify(int(exp(-t^2-x^2*t^(-2)), t = 0 .. infinity, method=_RETURNVERBOSE));

acer

When you call just `int` with exact end-points it attempts to do symbolic integration, which was hitting an uncaught error internally. You can force numerical quadrature by either 1) supplying float end-points, 2) supplying the `numeric` option to `int`, or 3) calling it as `evalf(Int(...))`.

V1:=<seq(x, x=0..1, 0.1)>:

V2:=<seq(x^2, x=0..1, 0.1)>:

y:=x->CurveFitting:-ArrayInterpolation(V1,V2,x,method=spline):

int(y, 0..1.0);                                               
                               0.333429558010905

int(y, 0..1, numeric);
                               0.333429558010905

evalf(Int(y, 0..1));
                               0.333429558010905

y:=x->CurveFitting:-ArrayInterpolation(V1,V2,x,method=spline,degree=5):

int(y, 0..1, numeric);
                               0.333333333333311

For efficiency with a large amount of data you should import your Vector and give them datatype=float[8].

For very large amounts of data the construction and evaluation of the piecewise returned by CurveFitting:-Spline (or its symbolic integral) can become quite expensive. (This may have become less of an issue, if Maple can sort the "univariate" piecewise conditions so that evaluating it at a point can do a quicker binary search. It's more expensive if it has/had to check conditonals from left to right.)

acer

Yes. One way is to save it to a .mla "library archive", using LibraryTools.

Then you can access it in any new session that has that library file's location in libname. And if you want that part to be automatic (for all new sessions) then you can set libname in your initialization file.

acer

Change those square brackets to round brackets.

In Maple the square brackets construct a list. You have a list raised to the power 2. I suppose you intended to obtain a scalar quantity, to be plotted.

In Maple round brackets are used as delimiters.

acer

Put a multiplication sign between the x and the (12*t+1) , if that's what you intended.

Or did you intend for that to a be function application?

acer

The Intel i5 and i7 series CPUs do well, even for the releases of a few years ago. That is you dont need the latest and greatest, which are not cost ineffective anyway. I don't suggest a Xeon for the same reason. I don't suggest a Xeon phi as it requires a special build against a special version of the Intel MKL (which maple doesn't offer) to attain its peak numeric linear algebra capabilities.

I recommend an nvidia graphics card over an ATI card. Not latest and greatest, both to hit cost effectiveness and minimize chances of driver problems. Some older ATI  cards caused problems with hardware acceleration of plots and manual 3D plot rotation.

The choice of Operating System matters. I recommend 64bit Maple for performance. Overall I perceive best performance on 64bit Linux.

acer

Replace (e)^(x) with exp(x) .

Also, define your operator like,

f := x -> -ln(x)+exp(x)

But don't put f(x) on the left-hand-side of an assignment statement. It's an abomination.

acer

How about just using the older mechanism, for which ~ is a newer short syntax?

map(int8,map(round,S))

acer

You problem seems to be that you were expecting subs to do an evaluation, following syntactic substitution. It doesn't. Use eval instead. This is a frequently asked question.

restart;

f := diff(y(x),x,x) + y(x) = sin(x):

subs(y(x) = sin(x), f);

                       /  2        \                  
                       | d         |                  
                       |---- sin(x)| + sin(x) = sin(x)
                       |   2       |                  
                       \ dx        /                  

%; # an evalution

                                 0 = sin(x)

eval(f, y(x) = sin(x));

                                 0 = sin(x)

acer

Why not make Track a submodule of Lattice? If you give submodule Track its own ModuleApply then you can continue to call it as before. But it could then have trackElement as its own module local.

Btw the example you posted would work if you hade trackElement defined prior to using it, inside the body of Track. One reason that's undesirable is that Maple has to recreate trackElement each time Track is called, which is a waste of resources.

acer

It isn't clear to whether you are asking for a way merely to display the list r and the list of its type-checked results in an aligned and tabulated manner.

Other have shown how to print a sequence of lists of lists, which displays horizontally across the worksheet.

But it occurs to me that you might instead be asking for ways to print the pairwise, vertically stacked, and horizontally aligned, results. That is, with a row of entries of r displayed on top of a row of the type-check results. It occurs to me that you may be looking for such a particular form of display, for the sake of your students, say.

So, on the chance that I've guessed rightly, here are a few ways to get that effect without the need to clutter the worksheet with the fenced boundaries of a pretty-printed Matrix. Note that in the examples below there is no returned value from the code which does the display. It's just an act akin to printing.

If current and older Maple you can use the printf command for such formatted display. A drawback here is that there is not prettyprinting of 2D Math.

In Maple 2015.1, using the Standard Java GUI you can also get a variety of effects from an embedded GUI Table, using the DocumentTools:-Tabulate command. Again, please note that neither of these commands return a value, and moreover you can't interleave all of this display amongst other regularly printed output in the same Execution Group.


restart;

r := [-3, -2.5, 0, 1, 3/2, Pi, sqrt(5)]:

printf("%{}9a\n\n%{}9a\n\n", <r>, <type~(r,nonnegint)>);

       -3      -2.5         0         1       3/2        Pi   5^(1/2)


    false     false      true      true     false     false     false

L := [r, type~(r,nonnegint)]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(L, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none);
interface(typesetting=oldsetting):

-3

-2.5

0

1

3/2

Pi

sqrt(5)

false

false

true

true

false

false

false

 

 
  By using strings for true and false we can get them shown with an upright font.

LL := [r, convert~(type~(r,nonnegint),string)]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(LL, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none);
interface(typesetting=oldsetting):

-3

-2.5

0

1

3/2

Pi

sqrt(5)

false

false

true

true

false

false

false

 

LLL := [["",r[]],
     ["nonnegint",convert~(type~(r,nonnegint),string)[]],
     ["numeric",convert~(type~(r,numeric),string)[]],
     ["realcons",convert~(type~(r,realcons),string)[]]]:

oldsetting := interface(typesetting=extended):
DocumentTools:-Tabulate(LLL, width=500, widthmode=pixels, alignment=left,
                        interior=none, exterior=none,
                        color=((T,i,j)->`if`(j=1,black,
                               `if`(T[i,j]="true","#009900","#bb0000"))),
                        fillcolor=((T,i,j)->`if`(i=1 or j=1, "#dddddd", "#cccccc")));
interface(typesetting=oldsetting):

 

-3

-2.5

0

1

3/2

Pi

sqrt(5)

nonnegint

false

false

true

true

false

false

false

numeric

true

true

true

true

true

false

false

realcons

true

true

true

true

true

true

true

 

 


tabled.mw

acer

First 219 220 221 222 223 224 225 Last Page 221 of 336