acer

32385 Reputation

29 Badges

19 years, 343 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Try this edited version of the file. It was missing several closing Section tags and the closing Worksheet tag.

Alle_opgaver_fixed.mw

acer

There are several syntax errors with your posted code, and your colorfunc's return values don't seem (to me) to fit a documented format. So it's hard to see what your after.

Your construction of p and g could be done more simply using plots:-densityplot, I think. And that command might be able to serve for your second part too, I suspect.

Let me know if this is on the right tack:

restart;

F := proc(x,y)
  local ans;
  #ans := evalf(argument(f(x+I*y))/2/Pi);
  ans := Re(f(x+I*y));
  if ans > evalf(2*Pi) then
    return 0.0;
  else
    return evalf(ans/2/Pi);
  end if;
end proc:

f := tan;

P2 := plots:-densityplot(F, -5..5, -5..5, colorstyle=HUE,
                       style=surface, axes=none, restricttoranges):

H:=plottools:-transform((u,v)->[sech(u)*cos(v),
                                sech(u)*sin(v),
                                u - tanh(u)]):

H(P2);

acer

The procedure SetBackground below changes the pixels that are "dark enough" (eg, black).

The command ImageTools:-Write can be used to write images (as created and understoof by ImagesTools commands) to files.

The code below is 1-D plaintext Maple Notation. It may not paste well directly as 2D Input. (See also the attached worksheet.) The images below look better in Maple. The export to .bmp produces a much better result, also using ImageTools:-Write, but I can't upload such files directly to this site.

restart;
Logistic := IterativeMaps:-Bifurcation([x], [r*x*(1-x)], [.5], 2.5, 4,
                        height=300, width=300):
ImageTools:-ColouringProcedures:-HueToRGB(Logistic):
ImageTools:-Embed(Logistic);
#ImageTools:-Write(cat(kernelopts(homedir),"/mapleprimes/im1.jpg"),
#                  Logistic):

SetBackground:=proc(A::Array, C::string)
  local i,p,T;
  uses ImageTools;
  if not type(A,'Array(:-datatype=float[8])') then
    error "expecting an Image for the first argument";
  end if;
  if nops([op(2,A)])<>3 then
    error "expecting a color Image with exactly three layers";
  end if;
  p:=[ColorTools:-Color(C)[]];
  for i from 1 to 3 do
    T[i]:=Threshold(FitIntensity(ToGrayscale(A)),0.001,
                    method=both,low=p[i],high=0.0);
    T[i]:=T[i]+GetLayer(A,i);
  end do;
  CombineLayers(T[1],T[2],T[3]);
end proc:

new1 := SetBackground(Logistic, "Teal"):
ImageTools:-Embed(new1);
#ImageTools:-Write(cat(kernelopts(homedir),"/mapleprimes/im2.jpg"),
#                  new1):

new2 := SetBackground(Logistic, "Gray"):
ImageTools:-Embed(new2);
#ImageTools:-Write(cat(kernelopts(homedir),"/mapleprimes/im3.jpg"),
#                  new2):

SetBack.mw

acer

Another possibility that works nicely here is specification of the particular contours as a list of numeric values. Eg,

plots:-contourplot( -(1/2)*y^2-(1/2)*x^2-(1-.3)/sqrt((x+.3)^2+y^2)
                    +((-1)*.3)/sqrt((x-1+.3)^2+y^2),
                    x=-2.25..2.25, y=-2.25..2.25, axes=boxed,
                    contours=[seq(-2.5..-1.3,0.1)], grid=[80,80],
                    coloring=["Niagara Azure","Orange"] );

acer

If you intend on pasting it somewhere else as plaintext then you should consider also setting interface(prettyprint=1). That will allow you to retain the formatting (multiple lines of text, with indenting). If you cut and paste the 2D Output of the printed procedure body then it may get pasted in elsewhere as one single long line.

interface(prettyprint=3): # the Standard GUI default
interface(verboseproc=1): # the default

print(Plot:-PointPlot); # displays only the elided body

interface(verboseproc=3): # allow the full body
kernelopts(opaquemodules=false); # printing of module locals

print(Plot:-PointPlot:-ModuleApply);

interface(prettyprint=1): # formatted plaintext printing

print(Plot:-PointPlot:-ModuleApply);

acer

On some machines Maple's Standard GUI has trouble with the rendering of spacecurves unless the linestyle option is specified. Does the following work for you?

restart;
with(DEtools):

DEplot3d({diff(y(x), x) = y(x)-z(x), diff(z(x), x) = z(x)-2*y(x)},
         {y(x), z(x)}, x = 0 .. 3, [[y(0) = 1.638, z(0) = 2.31]],
         y = 0 .. 2, z = -4 .. 4, scene = [x, z(x), y(x)],
         linecolor = COLOR(HUE, .5), linestyle=solid);

acer

If you open the Cloud palette in Maple itself (left panel), and log in to the Cloud from that, then you should be able to right-click on its entry in the private group and get a popup menu with a "delete" choice.

acer


 

restart;

ee := u*(BesselJ(0,u)^2 + BesselJ(1,u)^2) = 2*BesselJ(0,u)*BesselJ(1,u);

u*(BesselJ(0, u)^2+BesselJ(1, u)^2) = 2*BesselJ(0, u)*BesselJ(1, u)

Digits:=15:

fsolve( ee, u=1-3*I .. 15+3*I, complex );
evalf[30](eval( (rhs-lhs)(ee), u=% ));

4.46629854858362-1.46747037233377*I

-0.267718207452668e-14-0.3165012479938534e-14*I

sols := RootFinding:-Analytic( (rhs-lhs)(ee), u=-15-3*I .. 15+3*I );

0.6e-9, -0.4e-7, 0.2e-7+0.4e-7*I, -4.46629854858362-1.46747037233378*I, -4.46629854858362+1.46747037233378*I, -7.69410395105610-1.72697153718856*I, -10.8745744883790-1.89494334622134*I, -7.69410395105610+1.72697153718856*I, -10.8745744883790+1.89494334622134*I, -14.0388913115431-2.02006279566190*I, -14.0388913115431+2.02006279566190*I, 7.69410395105610-1.72697153718856*I, 10.8745744883790-1.89494334622134*I, 7.69410395105610+1.72697153718856*I, 10.8745744883790+1.89494334622134*I, 14.0388913115431-2.02006279566190*I, 14.0388913115431+2.02006279566190*I, 4.46629854858362-1.46747037233378*I, 4.46629854858362+1.46747037233378*I

seq( evalf[30]((rhs-lhs)(ee)), u=[sols] );

-0.27000000000e-28, 0.80000000000000e-23, 0.110000000000000e-22+0.20000000000000e-23*I, -0.916640078696539e-14-0.2081286559231727e-14*I, -0.916640078696539e-14+0.2081286559231727e-14*I, -0.193035011464111e-14-0.272336139113582543e-13*I, 0.498664204472203e-14-0.104441579826453566e-13*I, -0.193035011464111e-14+0.272336139113582543e-13*I, 0.498664204472203e-14+0.104441579826453566e-13*I, 0.1435733768169201e-13+0.298565617091312014e-13*I, 0.1435733768169201e-13-0.298565617091312014e-13*I, 0.193035011464111e-14-0.272336139113582543e-13*I, -0.498664204472203e-14-0.104441579826453566e-13*I, 0.193035011464111e-14+0.272336139113582543e-13*I, -0.498664204472203e-14+0.104441579826453566e-13*I, -0.1435733768169201e-13+0.298565617091312014e-13*I, -0.1435733768169201e-13-0.298565617091312014e-13*I, 0.916640078696539e-14-0.2081286559231727e-14*I, 0.916640078696539e-14+0.2081286559231727e-14*I

plots:-display(
  plots:-pointplot3d(map([Re,Im,0],[sols]),color=red,symbolsize=20),
  plots:-complexplot3d( (rhs-lhs)(ee), u=-15-3*I .. 15+3*I, grid=[41,41], view=0..1 )
);

 


 

Download besselthing.mw

acer

This sounds like a scenario for which one (or more) module based packages are suitable, saved to a .mla archive that is automatically in your libname.

By having the commands inside a package (named, say, MiscUtils or what have you) then the individual command names are still otherwise available to you unless you load the package(s) using the with command. But it is still easy to get them in any session, without having to remember some long, host-specific, source location string. That's a big advantage of modules, they give you control over the global name space.

I strongly suggest using LibraryTools:-Create and LibraryTools:-Save instead of savelib (especially since casual use of the latter without a specified archive can result in accidental littering of currentdir with errant .m files).

You only have to write the code which rebuilds the .mla archive once. Then you can re-use it each time you edit any of the sources.

If you place the .mla archive inside the file location (string) that the following command returns then its contents will be available in any wholly new session. Maple knows to add this to libname upon (completely new) launch. I use the name MiscUtils here just as an example.

cat(kernelopts(':-homedir'),"/maple/toolbox/MiscUtils/lib");

You can also make the location be version-specific. Eg,

cat(kernelopts(':-homedir'),"/maple/toolbox/2016/MiscUtils/lib");

Note that the forward slash "/" is understood across platforms (Linux, Windows, OSX), by Maple commands in the LibraryTools and FileTools packages.

So, a piece of re-usable build-code can form that string, concatenate with the name of (one or more) .mla filenames, and be used by LibraryTools commands.

You can also place .hdb or .help archives (Help databases) in the same locations.

Note that the GUI will also need a complete relaunch in order to pick up any Help files thus placed, after the first time the folder is created. But you don't have to mess around with manually adding any location to libname, or fiddling with in any initialization file.

So, you can get automatic access in new sessions by saving your procedues to a toolbox location, and by using package(s) your global name space is not cluttered (unless you choose to load a package).

acer

1) Upload the worksheet to a public location in the Maple Cloud (you can even do this straight from Maple's Standard GUI). See maplecloud.maplesoft.com .  Or you could set up a private group on that cloud, and allow access to only select members. Even using a web-browser like Chrome allows mouse-pointer rotation of 3D plots rendered in such pages.

2) They could install the MaplePlayer, which is free. It displays .mw and even allows interaction with any Embedded Components you have placed in the sheet (which you can load up with procedures, behind the scenes). This too talks to the Maple Cloud, so you could also upload/download from there. https://www.maplesoft.com/products/maple/Mapleplayer/

acer

The (unquoted) call to Quantile(X,z) returns a generic RootOf. And floating-point approximation of that (using evalf as plot will do) need not always converge to the "same" root (branch). The explanation by vv is very good.


 

restart;

with(Statistics):
U := Distribution(PDF=(t->piecewise(t<-5,0,t< 5,-(1/2000)*t^4+(9/1000)*t^2+7/80, 0))):
X := RandomVariable(U):

plot('Quantile'(X, z, numeric), z = 0 .. 1, adaptive=false, numpoints=30,
                size=[500,200], gridlines=false);

U:=Quantile(X, z);

RootOf(_Z^5-30*_Z^3-875*_Z+10000*z-5000)

[allvalues(U)];

[RootOf(_Z^5-30*_Z^3-875*_Z+10000*z-5000, index = 1), RootOf(_Z^5-30*_Z^3-875*_Z+10000*z-5000, index = 2), RootOf(_Z^5-30*_Z^3-875*_Z+10000*z-5000, index = 3), RootOf(_Z^5-30*_Z^3-875*_Z+10000*z-5000, index = 4), RootOf(_Z^5-30*_Z^3-875*_Z+10000*z-5000, index = 5)]

evalf( eval(%,z=0.2) );

[HFloat(7.337832818846145), HFloat(0.9188750749042348)+HFloat(4.672740913616434)*I, HFloat(-2.849847210142789), HFloat(-6.325735758511826), HFloat(0.9188750749042348)-HFloat(4.672740913616434)*I]

plot([allvalues(U)][1..4],z=0..1, gridlines=false);

 


 

Download dist1.mw

acer

Do you actually have a Matrix with floats? (The Matrix you mentioned will have exact integer entries.) Do you understand that Maple may have to do a lot more work to get an exact result. At the very least make sure that the entries of the Matrix are floats.

It's not sensible to compare with Matlab unless you're using floats and working with hardware floats (because that's all Matlab alone can do). For comparison with Matlab use Matrices/Vectors with datatype=float[8] and keep Digits<=15 and ensure that the environment variable UseHardwareFloats is not set to false.

Your suppositions about the computational complexity are misguided. That's not what big-O (or little-o) notation means.

acer

Do you consider the following as mathematically acceptable? (Note that everything below is in 1D Maple Notation.)

> Physics:-diff( diff(a(t), t)*a(t), a(t) ):

> lprint(%);
diff(a(t),t)
If so, then are you looking for something like this?
> restart;

> expr2 := a(t)*b(t)+2*(diff(a(t), t))*(diff(b(t), t))*c(t):

> S2 := frontend(int, [expr2,a(t)]):

> lprint(S2);
2*diff(a(t),t)*diff(b(t),t)*c(t)*a(t)+1/2*a(t)^2*b(t)

> Physics:-diff( S2, a(t) ):

> lprint(%);
a(t)*b(t)+2*diff(a(t),t)*diff(b(t),t)*c(t)

> expr2 - Physics:-diff( S2, a(t) );

                                    0
Alternatively, by freezing instead of using `frontend`,
> AltS2 := thaw( int( subs([diff(a(t),t)=freeze(diff(a(t),t)),
                            a(t)=freeze(a(t))],
                           expr2),
                      freeze(a(t)) ) ):

> lprint(AltS2);
2*diff(a(t),t)*diff(b(t),t)*c(t)*a(t)+1/2*a(t)^2*b(t)

> expr2 - Physics:-diff(AltS2, a(t));

                                     0

acer

If you just want to get something printed then here is a stab at it, though it relies on using a function call (and so itn't automatic, like PDEtools:-declare offers). Perhaps there is something easier, with only PDEtools or Physics. (It's not terribly sophisticated. As written it doesn't allow you to change from `U` to something else, on the fly. But if printing with a function call is adequate for your purpose then you could adjust it.)


 

restart;

eqn := diff(f(x),x) = diff(U(g(x)),x);

diff(f(x), x) = (D(U))(g(x))*(diff(g(x), x))

neweqn := diff(P(z),z) = diff(U(w(z)),z);

diff(P(z), z) = (D(U))(w(z))*(diff(w(z), z))

PDEtools:-declare(':-quiet'):

Print:=module()
       export SetVar;
       local ModuleApply, var;
       var:=':-x';
       ModuleApply:=proc(ee)
         print(subsindets(ee, specfunc(anyfunc(identical(var)),D(U)),
                          u->diff(U(op(0,op(u))),op(0,op(u))), ee));
         NULL;
       end proc:
       SetVar:=proc(v::symbol) var:=v; NULL: end proc;
end module:

Print(eqn);

diff(f(x), x) = (diff(U(g), g))*(diff(g(x), x))

Print:-SetVar(z);

Print(neweqn);

diff(P(z), z) = (diff(U(w), w))*(diff(w(z), z))

 


 

Download pardiff.mw

acer

restart;

# Method 1, handling just a pair of inequalities.
S := {t<=2.3, .01 < t}:
P := And( op(S) ):
RR := convert( P, RealRange );
`..`( op(subsindets(op(2,RR),specfunc(Open),op)) );

# Method 2, allowing `solve` to do it.
SR := solve( P, t );
`..`( op(subsindets(SR,specfunc(Open),op)) );

# So here we go... method 1.
func := proc(s::set({`<`,`<=`}))
  `..`( op(subsindets(op(2,convert( And( op(s) ), RealRange )),specfunc(Open),op)) );
end proc:

sols := [{theta <= Pi-arccos(-3/4+(1/4)*sqrt(13+16*sqrt(2))),
          arccos(3/4) < theta},

         {arccos(-3/4+(1/4)*sqrt(13+16*sqrt(2)))+Pi <= theta,
          theta < 2*Pi-arccos(3/4)},

         {theta <= 3*Pi-arccos(-3/4+(1/4)*sqrt(13+16*sqrt(2))),
          2*Pi+arccos(3/4) < theta}]:

map( func, sols );

evalf(%);

# A slightly harder case, which method 2 handles a bit better.
S2 := {t<=2.3, .01<t, t<1.8}:
SR2 := solve( And( op(S2) ), t );
`..`( op(subsindets(SR2,specfunc(Open),op)) );

# And so somewhat more robust...
func2 := proc(s::set({`<`,`<=`}))
  local var := op(1, indets(s,name) minus {constants});
  `..`( op(subsindets(solve( And( op(s) ), var),specfunc(Open),op)) );
end proc:

map( func2, sols );

evalf(%);

acer

First 203 204 205 206 207 208 209 Last Page 205 of 336