acer

8 years, 203 days


These are answers submitted by acer

applyrule

2 hours ago acer 9706
0 0

Simplification with side relations (which Markiyan demonstrates in another Answer) can be an easy way to get such an effect. It's a good answer.

But it can also be noted that there are times and other examples when some of the simplifications done to an expression might not be what is wanted. Consider the case that the input expression is conjugate(z)*z^2*(ln(2*z) and one wishes to replace conjugate(z)*z while also leaving ln(2*z) intact. In other words, the following might not be what is wanted,

simplify( conjugate(z)*z^2*(ln(2*z)), {z*conjugate(z)=x} );

                           (ln(2) + ln(z)) x z

And of course there are related problematic examples where some undesired aspect of simplification is not easily undone after the fact (with `combine` or what have you). In other words, the need for (only) plain substitution is not obviated by fixing the above simplistic example by calling something like `combine` on the result.

So it might be that for some examples one wants just the substitution. And `algsubs` goes awry trying to figure out where and whether z*conjugate(z) is "present". So it's natural to still ask whether `applyrule` could work here.

A difficulty is that `applyrule` does not see z*conjugate(z) as being present within conjugate(z)*z^2 say, and other related situations. An alternative for the rule used might be,

T:=ee->applyrule(z^(m::posint)*conjugate(z)^(n::posint)
                 = x*z^(m-1)*conjugate(z)^(n-1),ee):

And a few rudimentary examples to compare with the simplification with side effects might include,

R:=ee->simplify(ee,{z*conjugate(z)=x}):

f1:=conjugate(z)^2*z^2:
T(f1), R(f1);

                              2   2
                             x , x 

T(conjugate(z)*z^2), R(conjugate(z)*z^2);

                            x z, x z

T(conjugate(z)^5*z^2), R(conjugate(z)^5*z^2);

                              3      3
                           2 _    2 _ 
                          x  z , x  z 

T(conjugate(z)/z^2), R(conjugate(z)/z^2); # no change expected
                             _   _ 
                             z   z 
                             --, --
                              2   2
                             z   z 

But now we might notice that the above does not handle the case where the z*conjugate(z) appears in the denominator. We could try and clean that up crudely, by just repeating the process.

T:=ee->applyrule(z^(m::negint)*conjugate(z)^(n::negint)
                 = 1/(x/(z^(m+1)*conjugate(z)^(n+1))),
                 applyrule(z^(m::posint)*conjugate(z)^(n::posint)
                           = x*z^(m-1)*conjugate(z)^(n-1),ee)):

T(1/(conjugate(z)*z^2)), R(1/(conjugate(z)*z^2));

                             1    1 
                            ---, ---
                            x z  x z

T(1/(conjugate(z)^2*z^3)), R(1/(conjugate(z)^2*z^3));

                            1     1  
                           ----, ----
                            2     2  
                           x  z  x  z

And we can see how the two approaches differ with respect to leaving other terms unchanged (or not), for the example previously mentioned,

expr:=conjugate(z)*z^2*(ln(2*z)):
T(expr), R(expr);

                x z ln(2 z), (ln(2) + ln(z)) x z

It's unfortunate that `applyrule` is not as robust and easy to use as it might be, since it does seem to fulfil at least some needed functionality. (I would not be very surprised if the usage examples I gave above fall down on some related, problematic examples.)

acer

STL format

Yesterday at 2:38 AM acer 9706
0 0

Maple 18 can export 3D surface plots to STL (Stereolithography) file format, which some 3D printers might support directly. (Or you may be able to convert from STL to .x3g format.)

acer

elementwise

April 21 2014 acer 9706
4 2

Do you mean like this?

> A:=<<1|2>,<3|4>>;
                                      [1    2]
                                 A := [      ]
                                      [3    4]

> B:=<<2|3>,<4|5>>;
                                      [2    3]
                                 B := [      ]
                                      [4    5]

> A .~ B;          

                                  [ 2     6]
                                  [        ]
                                  [12    20]

> A *~ B;      

                                  [ 2     6]
                                  [        ]
                                  [12    20]

> zip(`*`,A,B);

                                  [ 2     6]
                                  [        ]
                                  [12    20]

acer

operator form

April 21 2014 acer 9706
0 0

It may be that Optimization internal routines are incorrectly identifying the objective expression as having 3 independent variables, where it mistakenly decides that the objective "depends" upon `t` the dummy variable of integration.

You could try something like this (which got me a numeric result in Maple 17.02),

restart:

eta:= 1000:  B:= 5/2:

obj := Int(B*eta^(-B)*t^(B-1)*exp(-(t/eta)^B)*(t-n*h),t=n..(n+1)*h)
       /Int(B*eta^(-B)*t^(B-1)*exp(-(t/eta)^B), t = n .. (n+1)*h):

evalf(subs(n=1,h=1.5,obj));

plot3d(obj,n=0..10,h=1..2);

with(Optimization):

F:=proc(N,H)
  local res;
  res := evalf(subs(n=N,h=H,obj));
  #if not type(res,numeric) then
  #  res:=Float(undefined);
  #  print([N,H]);
  #end if;
  return res;
end proc:

#infolevel[Optimization]:=3:

Minimize(F,0..10,1..2);

Of course you'll have to make sure that the ranges for n and t are correct, and similarly for those ranges of integration (like Carl, I find the range t=n..(n+1)*h a bit strange). Also, you may run into difficulties if it encounters values of n and h for which the numeric integration fails to produce a numeric value for the objective.

I will submit a bug report against the problematic Minimize(obj,n=0..10,h=1..2). I am not sure why it cannot rely upon `depends`, where depends(obj,t) returns false here.

Note that the following also gets a numeric result, by specifying the names of the variables when using the expression form,

Minimize(obj,n=0..10,h=1..2,variables=[n,h]);

acer

cylindrical

April 15 2014 acer 9706
1 1

Do cylindrical coordinates make your goal easier?

I am just guessing based on your diagram and description, but are you trying to produce something like one of these?

restart:
with(plots):
k:=8:

display(
   spacecurve([1,theta,0],theta=0..2*Pi,
              color=blue,coords=cylindrical),
   spacecurve([1,theta,cos(k*theta)],theta=0..2*Pi,
              color=red,coords=cylindrical,numpoints=1000)
        );

display(
   spacecurve([1,theta,0],theta=0..2*Pi,
              color=blue,coords=cylindrical),
   spacecurve([1+cos(k*theta)/4,theta,0],theta=0..2*Pi,
              color=red,coords=cylindrical,numpoints=1000)
        );

display(
   spacecurve([1,theta,0],theta=0..2*Pi,
              color=blue,coords=cylindrical),
   spacecurve([1+cos(k*theta)/4,theta,sin(k*theta)],theta=0..2*Pi,
              color=red,coords=cylindrical,numpoints=1000)
        );

display(
   spacecurve([1,theta,0],theta=0..2*Pi,
              color=blue,coords=cylindrical),
   spacecurve([sqrt(1+(cos(4*theta)^2-1/2)/2),theta,0],theta=0..2*Pi,
              color=red,coords=cylindrical,numpoints=1000)
        );

display(
   spacecurve([1,theta,0],theta=0..2*Pi,
              color=blue,coords=cylindrical),
   spacecurve([sqrt(1+(cos(4*theta)^2-1/2)/2),theta,sin(8*theta)],theta=0..2*Pi,
              color=red,coords=cylindrical,numpoints=1000)
        );

acer

Constant(a[0])

April 11 2014 acer 9706
0 1
restart:
with(ScientificConstants):

GetValue(a[0]);
Error, (in ScientificConstants:-GetValue) `a[0]` is not a scientific constant object

GetValue(Constant(a[0]));

                                     -11
                       5.291772081 10   

acer

eigenvalues

April 11 2014 acer 9706
1 13

The SVD may be used on your example. The first r=Rank(C) columns of orthonormal left singular vectors of C may be used, along with the first r singular values, to define matrices A and B.

Here is another diagonalizable 3x3 rank=2 symmetric example, but with eigenvalues of mixed sign.

restart:
with(LinearAlgebra):
C:=Matrix([[1.,1,2],[1,1,2],[2,2,2]],shape=symmetric,datatype=float):

r:=Rank(C);

                                   r := 2

Eigenvalues(C);

                            [-0.828427124746191]
                            [                  ]
                            [                0.]
                            [                  ]
                            [  4.82842712474619]

u,s,vt := SingularValues(C,output=[U,S,Vt]):

map(fnormal, u.u^%T); # orthonormal

                   [1.000000000           0.           0.]
                   [                                     ]
                   [         0.  1.000000000          -0.]
                   [                                     ]
                   [         0.          -0.  1.000000000]

fnormal( Norm(C - u[..,1..r].DiagonalMatrix(s[1..r]).vt[1..r,..]) );

                                     0.

A := u[..,1..r]; # dimension 3x2

                     [-0.500000000000000  -0.500000000000000]
                     [                                      ]
                A := [-0.500000000000000  -0.500000000000000]
                     [                                      ]
                     [-0.707106781186548   0.707106781186548]

B := DiagonalMatrix(s[1..r]).vt[1..r,..]; # dimension 2x3

            [-2.41421356237309  -2.41421356237310   -3.41421356237310]
       B := [                                                        ]
            [0.414213562373095  0.414213562373095  -0.585786437626905]

map(fnormal, B . A );

                        [4.828427125            -0.]
                        [                          ]
                        [        -0.  -0.8284271247]

 

The repeated eigenvalues {9,9} of your original C form the diagonal Matrix result.

It is also possible to show this on paper, where the difference in sign between columns of u and columns of v account for the differences in sign between the corresponding singular values and eigenvalues.

[update: the above may be a very poor choice of another example, since B.A may not be uniquely determined. comments below, about why, possibly. ugh.]

acer

how's this?

April 09 2014 acer 9706
3 1

Is this better?

2014_PDE_project_mod.mw

acer

Matrix

April 09 2014 acer 9706
1 1

This can be done without loops.

I wasn't sure whether your various functions names are indexed or not.

f:=M->Matrix(M,M,(i,j)->psi[1,i-1]((2*j-1)/(2*m))):
f(1), f(2), f(3);

f:=M->Matrix(M,M,(i,j)->cat(psi,1,i-1)((2*j-1)/(2*m))):
f(1), f(2), f(3);

acer

unapply

April 05 2014 acer 9706
0 0

f := unapply(a,x);

acer

one way

March 30 2014 acer 9706
1 2
thingy:=(L1,L2)->remove(member,L1,L2):

thingy([1,2,4,6,2,1,3,6,2],[7,4,2,5,2]);

                        [1, 6, 1, 3, 6]

If the second list is very large and has lots of duplicates not found within the first then it may help to first turn the second into a set. Ie,

thingy:=proc(a1::list, a2::list)
    local s2;
    s2:={op(a2)}; # saves effort, using a uniquified version
    remove(member,a1,s2);
end proc:

thingy([1,2,4,6,2,1,3,6,2],[7,4,2,5,2]);

                        [1, 6, 1, 3, 6]

acer

good question

March 27 2014 acer 9706
1 0

This is a good question. Hm. As far as I know the footer & header details (whether custom or not) are not picked up as part of a Style Sheet. (There's style details for footer and header, but it is just about the font, etc, used within any footer or header.) It might be a good improvement, if the GUI were to offer such a choice.

The only thing I have thought of is to create a blank sheet with your custom header and footer, and then to use that as a template for your new documents.

But that could be a pain, as the GUI's Recent Documents list is only so long, and rolls over. And it could be irritating to keep ruining the File Manager's remembered location by having to find the template. So a question is: how to easily and conveniently open some template sheet.

A .mw file can be opened by using a command. That command call could be shortened via an assignment. And that could be put into one's initialization file, so that it is just a few letters to type in.

Or the call (as input) could be right-clicked and made into a Task (on the Task palette) using a context-menu action. Then you could just click the palette entry, and then hit return on what it injected.

So, here is the kind of call I mean,

  streamcall(INTERFACE_WORKSHEET(':-display',
                                 ':-file'=cat(kernelopts(':-homedir'),
                                              "/Documents/MyTemplate.mw")));

The problem with these approaches is that some new input -- short as it might be made -- appears in your current document each time you invoke the template. It might be short, but it's still clutter.

note to experts: I wonder whether a custom addition to the right-click context menus could be made to effect the streamcall and then... to abort, with nothing inserted into the current sheet (not even NULL!).

Your Question is marked as being for Maple 17. There are easier ways to launch a template worksheet (with custimized footer or header) in Maple 18:

- One way is to set the template file as the "Startup page". Maple 18's Standard GUI has a new icon on its main menubar, which can be associated with any worksheet file of your choice. That can be associated with any worksheet of your choice, under Tools->Options->Interface-> Open worksheet at startup.

- Another way is to add a new kind of embedded component to whatever is your Startup page. (You could even save the default new Startup page to some new filename, add the new kind of embedded component to that, resave and make that copy the new Startup page. The new kind of embedded component I'm thinking of is called a Shortcut (see ?ShortcutComponent when the Online Help is updated to match Maple 18). That new kind of component can be set to open a particular worksheet whenever that component gets pushed.

So, in Maple 18 you could open a particular (template) worksheet as easily as just clicking on the Start page icon on the menubar, or by clicking on that icon to get to a page which contains a Shortcut component worksheet launcher.

acer

libname

March 26 2014 acer 9706
4 0

For a few releases now `.` is automatically in `libname`.

I think that is quite risky, especially for those in the habit of writing out .m files (also dubious, IMHO).

So perhaps you could strip that solitary `.` from `libname` in your initialisation file. Either of these might do, I suppose,

libname:=remove(type,[libname],identical("."))[];

libname:=remove(`=`,[libname],".")[];

acer

maybe

March 25 2014 acer 9706
1 6

Let me know if I got the shift bookkeeping wrong.

For your 184x184 image pair there are 184^2/2 possible shifts of the 1D Array in each direction (well, there is also the zero-shift...). This below takes about 35sec for all 184^2+1 possible shifts & adds, running Compiled. But it should be possible in Maple 18 to run that Threaded as well, with a bit more bookkeeping effort.

Running Compiled serially is faster than running 4-way parallelized evalhf for this code, I believe. But running the Compiled version in parallel and getting a few more factors of 2 out of it might be nice.

Anyway... let me know if I got it all wrong. Do you have the solution image already, to compare with?

[update: I used C[SBest] when I should have used just SBest in the final call to CircularShift. And padding either image with zeroes seems wrong for this shifting & abs-differencing scheme, so I have changed that to simple rescaling. I've updated the inlined content and attached worksheet and the final result looks much more sensible now.]


``

restart:

with(ImageTools):

img1 := Read(cat(kernelopts(homedir),"/Documents/circshift/13ydvt0.jpg")):
img2 := Read(cat(kernelopts(homedir),"/Documents/circshift/30rkxvt.jpg")):

# Scale img1 to dimensions of img2
# (padding with zero seems not appropriate to this circular shift
# and absolute-difference scheme.
img1 := Scale(img1,1..184,1..184):

``

View([img1,img2]);

with(ArrayTools):

A:=Reshape(img1,[1..184*184]):

B:=Reshape(img2,[1..184*184]):

p:=proc(N::integer, lo::integer, hi::integer, k::integer,
        a::Array(datatype=float[8],order=C_order),
        b::Array(datatype=float[8],order=C_order),
        c::Array(datatype=float[8],order=C_order))
  local cbest::float,tot::float,i::integer,kps::integer,
        s::integer,sbest::integer,Nsq::integer;
  sbest:=0; cbest:=1.0e6; Nsq:=N*N;
  for s from lo to hi do
    tot:=0.0:
    for i from 1 to Nsq do
      tot := tot+abs(b[i]-a[irem(Nsq-1+i-s,Nsq)+1]);
    end do;
    c[k+s]:=tot;
    if c[k+s]<cbest then
      sbest:=s; cbest:=c[k+s];
    end if;
  end do;
  return sbest;
end proc:
cp:=Compiler:-Compile(p):

C:=Array(1..401,datatype=float[8],order=C_order):
SBest:=CodeTools:-Usage( trunc(evalhf(p(184,-200,200,201,A,B,C))) );
C[201+SBest];

memory used=0.92KiB, alloc change=0 bytes, cpu time=4.90s, real time=4.91s, gc time=0ns

-37

HFloat(4148.680813681025)

# The Compiled version is about 10 times faster than the evalhf'ed version
C:=Array(1..401,datatype=float[8],order=C_order):
SBest:=CodeTools:-Usage( cp(184,-200,200,201,A,B,C) );
C[201+SBest];

memory used=0.84KiB, alloc change=0 bytes, cpu time=468.00ms, real time=469.00ms, gc time=0ns

-37

HFloat(4148.680813681025)

M:=184^2/2;
C:=Array(1..2*M+1,datatype=float[8],order=C_order):
SBest:=CodeTools:-Usage( cp(184,-M,M,M+1,A,B,C) );
C[M+1+SBest];

16928

memory used=0.81KiB, alloc change=0 bytes, cpu time=39.73s, real time=39.80s, gc time=0ns

1987

HFloat(2076.2536656353514)

final:=CircularShift(A,SBest):
imgfinal:=Reshape(final,[184,184]):

View([img1,img2,imgfinal]);
#Embed([img1,img2,imgfinal]);

plots:-pointplot(<<seq(i,i=-M..M)>|Vector[column](C)>,
                 gridlines=false);

 

``


Download circshift5.mw

 

acer

which versions

March 24 2014 acer 9706
2 2

Which version of Maple did you create the worksheet in? Which version of the Player do you use? I don't think that the "18" version of the Player has been made available yet, has it?

I was able to use the exploration if I created it in Maple 17 and then ran it in "Maple Player 17" (seen from the About menubar item in the Player).

But in order to get it to run properly, even with the versions matching (ie. version 17 for both creation and player) I had to put the assignment fn:=x^2; into the Startup Region of the document. That makes sense to me, since the Player does not run or execute all the contents of an opened sheet. But it does run the Startup Region's code if present. Your plot exploration depends upon `fn` being defined as an expression in terms of `x`. (This is an important aspect of the Player, and is not just related to Explore per se. If the action code behind any embedded components require some previous assignments then those could be executed in the Startup Region.)

By the way, the edited exploration that I got to run in Maple 17 and the Maple 17 Player also worked for me if I opened it in Maple 18. That is evidence of some degree of backwards compatibility.

But forwards compatibility is another story. Often when trying to open in Maple's GUI some document created in a later version there will be a warning about some features possibly not working.

Another observation, which I hope won't confuse the items above: The examples in the ?examples,Explore sheet don't make much if any use of names which have been assigned symbolic expresssions. The first argument to Explore has special evaluation rules (which seems to me to have been an early design mistake). I believe that there are cases where such chained symbolic assignments will not get adequately evaluated and resolved to be interpreted in terms of the names one might expect. It seems ok in this example but in general I would suggest instead either making the expression fully explicit in the actual call or use a function call. Eg,

Explore( plot(a*x^2,x=-2..2,view=-10..10),parameters=[a=1..5.0]);

or,

fn:=x^2:
f:=a->plot(a*fn,x=-2..2,view=-10..10):
Explore(f(a),parameters=[a=1..5.0]);

or,

f:=a->plot(a*x^2,x=-2..2,view=-10..10):
Explore(f(a),parameters=[a=1..5.0]);

or, (and the expert may recognize this as a heavy-handed way around the special evaluation rules, because `Explore` isn't as, umm, "convenient" as `plots:-animate` or `frontend`),

restart:
fn:=x^2;
eval('Explore'( 'plot'(a*fn,x=-2..2,view=-10..10),parameters=[a=1..5.0]));

acer

1 2 3 4 5 6 7 Last Page 1 of 94