acer

32348 Reputation

29 Badges

19 years, 329 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Carl Love A 2D contour plot (un-filled) can be combined with a 2D density plot of custom shading. The "2D density plot" can be constructed using plots:-densityplot or via plots:-surfdata(...,dimension=2,style=surface).

If using surfdata then the GRID data from a plot3d result can be re-used. And if you're willing to assemble the plot structure manually (or subsop) then even the very same RGB COLOR data from a plot3d(...,colorscheme=...) may be re-used I believe.

But, if the goal is only to insert the filled 2D contour plot as a lower, horizontal plane in the final, combined, 3D plot, then couldn't you just take a plot3d surface, shaded via with colorscheme, and map it down to the plane? And likewise map the 2D contours (explicit data) up to the upper surface.

Ie. Don't use style=surfacecontour for the plot3d upper surface. It's a pity that plots:-surfdata doesn't allow style=surfacecontour alongside dimension=2. I am supposing that it's nice to have the exact same x-y contour positions, as well as the same color shading.

[edited] Here are some of the ideas I was trying to convey.

restart;


# First variation: raising 2D CURVEs via plottools:-transform.
# The resulting 3D curves look a little graining against the surface.

P := plot3d(sin(x)*y^2, x=-Pi..Pi, y=-1..1,
            style=surface,
            colorscheme=["zgradient",
                         ["Red","Orange","Yellow","Green","Cyan","Blue","Magenta"]]):
P;

# 2D density plot
PLOT(op([1],P),STYLE(PATCHNOGRID));

lowerP := subsop([1,3]=Matrix(op(2,op([1,3],P)), -1.1, datatype=float[8]), P):

lowerP;

plots:-display( P, lowerP );

C2D := plots:-contourplot(sin(x)*y^2, x=-Pi..Pi, y=-1..1,
                          color=black, thickness=2):

plots:-display(
  P,
  plottools:-transform((x,y)->[x,y,sin(x)*y^2])(C2D),
  lowerP,
  plottools:-transform((x,y)->[x,y,-1.1])(C2D)
);

restart;

#
# Second variation: Using style=patchcontour on the upper surface.
# This makes the contour curves render better alongside the surface.
#

P := plots:-contourplot3d(sin(x)*y^2, x=-Pi..Pi, y=-1..1,
            contours=[-0.75,-0.5,-0.25,-0.1,0.1,0.25,0.5,0.75],
            thickness=1,
            colorscheme=["zgradient",
                         ["Red","Orange","Yellow","Green","Cyan","Blue","Magenta"]]):
P:=subsindets(P,specfunc(anything,STYLE),()->STYLE(PATCHCONTOUR));

# 2D density plot
PLOT(op([1],P),STYLE(PATCHNOGRID));

C2D := plots:-contourplot(sin(x)*y^2, x=-Pi..Pi, y=-1..1,
                          contours=op(indets(P,specfunc(anything,CONTOURS))[1]),
                          color=black, thickness=1):

plots:-display(
  PLOT(op([1],P),STYLE(PATCHNOGRID)),
  C2D
);

lowerP := subsop([1,3]=Matrix(op(2,op([1,3],P)), -1.1, datatype=float[8]), P):

lowerP;

plots:-display(
  P,
  lowerP,
  plottools:-transform((x,y)->[x,y,-1.1])(C2D)
);

#
# A third variation is possible, where the lower horizontal surface
# also has style=patchcontour. That'd be even easier, for building the
# full 3D assembly, as no explicit CURVE structures would be needed.
# But the 2D combine plot would still need explicit CURVE structures, since
# unfortunately the PATCHCONTOUR style is not accepted by the GUI for 2D. (bah!)
# I recall the a Mapleprimes member also wanted the 2D contour plot separately.
#

 

Download densityplot_from_3dsurface.mw

@Christopher2222 OK, I think I see. You are also using 2D Input mode for your example.

So, in the writeto file, the output shows in prettyprint=1 form, but the input shows as Typesetting code.

If you also want the input sent to file as 1D Maple Notation then you'll need to toggle to 1D Input mode in an Execution Group (as well as set interface(typesetting=standard) ).

I will submit a few bug reports:

  • There ought to be no need to set interface(typesetting=standard) when using writeto in the GUI. This seems a regression, now that extended is the default.
  • Using writeto in the GUI, setting interface(prettyprint=0) produces output that is wrongly wrapped in a Typesetting:-mprintslash call. And that is not avoidable even if also setting interface(typesetting=standard) .
  • It's not clear what 2D Input should produce when using writeto a file from the GUI. Personally I can imagine it as possible a useful way to debug 2D Input mode. But it's also just a barrier.
  • These subtleties aren't all documented in the Help page for writeto .

@Christopher2222 Please give an example of how it goes wrong when you writeto a file, with interface(prettyprint=1): .

For me it seems ok, in the sense that I don't see all output wrapped in calls to Typesetting exports. But if you'd care to be helpful and upload a worksheet that reproduces the issue, then please do so.

I also seemed to get ok results if I kept the Maple 2018 Standard GUI's default of interface(prettyprint=3) but toggled to interface(typesetting=standard): .

So do neither of these work for you in the Maple 2018 Standard GUI, with writeto a file?

  • interface(prettyprint=1):
    writeto(....);
    ...
    writeto(terminal):

     
  • interface(prettyprint=3):  # or leave as default in fresh worksheet
    interface(typesetting=standard):
    writeto(....);
    ...
    writeto(terminal):

ps. You know that the command restart does not reset these interface settings in a given Worksheet/Document in the Standard GUI, right?

I will mention one more, with a twist on doing it via definition.

This one also has the unexpanded (3*x^3+y^2)^2 subterms, as requested.

But the reason that I like this one is that --  when hit with simplify, say -- it does not produce those ugly numerator and denominator, both as sums with most terms involving radicals with fractional powers. And numer or denom of it produces the same as appear after applying either simplify or radnormal, which just the mentioned subterm getting expanded.

restart;

eqn := 5*(x*y)^2+x/sqrt(y) = x^2+2*(3*x^3+y^2)^3;

5*x^2*y^2+x/y^(1/2) = x^2+2*(3*x^3+y^2)^3

foo := implicitdiff(eqn, y, x);

2*(-54*y^(11/2)*x^2-324*y^(7/2)*x^5-486*y^(3/2)*x^8+10*x*y^(7/2)-2*x*y^(3/2)+y)/(216*y^(5/2)*x^6+144*y^(9/2)*x^3+24*y^(13/2)-20*x^2*y^(5/2)+x)

T := expr -> thaw(radnormal(subsindets(expr,`^`(`+`,posint),freeze))):

alt := -T(diff((rhs-lhs)(eqn), x))
       /T(diff((rhs-lhs)(eqn), y));

2*y*(54*y*x^2*(3*x^3+y^2)^2-10*y^3*x+2*x*y-y^(1/2))/(20*y^3*x^2-24*y^3*(3*x^3+y^2)^2-x*y^(1/2))

normal(alt - foo);

0

 

Download impldiff_alt.mw

 

Yet another way, without a kludge, and with a nicer form than I had above. (If isolate is replaced with solve and the rhs is removed, or if I don't first collect wrt diff, then the messier form attains.)

restart;

eqn := 5*(x*y)^2+x/sqrt(y) = x^2+2*(3*x^3+y^2)^3;

5*x^2*y^2+x/y^(1/2) = x^2+2*(3*x^3+y^2)^3

diff((rhs-lhs)(eval(eqn,x=x(y))), y):
rhs(isolate(collect(%, diff), diff(x(y),y))):
dxdy := eval(%, x(y)=x);

(-12*(3*x^3+y^2)^2*y+10*x^2*y-(1/2)*x/y^(3/2))/(2*x+54*(3*x^3+y^2)^2*x^2-10*x*y^2-1/y^(1/2))

simplify( dxdy - implicitdiff(eqn, x, y) );

0

diff((rhs-lhs)(eval(eqn,y=y(x))), x):
rhs(isolate(collect(%, diff), diff(y(x),x))):
dydx := eval(%, y(x)=y);

(-2*x-54*(3*x^3+y^2)^2*x^2+10*x*y^2+1/y^(1/2))/(12*(3*x^3+y^2)^2*y-10*x^2*y+(1/2)*x/y^(3/2))

simplify( dydx - implicitdiff(eqn, y, x) );

0

 

Download impdiffalt.mw

You have not included the equation.

@Kitonum The Generate(choose(...)) functionality is not fast, as used here. It's a little faster if the makeproc option is used. But it's still much slower than indexing by an integer generated via rand.

restart;
with(RandomTools):

LetList := [C, E, F, H, K, P, T, W, X, Y]:

[seq(Generate(choose(LetList)), i=1..5)];
                        [T, Y, P, E, H]

genR:=Generate(choose(LetList), makeproc):

genR();
                               P

[seq(genR(), i=1..5)];
                        [K, C, W, K, Y]

N:=10^5;
                          N := 100000

CodeTools:-Usage( [seq(Generate(choose(LetList)), i=1..N)] ):
memory used=252.55MiB, alloc change=32.00MiB, cpu time=1.71s, real time=1.71s, gc time=80.78ms

CodeTools:-Usage( [seq(genR(), i=1..N)] ):
memory used=165.57MiB, alloc change=0 bytes, cpu time=1.17s, real time=1.17s, gc time=56.40ms

gen:=rand(1..nops(LetList)):

CodeTools:-Usage( LetList[['gen()'$N]] ):
memory used=2.29MiB, alloc change=0.77MiB, cpu time=40.00ms, real time=40.00ms, gc time=0ns


CodeTools:-Usage( Generate(choose(LetList)), iterations=N ):
memory used=2.61KiB, alloc change=0 bytes, cpu time=17.28us, real time=17.29us, gc time=8.6e+02ns

CodeTools:-Usage( genR(), iterations=N ):
memory used=1.72KiB, alloc change=0 bytes, cpu time=12.08us, real time=12.09us, gc time=5.1e+02ns

CodeTools:-Usage( gen(), iterations=N ):
memory used=32 bytes, alloc change=0 bytes, cpu time=6.0e+02ns, real time=6.0e+02ns, gc time=0ns

I would expect that a more runtime-efficient way to construct these Matrices (if that really matters much to the OP) would be through repeated used of ArrayTools:-BlockCopy.  That avoids construction of the rows as lists of sequences of duplicate copies of L and F, which is just temporary/collectible garbage.

Likely even more efficient than that would be repeated assignment of just the nonzero entries of sparse F and L into the target Matrix.

I answered in terms of Matrix(..., scan=triangular[upper]) because it seems simple and clear. And the way the rows are constructed is very much like the OP's construction of the bands in his call to BandMatrix for L, by simple use of seq.

Do you think that the consequences of such a change in behavior would be limited to, "just a little overhead"?

There are at least two actions here, both of which may take place in `^` which is a kernel built-in: splitting (2*Pi)^(1/2) and rationalizing the denominator in 1/2^(1/2) .  I don't see why changing either of those canonicalizations might not bring about unexpected changes in functionality or performance.

I really, really don't like customizable, computational preferences with such a low-level effect. Every time a new one is added the cost of an exhaustive regression- and unit-test run (against all combinations of all such kind of preferences) will likely nearly double.  There are now enough such preferences that the cost of a frequently scheduled, exhaustive test run must surely be prohibitive. And hence the consequence of adding such a new preference is the added risk that some computations will fail under some configurations without anyone discovering it before conflicting examples take root.

Since the OP asked about what formulas Maple might access, there is also this:

  map(print, FunctionAdvisor(hypergeom, quiet, "special_values")):

or, paying attention to the "special values" section which is produced in Maple 2018,

  FunctionAdvisor(hypergeom);

There are also somewhat brief help-pages for Topics convert,GAMMA_related and simplify,hypergeom and convert,StandardFunctions . The help page for Topic hypergeom mentions the last of those in its description.

The knowledge in FunctionAdvisor and in convert and simplify are related, but I suspect that it is a considerable ongoing task to put the mechanisms, knowledge, and documentation in optimal order.

In the rare times that I've needed to, it's been possible to extract programmatically a particular formula out of FunctionAdvisor's return, and then use it to effect a replacement.

 

Ok, it looks as if you entered x^2+5-2 presumably in 2D Input mode.

But there are a few other configuration options that might be affecting this. For example, do you have a language pack installed? What typesetting level is your default?

Did you type all the input from the keyboard, or did you use any of the palettes or command-completion?

It would probably be helpful if you could upload short Worksheet/Document that illustrated (just) the problem, as well as answered the above queries.

@digerdiga Try it as,

frontend~(expand,`[]`~(o))
 

 

@digerdiga Where did you get the idea that the following will apply both simplify and combine to the collected coefficients?  (If it's due to something I once wrote, then it was likely a mistake I missed in haste.)

   collect(f,[k,GAMMA],simplify,combine)

Please compare,

restart;
kernelopts(version);

    Maple 2018.1, X86 64 LINUX, Jun 8 2018, Build ID 1321769

collect( 1+x+x^2, x, K );

                          2                
                    K(1) x  + K(1) x + K(1)

collect( 1+x+x^2, x, K, W ); # no application of K

                          2                
                    W(1) x  + W(1) x + W(1)

collect( 1+x+x^2, x, W@K );

                         2                      
                W(K(1)) x  + W(K(1)) x + W(K(1))

collect( 1+x+x^2, x, u->W(K(u)) );

                         2                      
                W(K(1)) x  + W(K(1)) x + W(K(1))

And for your example these two produce the same thing,

collect(numer(f),[k,GAMMA],u->simplify(u/denom(f)));

collect(numer(f),[k,GAMMA],simplify@(u->u/denom(f)));

@digerdiga Please explain precisely what you mean, and if in doubt upload a worksheet that illustrates the problem clearly.

restart;

kernelopts(version);

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

f:=GAMMA(L+2*q-3-k)/(GAMMA(L-k)*k)*((GAMMA(-2*q+L)*GAMMA(L+2*q-3-k)
   -GAMMA(L+2*q-3)*GAMMA(L-2*q-1-k)*(L+2*k-1-(4*k+2)*q))
   /((2*(-1+2*q))*(4*q-3)*GAMMA(L+2*q-3)*GAMMA(L+2*q-3-k)));

(1/2)*(GAMMA(-2*q+L)*GAMMA(L+2*q-3-k)-GAMMA(L+2*q-3)*GAMMA(L-2*q-1-k)*(L+2*k-1-(4*k+2)*q))/(GAMMA(L-k)*k*(-1+2*q)*(4*q-3)*GAMMA(L+2*q-3))

collect(numer(f),[k,GAMMA],u->u/denom(f));

(1/2)*(4*q-2)*GAMMA(L-2*q-1-k)/(GAMMA(L-k)*(-1+2*q)*(4*q-3))+(1/2)*GAMMA(L+2*q-3-k)*GAMMA(-2*q+L)/(GAMMA(L-k)*k*(-1+2*q)*(4*q-3)*GAMMA(L+2*q-3))+(1/2)*(-L+2*q+1)*GAMMA(L-2*q-1-k)/(GAMMA(L-k)*k*(-1+2*q)*(4*q-3))

collect(numer(f),[k,GAMMA],u->simplify(u/denom(f)));

GAMMA(L-2*q-1-k)/(GAMMA(L-k)*(4*q-3))+(1/2)*GAMMA(L+2*q-3-k)*GAMMA(-2*q+L)/(GAMMA(L-k)*k*(-1+2*q)*(4*q-3)*GAMMA(L+2*q-3))-(1/2)*(L-2*q-1)*GAMMA(L-2*q-1-k)/(k*(-1+2*q)*(4*q-3)*GAMMA(L-k))

 

 

Download collect_numer_2015.mw

Don't try and insert the contents of your file here. Just insert a link to the uploaded file.

Hit the OK button as the last step in the pop-up dialog, after inserting the link.

If that all fails then try it with a compressed .zip file.

First 238 239 240 241 242 243 244 Last Page 240 of 592