sursumCorda

922 Reputation

13 Badges

2 years, 206 days

MaplePrimes Activity


These are questions asked by sursumCorda

In an old question, @nm asked how to . While the answer in that question was almost up to the mark, there remains a regret. 

As the instance listed below shows, Maple, by default, draws arrows on a rectangular grid (rather than on a hexagonal mesh): 

  # Example of a three-dimensional vector field: 
vf__2d := VectorCalculus:-VectorField([sin(x)*(cos(x) + cos(y)), 
                                       sin(y)*(cos(x) - cos(y))], 'cartesian'[x, y]):
  # Example of a two-dimensional vector field: 
vf__3d := VectorCalculus:-VectorField([1 - (sin(u - v) + sin(u - w)), 
                                       1 - (sin(v - w) + sin(v - u)), 
                                       1 - (sin(w - u) + sin(w - v))], 'cartesian'[u, v, w]):
  # Phase portrait. 
Student:-VectorCalculus:-PlotVector(vf__2d, (x, y) =~ -Pi .. Pi, 
                                            'grid' = [`$`](25, 2), 
                                          'arrows' = 'THICK', 
                                   'fieldstrength' = log[63], 
                                           'color' = ColorTools:-Color("#0072BD"), 
                                            'axes' = "box"(*, …omitted…*));
= 

Note that I have changed some of the options in order to make the layout of arrows more prominent.
However, according to the help page of Mma's VectorPoints, among the following methods of location generation, Mma by default uses Hexagonal for 2D field vectors and FaceCenteredCubic for 3D field vector: 

Here is a collection of different settings available in Mma:

So if the requirement is to get the Maple's output looking like Mathematica's (see the beginning), the number and placement of vectors to plot should be thought of as well. In Maple, “the number of vectors” can be controlled by the plot (or plot3d) opinion , but how do I specify “the placement of vectors” (e.g., Mma's "Hexagonal" and "Mesh")?

Although there exists an  chapter in the documentation, randomly positioned arrows do not fit the bill. Is there any workaround?

This question is an expansion of my previous reply. 

There exist sixty kinds of statements in Maple, whose major ​​​​portion can be used as an expression or within an expression (e.g., assignment, loop, and condition). But why is use an exception?

Moreover, since it is reasonable to think of use as a (partial) generalization (see below) of the subs function, shouldn't the behaviour of use be consistent with do/if?

Compare: "seq((…;…;…), x in x__0):" (not allowed) vs. "for x in x__0 do …;…;… od:" (allowed); "subs(x = x__0, (…;…;…)):" (not allowed) vs. "use x = x__0 in …;…;… od:" (Not allowed! Why?).)

Edit. Besides that, is there some workaround to do something like

  # If use can be used as an expression or within an expression, 
use x = 2 + y in 'use y = 4 in x + y end' end;
  # should return “use y~ = 4 in (2 + y) + y~ end use;” and 
(use y = 2 + x in x -> x + y end);
  # should output “x~ -> x~ + (2 + x);”. 
  # Unfortunately, I cannot find a workaround to stimulate them.

 at present? Note that the `subs` function is unable to do so, so in my opinion, only when the use of `use` is no longer limited to statements will it become a sweeping generalization of `subs`.

The documentation says:

A for...in loop can optionally have two loop variables. … If the second variable is the name _ (a single underscore), this indicates that the value is not needed, and Maple may choose to not look it up, and not assign a value to _.

So “_” can be treated as an argument placeholder in a for–in loop. Nevertheless, I would like to know if there is an argument placeholder like MatLab's tilde (~) operator:

Ordinarily, there is no need to to ignore inputs in function definitions, but as for the former, since there is a _nresults keyword in Maple (and some "built-in" routines do use it), when accessing the source code is unavailable, how do I ignore specific outputs from such a function (e.g., a procedure with option encrypted that has been loaded from a repository)?
For instance, the help page of MTM:-eig mentions three calling forms: 

  1. l := MTM:-eig(A): 
  2. [V,L] := MTM:-eig(A): 
  3. [V,L,N] := MTM:-eig(A): 

If I do not directly invoke the linalg/Student[LinearAlgebra]/LinearAlgebra/Matlab package (and do not manually compute Eigenvals), will it be possible to imitate MatLab's 

[~, ~, W] = eig(A);

in Maple as verbatim as possible? 
Note that MatLab's help page claims: 

… In this case, the variables are small. However, some functions return results that use much more memory. If you do not need those variables, they waste space on your system. …

There are two opposing commands remove and select in Maple. According to the main help page, StringTools:-RegSplit effectively implements the removal (i.e., capturing substrings that does not match the given pattern), but as regards extracting the matching parts of the input string (e.g., this example from MatLab), where is the command to carry out the selection?
At present I can do something like 

use StringTools in RegFilter := (p::string, s::string) -> select[2](RegMatch, sprintf("^%s$", p), (op@NGrams)~(s, [`$`](Length(s)))) end:
RegFilter("a.++b", "aabbbaaabb");
 = 
 ["aab", "abb", "aab", "abb", "aabb", "abbb", "aaab", "aabb", 

   "aabbb", "aaabb", "abbbaaab", "aabbbaaab", "abbbaaabb", 

   "aabbbaaabb"]


Nevertheless, there exist at least two disadvantages to it.

This is essentially equivalent to letting the matcher keeps starting at the same position until no more new matches are found, while sometimes one may just need the matcher to continue the shortest-match testing at the character following the last matched substring after finding a match:

For instance, there should be three flags in “RegFilter("a.+?b", "aabbbaaabb", 'overlapped'=⁇);”: 
⒈“["aab", "aaab"]” (selection with no overlap), 
⒉“["aab", "abb", "aaab", "aab", "abb"]” ( with partial overlaps), and 
⒊“["aab", "aabb", "aabbb", "aabbbaaab", "aabbbaaabb", "abb", "abbb", "abbbaaab", "abbbaaabb", "aaab", "aaabb", "aab", "aabb", "abb"]” ( with full overlaps). 

Unfortunately, the  above can only handle the last mode.

Another disadvantage is its inefficiency. Considering the following regular expression which matchs email-like strings

sample := Import("https://github.com/mariomka/regex-benchmark/raw/optimized/input-text.txt"): # lengthy 
re := "[a-zA-Z_0-9\\.+-]+@[a-zA-Z_0-9\\.-]+\\.[a-zA-Z_0-9\\.-]+":
time[real]((remnants := StringTools:-RegSplit(re, sample)));
 = 
                             3.157

So Maple is capable of completing this removal within 4 seconds, yet if I execute the analogous

timelimit(60, time[real](RegFilter(re, sample))); 

Maple will end up running out of memory.

In view of these, where is the generic StringTools:-RegFilter functionality? Or can we construct those matched cases from  and the original text?

In short, I'd like to obtain n largest/smallest elements in a huge list of (probably non-numeric) data. Of cource I can sort it and then extract the desired part, yet isn't there a dedicated procedure that do a partial sort of the input data in Maple?

Edit. In a MatLab weblog, the blogger gave: 

So I believe that a dedicated one is not useless. But what is the Maple equivalent to MatLab's maxk, mink, and topkrows?

3 4 5 6 7 8 9 Last Page 5 of 19