acer

32385 Reputation

29 Badges

19 years, 335 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Unfortunately the plots:-listcontplot command doesn't (yet) offer easy options for specifying the ranges of the X and Y data, in the way that the plots:-surfdata command does. And the 2D usage of the surfdata command doesn't allow style=contour or style=surfacecontour.

So here are three approaches. (I concocted a procedure so that I could get some Z data with which to work.)
1) plot3d and a forced orientation so as to appear like a 2D plot.
2) contourplot using an interpolating object (made from the data)
3) listcontplot and a rescaling of the result. [Also possible here are forced tickmarks, but I didn't do that because it uses similar formulas and IMO it's slightly inferior to solve an issue by faking tickmarks. You could also refine Z by interpolating it using ArrayInterpolation, and then use listcontplot. But since that still leaves the tickmarks issue it just seems like unnecessarily more effort than approach 2).]

matrix_cont_plot.mw

If the approach of generating such smooth, interpolated contours is ok for you, then note that there are additional options and choices to control the interpolation scheme. I leave that aside for now.

Are you aiming for a pde33 result something like this?

de_subst.mw

Using Maple 2020.1,

filenm:="https://www.gw-openscience.org/GW150914data/P150914/fig2-unfiltered-template-reconstruction-H.txt":

M:=ImportMatrix(filenm,source=Matlab,skiplines=1):

plot(M[..,[1,3]]);

You can add various options for the plotting command (eg. axis labels, color, line style, etc).

You can use the commands Create and Save from the LibraryTools package to create a new .mla (Maple Library Archive) file and store your procedures or modules.

You can then make the contents of that .mla file available to any new session by augmenting libname. with the location of that .mla file. (Don't put it inside Maple's installation directory; that's a poor choice.)

You can code that augments libname into a personal initialization file. Alternatively you could put the .mla file in a specially named toolbox folder so that libname is augmented automagically. (Ask if you want details on doing that. Or see chapter 11 or section 11.4 of the Programming Guide.) If you do either of those then you don't need to explicitly adjust libname in each session/worksheet.

See the attached worksheet for reusable procedure(s).

atomic_subsup.mw

Three procedures are included.

The first is simple, but inflexible wrt italics (mi vs mo), and doesnt typeset sub/superscripts. (It's close to dharr's procedure.)

The second accomodates those issues by typesetting both sub/superscript.

The third is more general. It turns most any expression into a so-called atomic identifier (ie. name), via TypeMK. The effect is similar to what the right-click menu does, but programmatic.

Don't use 0.5 as an exponent if you could use 1/2 instead. The former can introduce roundoff issues when manipulating the expression.

Here is something (in Maple 2015 as you used), first solving for x and then applying sin.

restart;
kernelopts(version);

    Maple 2015.2, X86 64 LINUX, Dec 20 2015, Build ID 1097895

expr := cos(2*x)-sin(x)*(sin(x)^2+1)^(1/2)
        +cos(x)^2*sin(x)/(sin(x)^2+1)^(1/2):

convert([solve(expr)],
        compose, radical, arcsin);

        [       /1   (1/2)\         /1   (1/2)\      ]
        [ arcsin|- 12     |, -arcsin|- 12     | + Pi ]
        [       \6        /         \6        /      ]

map(simplify@sin, %);

             [ 1  (1/2)  1  (1/2) ]
             [ - 3     , - 3      ]
             [ 3         3        ]

simpl_sin_isolate.mw

I don't know why I didn't notice this shorter form earlier:

map(sin, [solve(expr)]);

               1/2   1/2
              3     3
             [----, ----]
               3     3

As Tom showed, that can be done even terser as,

sin~([solve(expr)]);

@MapleEnthusiast It is not very surprising that the first 9 digits of pairwaise entries (in each of the two columns) match.

If you want additional digits that illustrate that the two rows are not actually the same, then you may increase the working precision by assigning a value (higher than 15, say) to Digits.

matinv_bad_cond.mw

 

If you change this setting then the entries of a Vector with dimension less than or equal to 20 will get printed explicitly.

   interface(rtablesize=20):

You can adjust as needed.

Often people put something like that at the start of the Worksheet/Document. If you do that then you should put it in a seperate Execution Group or Document Block than any restart which precedes it.

One direct way to plot the Vector is with the command plots:-listplot.

You could try applying the trunc command to all the entries, eg. using the map command.

For example,

   map(trunc, data);

If data contains things for which trunc doesn't apply then you could alternatively use subsindets, but it can get trickier if data is a Vector/Matrix/Array that has datatype=float[8]. For example,
  data:=Vector[row]([15.0,25.0], datatype=float[8]):        
  subsindets(rtable(data,datatype=anything), float, trunc);

 

Your pf is a table. Two ways that you can extract its entries are using the entries or seq commands.

For example,

restart;
pf:='pf':
for j from 1 to 20 do 
pf[j]:=plot(x^j, x = 0..1);
end do:
plots:-display(entries(pf,nolist));

restart;
N:=20:
pf:='pf':
for j from 1 to N do 
pf[j]:=plot(x^j, x = 0..1);
end do:
plots:-display(seq(pf[j],j=1..N));

There are several other ways to accomplish such goals, but you have not specified enough details of the requirements to distinguish properly amongst them.

The ImageTools:-PlotHistogram command allows for a line or a point plot.

You can do a similar thing, with bars, using the Statistics:-Histogram command.

PlotHistogram.mw

Here are two examples, for N=16 and N=128 buckets. These overlay the results from both commands, with a few options adjust to get the points to align with the horizontal midpoints of the bars. (See also their Help pages.)

You can experiment. I believe that you'll find that, as the number of bars gets high there are visual abberations as the sides of the bars get very close (eg. Moire, etc). That happens even with thickness=0 to make the bar's side lines thinner. That's one reason why ImageTools:-PlotHistogram shows only the midpoints (connected via lines, or as separated points) and not the actual bars.

You could also add the style=polygon option to the call to the Statistics:-Histogram command. That suppresses the inner lines between the bars, giving the effect of a solid filled region. Similarly you could pass the option filled to the ImageTools:-PlotHistogram command.

FYI, thickness=0 doesn't produce the thinnest line possible in the Maple 17 GUI. Using N=256 bins you can also try this kind of thing, where Lena is the 2D Array of your imported grayscale image.

N:=256;
P2:=Statistics:-Histogram(convert(Lena,Vector),
                          bincount=N, color="Azure",
                          frequencyscale=absolute,
                          thickness=0):
RR:=[min,max](map(x->map[2](op,1,x), [op([1,..-2],P2)])):

P1:=ImageTools:-PlotHistogram(Lena, N, range=RR[1]..RR[2],
                              thickness=0):

plots:-display(P2, P1);
P1b:=subsindets(P1,specfunc(anything,THICKNESS),u->THICKNESS(0.01)):
P2b:=subsindets(P2,specfunc(anything,THICKNESS),u->THICKNESS(0.01)):

plots:-display(P2b, P1b);

 

What version of Maple, and what platform Operating System, are you using.

With Maple 2020.1 on Linux I get them different font specifics if not preceded immediately by a newline character (or possibly another special symbol?).

Omega_printf.mw

By the way, I used "Ω" instead of your "#937".

The following seems to work in Maple 2019.2, if the conversion to exp is ok.

simplify(int(factor(expand(convert(v, exp))), x));

Help_1_ac_2019.mw

Are you trying to upload and use a MapleCloud application document with embedded components and code behind them, which (via libname) directly and automatically utilizes some of user-defined procedures/packages stored within an .mla file? That is how your Question reads, to me.

A usual way to do such, in a modest scale, would be to have the user-defined code be in the Startup Code of the application .mw file uploaded to the cloud site. (A similar idea is to use a Code Edit Region marked as auto-execute.) If the amount of user-defined code is large and unwieldy, or if you only have someone else's .mla file but not the source code text, then this idea can become problematic.

It might be possible to utilize a .maple workbook rather than a .mw worksheet/document, and have the user-defined procedures be stored in the workbook. But I am not sure whether this is practical, in terms of automated usability as the application running as a single standalone entry point on the MapleCloud.

[edit] It is possible to upload a .mla file inside a cloud package, which the end-user can download or install locally. That would allow them to run your application locally in Maple or the MaplePlayer on the local machine, and have it pick up the .mla's contents. But this does not provide a way for the end-user to utilize the application on the MapleCloud site itself and have that pick up and use the .mla's contents. 

If you haven't programmatically removed components via the "replaceable content" mechanism for a Task region then it's also a rather weird and unusualy thing to to -- in that case likely indicating inadequate bookkeeping during creation of components.

Here is one way, using the idea (which I suspect is correct) that all Embedded Components have the visible property.

ExistsEC:=proc(EC::{name,string})
  try
    DocumentTools:-GetProperty(EC, ':-visible');
    true;
  catch "Attempted to retrieve property of unknown component":
    false;
  end try;
end proc:

ExistsEC_example.mw

Here is another, less efficient, way. It is possible to get all the string identities of components in the current Worksheet/Document, but it is not an efficient thing to do.

For example,

raw := :-Worksheet:-FromString(streamcall(INTERFACE_WORKSHEET("extract"))):
CBs := select(x->member(_XML_ElementType("EC-ComboBox"),[op(x)]),
              indets(raw,'specfunc(_XML_Element)')):
map(x->map(xxx->op(1,indets(xxx,'specfunc(_XML_AttrValue)')[-1]),
           select(xx->member(_XML_AttrName("id"),[op(xx)])
                      and indets(xx,'specfunc(_XML_AttrValue)')<>{},
                  indets(x,'specfunc(_XML_Attribute)'))), CBs);

EC_query.mw

You could then programmatically test for membership in that set of all existing components of the given kind.

First 93 94 95 96 97 98 99 Last Page 95 of 336