acer

32385 Reputation

29 Badges

19 years, 334 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You can force specific tickmark positions, as well as get the formatting you described. For example,

plot(x, x = 0 .. Pi/2,
     xtickmarks=[seq(n*Pi = Typesetting:-Typeset(Typesetting:-EV(n*Pi)),
                     n = 0 .. 1, 1/10)]);

You could also reduce the font size, eg.

plot(x, x = 0 .. Pi/2,
     xtickmarks=[seq(n*Pi = Typesetting:-Typeset(Typesetting:-EV(n*Pi)),
                     n = 0 .. 1, 1/10)],
     axesfont=[Times,9]);

@AzU You can show the form in a few ways, eg,

de_mat.mw

In your first three examples you wrapped the plotted expressions in calls to abs.

But in your last two examples you used A[1] which is not real-valued for almost all of the specified domains.

Notice that the results for A, coming out of solve, do not contain calls to abs. (Whether you agree with what solve produces, or not, is another matter. You can see the form of your A[1]. The last two examples' plotting results follow from what A[1] happens to be.)

These plotting commands need something real-valued (or with a very small imaginary component which could be taken as a round-off error artefact). The first three examples do that, but the last two do not.

I don't know whether you understand what happens when you wrap such expressions in calls to, say, abs, or Re, or Im. Using your A[1] expression, have a look at the result of,
    plot([Re, Im, abs](A[1]), x = -6 .. 6)

Here are two closely related approaches to coloring the contours by hue. I used only the ColorTools:-Color command here, for the coloring of the curves.

I used a sequence of plots:-implicitplot calls, for the contours. That allows for some convenient ways to specify the coloring method. You could also pass additional options, eg. grid=[41,41] or gridrefine=n, etc, to improve the curve resolution.

I also used one of the plot3d color-function methods (and commented out a colorscheme alternative). But that was mostly to illustrate the difference in the two approaches shown for the curves.

The first approach has the contour colors range over the full hue range. The second has the contour hues scaled relative to the z-range attainable over the full, specified x-y grid.

You could also utilize hue ranges from 0.0 to 0.85, or Red to Magenta, or your preference if you don't want the full cycle. But the above choice would still exist: should the contour hues extend over that full range, or be scaled relative to the z-range attainable over the given x-y ranges?

restart;

contours := [seq(1/2^n, n = 1 .. 3), seq(2^n, n = 1 .. 5)];

[1/2, 1/4, 1/8, 2, 4, 8, 16, 32]

f := abs(sin(x) + y^2 + y + x*I);

abs(sin(x)+y^2+y+I*x)

xyranges := x = -6 .. 6, y = -5 .. 5.5;

x = -6 .. 6, y = -5 .. 5.5

Pmin,Pmax:=[min,max](contours)[];

1/8, 32

PC:=plots:-display(
  seq(plots:-implicitplot(f(x,y)=Z, xyranges
                          , thickness=3
                          ,color=ColorTools:-Color("HSV",[abs((Z-Pmin)/(Pmax-Pmin)),1,1])),
      Z=contours)):
PC;

 

Below is a variant that uses the computed z-range over the specified x-y grid,
as an alternate match of the contour's colors to the hue-density over that
x-y grid.  (The minimal and maximal z-values will be close the red, for the grid.
And the contours colored propertionately.)

 

PS:=plot3d(f(x,y), xyranges
           #,colorscheme=["zgradient",["Red","#FF0001"],colorspace="HSV"]
           ,color=[f, 1.0, 1.0, colortype=HSV]
           ,style=surface):


This is like densityplot, but we control precisely how the hue shading is done.

PS2D:=subsindets(subsindets(PLOT(op(PS)),specfunc(STYLE),u->STYLE(PATCHNOGRID)),
           specfunc({AXESLABELS,CONTOURS}),()->NULL);

Pmin,Pmax:=[min,max](op([1,3],PS))[];

HFloat(0.0322265625), HFloat(37.05499993914233)

PCAlt:=plots:-display(
  seq(plots:-implicitplot(f(x,y)=Z, xyranges
                          , thickness=3
                          ,color=ColorTools:-Color("HSV",[abs((Z-Pmin)/(Pmax-Pmin)),1,1])),
      Z=contours)):
PCAlt;


We can see a close match in color, between contours and the density-style plot.

plots:-display(plots:-display(PS2D,overrideoptions,transparency=0.1),
               PCAlt);


The earlier PC plot, using max and min of the contours for the extreme colors (red),
doesn't properly represent the z-range that the x-y grid attains.

plots:-display(plots:-display(PS2D,overrideoptions,transparency=0.1),
               PC);

 

Download contourplot_hue.mw

Without that transparency adjustment the PC2 colors would be a very close match to those in the PS density-plot. I adjusted the transparent so that we could see that they were indeed overlaid together. And, of course, you could make other adjustments and overlay them deliberately.

Some related plot coloring pages:
  plot3d,colorfunc
  plot,colorscheme,coordinates
  plot,color
There are several other ways to color contours according to some function f(x,y).

If you want something else then you should really be very clear about exactly what you want, how the colors relate to the function as well as its supplied plotting domain (ranges), etc.

So far you have not stated precisely what you want. The citation to the wikipedia Domain-coloring article is still ambiguous.

One simple way is to use a later version,

restart:

kernelopts(version);

`Maple 2019.2, X86 64 LINUX, Nov 26 2019, Build ID 1435526`

with(Statistics):

E := RandomVariable(Normal(mu, sigma)):

Mean(f(x)+E);

f(x)+mu

E := RandomVariable(Distribution(PDF = (z -> f(z)), Mean=mu)):

Mean(f(x)+E);

f(x)+mu

Download Mean_RV.mw

You wrote that there is no unit with symbol M for molar concentration.

But you could add such a thing, with the Units:-AddUnit command.

chemistry_units_ac1.mw

You could also make that new M unit the default (prefered unit) for simplification for expressions having dimensions the same as mol/L and say (mol/L)^2. You could also load the Units:-Simple package, so that simplification and combining of units occurs automatically when using its bindings for arithmetic, etc.

chemistry_units_ac2.mw

Also, the code to define a new unit, and set it as default, could be tidily hidden away inside the Startup Code region of the document. (I won't suggest putting those in an initialization file, or else other people wouldn't see the same results when rerunning the document.)

I got the impression that you'd prefer to see the unit M for molar concentration. If you would actually prefer the literal (mol/L)^2 then please say so. It might be achieved similarly, with the symbol a typeset identifier (name) of (mol/L)^2, or (mol/L)^(-2), instead of 1/M^2, etc. But reciprocals of those might get difficult to handle well.

The first pair of parantheses (brackets) does grouping of terms, to assist with the precedence.

The second pair of parentheses does the functional application, ie. forming function calls.

Here is an example of only the second kind:
    sin(x)

Here is an example of both kinds in use together:
    (sin+cos)(x)
which returns   sin(x) + cos(x)  .

The following shows the role of grouping. Compare these two examples:
    (f+g)(x)
which returns   f(x) + g(x)  .  And now,
    f+g(x)
which returns   f + g(x)   which is the addition of the term f and the term g(x).

The first pair of brackets in   (f+g)(x)  serve an important purpose, for grouping of terms, which makes it quite different from say   f+g(x)   .

The key thing here is which takes precedence -- the function application or the addition. The first pair of parentheses in  (f+g)(x)  allow us to force the addition as preceding or taking precedence over the function application denoted by the second pair of parentheses.

Now something subtler. Suppose that g is unassigned at present, but later on may get a meaning such that g(x) returns something which can itself be applied to arguments. The expression  g(x)(t)  denotes the symbolic placeholder g(x) applied to argument t. So, we can meaningfully apply g(x) to something else, and use it like an operator.

In this rich world we could compose operator f with the placeholder g(x) for some (as yet unknown operator).  So now,
    f@g(x)
denotes the composition of those two operators, f and g(x). This conceptual composition of operators is not itself being applied to an argument. But the result is indeed a meaningful expression, and is not nonsense.

Now compare that last example with this,
    (f@g)(x)
which represents something quite different. This denotes the composition f@g applied to argument x, which results in   f(g(x))  .

The first pair of brackets in   (f@g)(x)  serve an important purpose, for grouping of terms, which makes it quite different from say   f@g(x)   . 

The key thing here is which takes precedence -- the function application or the composition. The first pair of parentheses in  (f@g)(x)  allow us to force the composition as preceding or taking precedence over the function application denoted by the second pair of parentheses.

I hope that helps some.

From some of your other recent Questions it seems that you are interested in module programming for involved purposes, eg. your large automated integration and differential equations solving and testing. In other words, likely some serious, involved, and lengthy code.

I suggest shooting for code maintainability over convenience.

I also think that qualified module references are much superior to so-called short-form names, in lengthy production-quality code. For example, I strongly prefer B:-foo() over just foo() following uses or use or with. I think that it's important that the code be managable, and is legible, understandable and naturally unambiguous. I think that is a far better way to manage the name-space.

If you really prefer terser code, for reading, then the qualified module references can be made shorter. Control of that can be done without having to utilize the uses functionality.

I also think that large amounts of valued code for procedures and modules should be kept in plaintext files -- for safety and robustness of the format, as well as for the ability to do good revision control.

Having said all that, I suggest a plaintext file format (which can be accessed in the GUI using the read command), that might look something like the following. Here the actual names of the modules and submodules can be easily changed later on, because they are defined in a centralized manner.

This is just an example,

$define AM=Amodule
$define BSM=Bsubmodule
$define CSM=Csubmodule

AM:=module()
   export BSM:=module()
     export foo:=proc()
         print("In foo()");
     end proc;
   end module;

   export CSM:=module()
      export boo:=proc()
           BSM:-foo();
      end proc;
   end module;
end module:

$undef CSM
$undef BSM
$undef AM

How about,

    `.`( seq(A[i], i=1..n) );

Naturally, n would be some actual integer.

 

Did you first embed a Speaker Component, say from the Embedded Components palette?

Did you check that the identity property of the Speaker Component matched the second argument passed to the Play command?

Do the other right-click properties of the embedded Speaker Component look reasonable? (eg. not muted, volume>0, driver device looks right, etc)

 

restart:

kernelopts(version);

`Maple 2018.2, X86 64 LINUX, Nov 16 2018, Build ID 1362973`

T := 10^(-6): delta := 10: m := 1:
alpha:= 75/10: v := 65: mu := 8:

z := sqrt((omega^2 - 4*m^2)/alpha^2 - v^2/alpha^2*(4 *delta/alpha*tan(theta)^2
           - v^4/alpha^4*tan(theta)^4)):

a := sec(theta)/sqrt(2)*sqrt((2 *delta)/alpha - v^2/alpha^2*tan(theta)^2 + z):

f1 := 1/(exp(( omega/2 - mu)/T) + 1):
f2 := 1/(exp((- (omega/2) - mu)/T) + 1):

A1 := (-(f1 - f2)*abs(omega/(4*a*alpha*cos(theta)^2
                      *(-delta+ a^2 *alpha* cos(theta)^2)
                      + 2*a*v^2*sin(theta)^2 + 1/10000))):

b := sec(theta)/sqrt(2)*sqrt((2*delta)/alpha - v^2/alpha^2*tan(theta)^2 - z):

f3 := 1/(exp(( omega/2 - mu)/T) + 1):
f4 := 1/(exp((- (omega/2) - mu)/T) + 1):

A2 := (-(f3 - f2)*abs(omega/(4*b*alpha*cos(theta)^2
                      *(-delta+ b^2 *alpha* cos(theta)^2)
                      + 2*b*v^2*sin(theta)^2 + 1/10000))):

Digits:=15:
CodeTools:-Usage(plot(Omega->Int(subs(omega=Omega,unapply(A1+A2,theta)),
                                 0..2*Pi,method=_d01ajc,epsilon=1e-4),
                      0..50));

memory used=7.80MiB, alloc change=0 bytes, cpu time=989.00ms, real time=990.00ms, gc time=0ns

 

Download code_Int_ac.mw

That kind of labeling is available in the Command Line Interface (aka CLI or TTY), and in the Classic GUI.

It is not enabled with default settings in the Java GUI. But it can be enabled by adjusting various interface settings.

Unfortunately the line-breaking doesn't work properly in the Java GUI, for such labeling. Which is a shame because (when working properly) it is a very nice feature. It can make a long expression legible and comprehensible, that would otherwise take many pages to pretty-print.

restart;

kernelopts(version);

`Maple 2018.2, X86 64 LINUX, Nov 16 2018, Build ID 1362973`

sol:=[solve](x^3+x^2-1,x,Explicit):

 

interface(labeling=true):         # default is true
interface(typesetting=extended):  # default is extended
interface(prettyprint=3):         # default for GUI is 3

sol;

[(1/6)*(100+12*69^(1/2))^(1/3)+(2/3)/(100+12*69^(1/2))^(1/3)-1/3, -(1/12)*(100+12*69^(1/2))^(1/3)-(1/3)/(100+12*69^(1/2))^(1/3)-1/3+((1/2)*I)*3^(1/2)*((1/6)*(100+12*69^(1/2))^(1/3)-(2/3)/(100+12*69^(1/2))^(1/3)), -(1/12)*(100+12*69^(1/2))^(1/3)-(1/3)/(100+12*69^(1/2))^(1/3)-1/3-((1/2)*I)*3^(1/2)*((1/6)*(100+12*69^(1/2))^(1/3)-(2/3)/(100+12*69^(1/2))^(1/3))]

interface(labeling=true):         # default is true
interface(labelwidth=20):         # default is 20
interface(typesetting=standard):  # default is extended
interface(prettyprint=2):         # default for GUI is 3

sol;

"([[`%1`=1/6 (100+12 sqrt(69))^(1/3)-(2)/(3 (100+12 sqrt(69))^(1/3))]])"

interface(labeling=true):         # default is true
interface(labelwidth=15):         # default is 20
interface(typesetting=standard):  # default is extended
interface(prettyprint=2):         # default for GUI is 3

sol;

"([[`%1`=1/6 (100+12 sqrt(69))^(1/3)],[`%2`=(2)/(3 (100+12 sqrt(69))^(1/3))],[`%3`=1/12 (100+12 sqrt(69))^(1/3)],[`%4`=(1)/(3 (100+12 sqrt(69))^(1/3))]])"

interface(labeling=true):         # default is true
interface(labelwidth=10):         # default is 20
interface(typesetting=standard):  # default is extended
interface(prettyprint=2):         # default for GUI is 3

sol;

"([[`%1`=(100+12 sqrt(69))^(1/3)],[`%2`=1/6 `%1`-(2)/(3 `%1`)]])"

 

Download expr_labeling.mw

In some situations the LargeExpression package has some related utility.

And there are also the GUI Equation Labels, which have a different utility.

It's not clear what range for x you wish to allow, or what upper bound for k you wish to consider, or whether you want the plot to illustrate k values.

Here are some ideas. You can solve synbolically for x that make k positive (or not).

restart;

gamma__1:=2;

2

k:=gamma__1*(100-x)/100-x*0.05*gamma__1*(100-x)/100;

2-(1/50)*x-0.1000000000e-2*x*(100-x)

alpha:=0.01+0.00001*((k+2*gamma__1)/2)^2;

0.1e-1+0.1e-4*(3-(1/100)*x-0.5000000000e-3*x*(100-x))^2

M:=41539.42878*alpha;

415.3942878+.4153942878*(3-(1/100)*x-0.5000000000e-3*x*(100-x))^2

unwanted:=solve(k<0,{x});

{20. < x, x < 100.}

plot(M,x=0..20,color=red);

plots:-dualaxisplot(M,k, x=0..20, color=[red,blue],
                    axis[2]=[[color=red],[color=blue]]);

plot(piecewise(And(op(unwanted)),undefined,M),x=0..150,color=red);

plots:-dualaxisplot(piecewise(And(op(unwanted)),undefined,M),
                    piecewise(And(op(unwanted)),undefined,k),
                    x=0..150, color=[red,blue],
                    axis[2]=[[color=red],[color=blue]]);

 

Download pw.mw

There appears to be a corrupted Plot XML element (I think in section Opg 3 of Rumintegraler Uge 6).

With that bad element removed, the remaining contents are available, see attachment. This recovers twelve Sections, up to Uge 12. (The Maple 2021.0 GUI could, sadly, only recover the first five of those.)

matOpgaver_1_ac.zip

I strongly suggest that you keep your own regular backups of lengthy and precious assignments done as Maple worksheets.

[edit] I will add this to my collection of earlier reports of corrupted worksheets of Danish students. I'll have to repeat my earlier notes that the manner in which the GUI "repairs" corrupted XML elements could be significantly improved..

@tarik_mohamadi The expression Bi-1 divides both the real and the imaginary components of the determinant expression (eq), under the assumption that remaining parameters are real.

First 88 89 90 91 92 93 94 Last Page 90 of 336