acer

32333 Reputation

29 Badges

19 years, 326 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Is ImageTools:-Complement what you're looking for? Eg,

with(ImageTools):

img:=Scale(Read(cat(kernelopts(datadir),"/images/rollercoaster.jpg")),0.6):

Embed([img,Complement(img)],exterior=none,interior=none);

img:=Scale(Read(cat(kernelopts(datadir),"/images/tree.jpg")),0.6):

Embed([img,Complement(img)],exterior=none,interior=none);

That's `color inversion' in this sense (in the RGB colorspace): green<->magenta, blue<->yellow, red<->cyan.

acer

Another technique, the earliest use of which I'm aware is by Alec Mihailovs (and used inside plots:-shadebetween I believe):

 

restart;

(f,g):=2,1/sqrt(1-x^2):
plottools:-transform(unapply([x,y+g],x,y))(plot(f-g,x=0..sqrt(3)/2,filled=true));

 

 

Download shadeb.mw

acer

Is Example 4 on this page the kind of thing you mean? (Also see the trig identity example here.)

Another way to manipulate expressions (and equations) and see steps taken is to use the Equation Manipulator.

Or are you trying to achieve step-by-step integration? If so, see the this tutor or this overview.

acer

You can use plots:-spacecurve to plot this in your Maple 18.

And you can Explore the spacecurve, to see how the parameters affect the curve. See the attachement below.

spacecurve.mw

acer

How about something like this? You'd apply it to your expression or name, instead of applying numelems.

nelems := e->`if`(e::indexable,numelems(e),0):

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 `&angle;` 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 := `&angle;`(30)

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

argument(a)

30

abs(a)

1

b := -`&angle;`(270)

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

b := `&angle;`(-1, 270)

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

a+b

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

`&angle;`(4, 45.0)+`&angle;`(5, 30.0)

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

`&angle;`(4, 45)+`&angle;`(5, 30)

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

evalf[20](%)

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

`&angle;`(2, 180)+3

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

x*b

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

6.0*b

module `&angle;` () 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 `&angle;`()
  option object, `Copyright (c) 2015 by R. Acer. All rights reserved.`;
  local ModulePrint, larg, labs;
  export ModuleApply::static:=proc()
    Object(`&angle;`, _passed);
  end;
  export ModuleCopy::static:=proc(new::`&angle;`,proto::`&angle;`,
                                  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],`&angle;`);
    if nargs=1 then return args[1];
    else
      R:=add(abs(z)*exp(argument(z)*Pi*I/180),z=a) + add(z,z=o);
      `&angle;`(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],`&angle;`);
    R:=mul(abs(z)*exp(argument(z)*Pi*I/180),z=a) * mul(z,z=o);
      `&angle;`(simplify(radnormal(:-abs(R)),size),
                simplify(radnormal(:-argument(R)*180/Pi),size));
  end proc;
  export evalf::static:=proc(a)
    `&angle;`(:-evalf(a:-labs,_rest),:-evalf(a:-larg,_rest));
  end proc;
  ModulePrint:=proc(a)
    '`&angle;`'(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

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