acer

32303 Reputation

29 Badges

19 years, 309 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Did you call fclose or fflush (or restart)?

If not, then buffered results may not yet be flushed to the file.

Another possibility is that currentdir() is not what you expecting. That's a Maple command.

You could use,

    1+ilog2(n)

Eg,

    1+ilog2(22);

              5

For base 3 you might use the following,

   nops(convert(n,base,3));

and you might be able to use the following for positive integers,

   1+trunc(log[3](Float(n,0)))

Test, to make sure I haven't made mistakes.

For some reason the Sliders don't appear when the worksheet is inlined in this discussion forum. But they're there in the .mw file. You need to execute the definition of F, for it to work.

You should easily be able to add a textplot at the end-point of the 4th arrow.

restart;

with(plots):

F := proc(a,b,c)
  local w:=5, arropts := (':-width'=w,':-head_length'=20);
  uses plots, ColorTools;
  display(arrow(<0,0,0>,<255.0,0.0,0.0>,':-color'="red",arropts),
          arrow(<0,0,0>,<0.0,255.0,0.0>,':-color'="green",arropts),
          arrow(<0,0,0>,<0.0,0.0,255.0>,':-color'="blue",arropts),
          arrow(<0,0,0>,<a,b,c>,':-color'=Color([a,b,c]),arropts),
          ':-view'=[-5..255+w,-10..255+w,-w..255+w],':-axes=none',
          map(L->plottools:-line(L[],':-color'="808080",':-thickness'=3,
                                 ':-linestyle'=':-dot'),
              [[[0,255,255],[0,0,255]],[[0,255,255],[0,255,0]],
               [[255,255,0],[255,0,0]],[[255,255,0],[0,255,0]],
               [[255,0,255],[0,0,255]],[[255,0,255],[255,0,0]],
               [[255,255,255],[255,0,255]],[[255,255,255],[255,255,0]],
               [[255,255,255],[0,255,255]]]),
          ':-orientation'=[-70,75,0], ':-size'=[700,700]);
end proc:

Explore(F(red,green,blue),
        ':-parameters'=[[red=0..255],
                    [green=0..255],
                    [blue=0..255]],
        ':-initialvalues'=[red=217,green=43,blue=143],
        ':-placement'=':-left', width=700);

 

 

 

 

red

 

 

 

 

green

 

 

 

 

blue

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Download expl_rgb.mw

And here is a version that creates it in a new Tab in the GUI (new worksheet). This should subsequently run-standalone, as the definition of procedure F gets put into the Startup Region of that sheet.

Download expl_rgb_mkalone.mw

You might call Optimization:-Maximize on a range restricted to close to a peak. This can be performed on a simplification of abs(q) that is real-valued with less imaginary roundoff noise (artefact).

For example, using Maple 18.02,

restart

kernelopts(version);

`Maple 18.02, X86 64 LINUX, Oct 20 2014, Build ID 991181`

with(plots):

q := -(-518445+187776*x^4+4096*x^6-48932352*t^2+30670848*t^6-3939840*x^2-13559808*t^4-84934656*t^8-2048*sqrt(2)*x^7+14352384*t^4*x^2+3801088*t^3*x^3+638976*t^2*x^4+49152*t*x^5-14024704*t^4*x^4-589824*t^2*x^6-65536*t*x^7+29097984*t^5*x-113246208*t^7*x-40894464*t^5*x^3-84934656*t^6*x^2-15759360*t*x-3407872*t^3*x^5-85843968*sqrt(2)*t^5-2047860*sqrt(2)*x+4126464*sqrt(2)*t^3+(294912*I)*t^5+(8702976*I)*t^3-(1440*I)*t-4095720*sqrt(2)*t-1064960*sqrt(2)*t^3*x^4-7667712*sqrt(2)*t^5*x^2-221184*sqrt(2)*t^2*x^5-10616832*sqrt(2)*t^6*x-3506176*sqrt(2)*t^4*x^3-28672*sqrt(2)*t*x^6+4700160*sqrt(2)*t^2*x^3+(84934656*I)*t^6*x-(245760*I)*t^2*x^3+3917952*sqrt(2)*t^2*x-1658880*sqrt(2)*t^3*x^2-53096448*sqrt(2)*t^4*x+1391040*sqrt(2)*t*x^2+1866240*sqrt(2)*t*x^4-(835584*I)*t^3*x^2-(1376256*I)*t^4*x+(53035008*I)*sqrt(2)*t^4+(49152*I)*t*x^6+(589824*I)*t^2*x^5+(17301504*I)*t^4*x^3+(4128768*I)*t^3*x^4+(7077888*I)*sqrt(2)*t^6+(541440*I)*sqrt(2)*t^2+(49545216*I)*t^5*x^2+(2193408*I)*sqrt(2)*t*x^3+(44064768*I)*sqrt(2)*t^3*x+(13160448*I)*sqrt(2)*t^2*x^2+(4325376*I)*sqrt(2)*t^4*x^2+(1376256*I)*sqrt(2)*t^3*x^3+(270720*I)*sqrt(2)*t*x+(8257536*I)*sqrt(2)*t^5*x+1502208*t*x^3+211968*t^2*x^2-11169792*t^3*x+186624*sqrt(2)*x^5+231840*sqrt(2)*x^3-7077888*sqrt(2)*t^7-4096*x^8)*exp(I*(3*t-x))/(-518409+91968*x^4-512*x^6-145440*t^2-884736*t^6-34776*x^2-7449600*t^4-1024*sqrt(2)*x^7-516096*t^4*x^2-180224*t^3*x^3-43008*t^2*x^4-6144*t*x^5-884736*t^5*x-139104*t*x-307200*sqrt(2)*t^5-1045458*sqrt(2)*x-950400*sqrt(2)*t^3-2090916*sqrt(2)*t+(7077888*I)*t^7-(1105920*I)*sqrt(2)*t^2*x^2-(184320*I)*sqrt(2)*t*x^3+(69120*I)*sqrt(2)*t*x+(1728*I)*t*x^2+(12288*I)*t^2*x^3+(6912*I)*t^2*x-(245760*I)*t^4*x-(36864*I)*t^3*x^2+(7372800*I)*sqrt(2)*t^4+(1536*I)*t*x^4+(49152*I)*t^2*x^5+(4096*I)*t*x^6+(344064*I)*t^3*x^4+(4128768*I)*t^5*x^2+(1441792*I)*t^4*x^3+(7077888*I)*t^6*x+(138240*I)*sqrt(2)*t^2+(614400*I)*t^5+(57600*I)*t^3+(4147272*I)*t-532480*sqrt(2)*t^3*x^4-3833856*sqrt(2)*t^5*x^2-110592*sqrt(2)*t^2*x^5-5308416*sqrt(2)*t^6*x-1753088*sqrt(2)*t^4*x^3-14336*sqrt(2)*t*x^6+3072*sqrt(2)*t^2*x^3-294336*sqrt(2)*t^2*x+79872*sqrt(2)*t^3*x^2-30720*sqrt(2)*t^4*x+135648*sqrt(2)*t*x^2-3840*sqrt(2)*t*x^4+(2211840*I)*sqrt(2)*t^3*x+735744*t*x^3+4608*t^2*x^2-5867520*t^3*x-384*sqrt(2)*x^5+22608*sqrt(2)*x^3-3538944*sqrt(2)*t^7):

new := `assuming`([simplify(abs(q), size)], [x > -5, x < 5, t > -5, t < 5]):

plot3d(new, x = -5 .. 5, t = -5 .. 5, numpoints = 5000, axes = frame, style = surface, labels = ['x', 't', ""], labelfont = [TIMES, ITALIC, 16], axesfont = [TIMES, ROMAN, 14], shading = ZHUE, orientation = [50, 55, 0]);

sol1 := Optimization:-Maximize(new, t = -.5 .. 1.5, x = -5 .. -2);

[178.124646707148315, [t = HFloat(0.9557075158427223), x = HFloat(-3.5487225916120098)]]

[125.493296995342149, [t = HFloat(-0.9563856851285822), x = HFloat(0.2895352694643224)]]

[29.4557218848098721, [t = HFloat(1.7054438218049695e-8), x = HFloat(3.1825552777668866)]]

plots:-display(plot3d(new, x = -5 .. 5, t = -1.5 .. 1.5, grid = [201, 201], axes = frame, style = surface, labels = ['x', 't', ""], labelfont = [TIMES, ITALIC, 16], axesfont = [TIMES, ROMAN, 14], shading = ZHUE), plots:-pointplot3d([eval([x, t, new], sol1[2]), eval([x, t, new], sol2[2]), eval([x, t, new], sol3[2])], symbolsize = 10, symbol = solidcircle, color = black), orientation = [50, 55, 0]);

 

Download p3dopt.mw

Here is one way, using Maple 17.

In modern Maple there are more ways to get similar effects.

I could have used just plots:-surfdata to get the surface. But coloring that flexibly would be more complicated. And there are a few irritations with using plots:-listdensityplot here.

So instead I construct an interpolating procedure F, which I use for the various pieces.

restart;

kernelopts(version);

`Maple 17.02, X86 64 LINUX, Sep 5 2013, Build ID 872941`

(1)

with(plots): with(plottools):

x:=[0.1, 0.2, 0.3, 0.4, 0.5, 0.1, 0.2, 0.3, 0.4, 0.5,
    0.1, 0.2, 0.3, 0.4, 0.5,0.1, 0.2, 0.3, 0.4, 0.5,
    0.1, 0.2, 0.3, 0.4, 0.5]:

y:=[0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.2,
    0.3, 0.3, 0.3, 0.3, 0.3, 0.4, 0.4, 0.4, 0.4, 0.4,
    0.5,0.5,0.5,0.5,0.5]:

z:=[1.971284960, 1.642401616, 1.372353338,1.153620572,0.9762759982,

    1.675502483, 1.411976881, 1.190627373,1.007730234,0.8570007139,

    1.397140245, 1.184230644, 1.003688984,0.852696223,0.7268039317,

    1.144791107, 0.9725020383,0.8257592921,0.7020549659,0.5979974836,                                                        0.9208492326, 0.7816302394, 0.6627749172,0.5620029444,0.4766238930]:

M := Matrix(5,5,z)^%T:

xydat := [<[0.1,0.2,0.3,0.4,0.5]>,<[0.1,0.2,0.3,0.4,0.5]>]:

F := proc(a,b) option remember;
   if not [a,b]::list(numeric) then return 'procname'(args); end if;
   CurveFitting:-ArrayInterpolation(xydat, M,
                                    Array(1..1, 1..1, 1..2,
                                          [[[a,b]]]))[1,1];
end proc:

P3 := plot3d(F(a,b), a=0.1 .. 0.5, b=0.1 .. 0.5,
             color=[F(a,b)/(2-0.5)-0.333, F(a,b)/(2-0.5)-0.333, 1]):

P4 := contourplot(F(a,b), a=0.1 .. 0.5, b=0.1 .. 0.5,
                  color="DarkGreen",contours=5):

display(P3,
        transform((a,b,c)->[a,b,1e-2])(P4),
        plot3d(0, a=0.1 .. 0.5, b=0.1 .. 0.5,
               color="yellow",style=surface),
        labels=["x","y","z"], orientation=[30,75,0]);

 

 

 

Download MAXR_surfcontdat.mw

The index option is not available to the max command in Maple 17. You could see that by reading its Help page in your version.

As a simple (but less efficient) alternative, you could try using,

    ind[k] := ListTools:-Search(max(abs(Y[k])), Y[k]);

instead of your,

   ind[k] := max[index](abs(Y[k]));

Note that there are other problems with the code. You assign to lowercase tol but then try and compare something against all-caps TOL. which has no assigned numeric value. The code tries to use yp, but that is unassigned. And so on.

Here is one way.

The Table looks nicer in actual Maple.

You could suppress the display of the Matrix (ending the line containing the statement that creates it with a full colon), if you're also going to Tabulate it.

The plot was just for fun. (You could also make a dual-axis plot with, say, height on the left vertical axis and velocity on the right vertical axis.) The plot could also be animated.

restart;
with(DocumentTools):

h := -4.9*t^2 + 50*t + 960;

-4.9*t^2+50*t+960

v := diff(h, t);

-9.8*t+50

a := diff(v, t);

-9.8

T := Vector([seq(t, t=0..21, 4.0)]):

H := map(tt->eval(h,t=tt), T):

V := map(tt->eval(v,t=tt), T):

A := map(tt->eval(a,t=tt), T):

data := <<"time"|"height"|"velocity"|"acceleration">,
        <T|H|V|A>>;

Matrix(7, 4, {(1, 1) = "time", (1, 2) = "height", (1, 3) = "velocity", (1, 4) = "acceleration", (2, 1) = 0, (2, 2) = 960., (2, 3) = 50., (2, 4) = -9.8, (3, 1) = 4.0, (3, 2) = 1081.600, (3, 3) = 10.80, (3, 4) = -9.8, (4, 1) = 8.0, (4, 2) = 1046.400, (4, 3) = -28.40, (4, 4) = -9.8, (5, 1) = 12.0, (5, 2) = 854.400, (5, 3) = -67.60, (5, 4) = -9.8, (6, 1) = 16.0, (6, 2) = 505.600, (6, 3) = -106.80, (6, 4) = -9.8, (7, 1) = 20.0, (7, 2) = 0., (7, 3) = -146.00, (7, 4) = -9.8})

Tabulate(data, widthmode=pixels, width=500,
         fillcolor=((val,i,j)->`if`(i=1,"Tan","White"))):

 

time

height

velocity

acceleration

0

960.

50.

-9.8

4.0

1081.600

10.80

-9.8

8.0

1046.400

-28.40

-9.8

12.0

854.400

-67.60

-9.8

16.0

505.600

-106.80

-9.8

20.0

0.

-146.00

-9.8

 

 

plots:-display( plot(h, t=0..20, size=[500,200]),
                plot(<T|H>, style=point, color=blue,
                     symbol=solidcircle, symbolsize=15) );

 

thva.mw

You can store multiple procedures (as well as modules that export procedures) in a special kind of file called a Maple Library Archive. Such a file has .mla as its filename extension.

I suggest that you start by reading the Help pages for the LibraryTools package's documentation.

You could start by calling LibraryTools:-Create to make a .mla file.

Then you could call LibraryTools:-Save to store your various procedures within it. I strongly suggest always using the calling sequence in which you supply the location of the file explicitly (ie. without using savelibname).

Once you have stored a procedure within the personal .mla file you can use it from any other worksheet/document/session as long a its location is one of the items in the path assigned to libname.

For example, suppose that you'd stored procedure MyProc inside a .mla file at location,
    C:/Users/Acer/mystuff/MyArchive.mla
In that case you could augment libname with the Maple command,
   libname := C:/Users/Acer/mystuff/MyArchive.mla, libname;
One way to make that libname adjustment automatic is to put that command inside a personal initialization file.

An alternate way to make that libname adjustment happen automatically upon launch/restart is to use a special kind of location. For example, if my MS-Windows username were "Acer" then the following is such a special location,
   C:/Users/Acer/maple/MyPackage/lib/MyPackage.mla
where "MyPackage" could be some name of my choosing. I'd use this when calling the LibraryTools commands mentioned. Then my stored procedures could be used immediately and directly in any new Maple session.

You might also consider encapsulating a collection of related procedures inside a package, which is a special kind of module. You can read some documentation on this in Chapter 11 of the Programming Guide. That chapter also has a subsection on using LibraryTools, like I described above.

The URLs I give are links to the on-line version of the documentation, usually corresponding to the current version of Maple. You can also access these Help pages -- offline and specific to your version -- from within Maple itself.

In the example you mention, the solving was invoked by using the context-sensitive menu of operations in the left panel of the GUI.

That very fact is stated right there at the bottom of your example.

I suggest you read the corresponding Help pages (documentation). I've used a URL link above so that you can get to the on-line version of a relevent Help page.

The following example will produce a list of lists.

Each inner list has three components, for x,y, and z.

de := plot3d(y*sin(x), x = 0 .. 2*Pi, y = -2 .. 2):
temp := plottools:-transform((x,y,z)->[x,y,z])(de):
convert(plottools:-getdata(temp)[3],listlist);

As Preben has shown, your Question's second integral can be done directly in Maple 2022.2, and then further simplified. But I was unable to get that symbolic integral to compute directly in Maple 2022.1, nor any version of Maple 2021.

And your response to him mentioned only Maple 2021 in the context of that example. You then mentioned both Maple 2021 and Maple 2022 for the followup Statistics example. I would guess that means you have Maple 2022, but I'm not 100% sure.

So, for fun, here's how it can also be done in Maple 2021.2 (and onwards),

restart;

kernelopts(version);

`Maple 2021.2, X86 64 LINUX, Nov 23 2021, Build ID 1576349`

g := piecewise(z/t < 1, 0, z/t < 2, 10080-60480*z/t+156240*z^2/t^2-226800*z^3/t^3+202230*z^4/t^4-113400*z^5/t^5+39060*z^6/t^6-7560*z^7/t^7+630*z^8/t^8, 0)/t;

g := piecewise(z/t < 1, 0, z/t < 2, 10080-60480*z/t+156240*z^2/t^2-226800*z^3/t^3+202230*z^4/t^4-113400*z^5/t^5+39060*z^6/t^6-7560*z^7/t^7+630*z^8/t^8, 0)/t

H:=Int(g,t=1..3):

simplify(value(IntegrationTools:-Change(H,s=z/t,s)));

-(5/4)*piecewise(z <= 1, 0, z <= 2, -63*z^8+864*z^7-5208*z^6+18144*z^5-40446*z^4+60480*z^3-62496*z^2+48384*z-19659-8064*ln(z), z < 3, 5589-8064*ln(2), z < 6, 25248-8064*ln(2)+(7/729)*z^8-(32/81)*z^7+(1736/243)*z^6-(224/3)*z^5+(1498/3)*z^4-2240*z^3+6944*z^2-16128*z-8064*ln(3)+8064*ln(z), 6 <= z, 0)

Download mmcdara_int_2021.mw

Fwiw, your original Question's second integration example can also be forced in Maple 2015.2, by converting to Heaviside, veiling those, changing variables, computing value symbolic, and then reverting to piecewise. That kludgy approach produces some undefined discontinuities at a couple of points, which I know you don't like.  mmcdara_int_2015.mw

Those techniques involving change of variables don't seem to help in older versions for your followup Statistics example, which has an integral of a product of two piecewise, one with conditions on z/t and one on just z. This gets messed up in older versions (similar to how previous versions go awry on the two original integrals, I believe) and can erroneously produce just zero.

But perhaps you do have Maple 2022.2, which gets that followup symbolic integral as well. Or perhaps you'd be satisfied with much faster numeric integrations, as I mentioned elsewhere.

1) The forward slash dates from before modules. It's presence in Library procedure names is usually just a reflection of the directories (and subdirectories) in which the source files were stored on a Unix system. That was a convenient convention for naming internal routines within, say, old table-based packages.

Mostly the forward slash doesn't give special functionality to names. One exception is the case of the extension mechanism for kernel builtins, eg.   `print/foo` as a way of naming a procedure that would be used automatically for printing unvaluated function calls foo(...).

2) The left ticks are needed to let the parser distinguish between, say, the fraction foo/bar and the name `foo/bar`. Single left-ticks (aka name quotes) allow you to have names with nonalphanumeric characters, etc.

In contrast, the colon-dash :- is a special syntax for referring to module members. If you wrap that in name quotes then the parser sees it as just a name that happens to have some special characters in it, ie. not as a module member reference.

So these cases are actually consistent. A pair of wrapped left ticks veils the special syntactic meaning of forward slash / (ie. division), just as it would veil the special syntactic meaning of colondash :- (ie. module membership).

3) A module can be "appliable", in the sense that its name can be applied directly to arguments. For example fsolve is now a module, yet you can call  fsolve(cos(x)) .  That actually invokes 

     fsolve:-ModuleApply

on the arguments.

4) The showstat command is for rendering a display of a procedure's structure and body, including line numbers. You can also call `print` on a procedure.

You can also print (or make a string from) parts of a module. See the Help for a description of the various operands of a module. 

Note that showstat was not designed for modules and it's not clear how precisely it would display such, or why it ought to.

Note that you can call,

    showstat(fsolve::ModuleApply)

if kernelopts(opaquemodules) is `false`, and that were `true` you could use :- instead of :: .

[edit] IIRC you can also call `printf` with "%P" to specify the format, and get a plaintext, indented display of a procedure  eg.

   printf("%P",
              eval(fsolve:-ModuleApply));

The last time I checked  I could not do the same in one shot for a module. (That's inconvenient for me as module bodies can exceed the line length limit if printed after converting to unbroken string. I'd rather have nicer text pretty-printing than crude backslash linebreaks.)

If you have already executed this:

with(GroupTheory): with(DocumentTools):
lis := SearchSmallGroups('order' = 10 .. 100, 'soluble'):
S := seq(DrawSubgroupLattice(SmallGroup(g), 'highlight' = CompositionSeries(SmallGroup(g))), g in lis[10 .. 20]):

then you could do something like the following,

Tabulate(Matrix(4, 3, [S])):
That shows 3 plots per row, using the full window width by default. There are options to let you control the widths, visibility of separators, etc.

You can force the issue here by using the symbolic option of simplify and combine. Or you can use an assumption.

See the Help for some description of that symbolic option, here and here.

Sometimes the solve command will produce a "simplified" form (half your goal here).

There is a large set (nonzero measure in the RxR space of m and c) where the expression sqrt(m*c)/m and sqrt(c/m) are not equal. Hence it would hardly be an improvement if those two commands treated these two forms as equivalent, by default. I'd agree that it would be an improvement if the context-menu (context-panel) offered the choice,
   combine(..., symbolic)

restart;

g := sqrt(m*c)/m;

(m*c)^(1/2)/m

combine(simplify(g)) assuming m>0;

(c/m)^(1/2)

combine(simplify(g,symbolic),symbolic);

(c/m)^(1/2)

eq := m*omega^2 = c;

m*omega^2 = c

solve({eq, m>0}, omega);
combine(%) assuming m>0;

piecewise(m <= 0, [], 0 < m, [{omega = sqrt(c)/sqrt(m)}, {omega = -sqrt(c)/sqrt(m)}])

[{omega = (c/m)^(1/2)}, {omega = -(c/m)^(1/2)}]

Download symbolic.mw

I'm not sure that I fully understand what you mean by "improve" or "best".

You could use the mathfunc type. You could restrict that to not include the elementary functions.

In such a way you could decide up front what you want to accept as "elementary". And presumably that internal list of special functions is updated if something gets added to Maple's stock.

For example, (and this could be tweaked):

restart;

K := proc(ee)
  ormap(type,op~(0,indets(ee,function))
             minus {arccos,arccosh,arccot,arccoth,arccsc,arccsch,
                    arcsec,arcsech,arcsin,arcsinh,arctan,arctanh,
                    cos,cosh,cot,coth,csc,csch,exp,ln,sec,sech,
                    sin,sinh,tan,tanh},mathfunc);
end proc:

 

expr:=(sin(x)*EllipticF(k, y)/(BesselI(z, l)*arctan(y, x)))^WhittakerW(mu, nu, z);

(sin(x)*EllipticF(k, y)/(BesselI(z, l)*arctan(y, x)))^WhittakerW(mu, nu, z)

K(expr);

true

K( sin(x) + f(x) );

false

K( sin(x) + f(x) + BesselJ(0,x) );

true

Download specf.mw

First 58 59 60 61 62 63 64 Last Page 60 of 336