mmcdara

3743 Reputation

17 Badges

6 years, 75 days

MaplePrimes Activity


These are questions asked by mmcdara

Hi 

How to add a legend to Statistics:-Histogram?

This could be particularly useful to compare histograms, for instance in

S := Statistics:-Sample(Normal(0, 1), 1000):
T := Statistics:-Sample(Normal(1, 1), 1000):

plots:-display(
  Statistics:-Histogram(S, color=gold, transparency=0.3, legend="N(0,1)"),
  Statistics:-Histogram(T, transparency=0.3, legend="N(1,1)")
);

But doing this generates the error Error, (in Statistics:-Histogram) display does not accept the legend option

And yes indeed, even this command

h := Statistics:-Histogram(S, legend="N(0,1)")

already produces the same error.

After having examined the structure of h and using a way Carl Love gave here How to change the colour inn Statistics:-Sunflower?  I finally obtained the expected plot.
 

HS := Statistics:-Histogram(S, color=gold, transparency=0.3):
HT := Statistics:-Histogram(T, transparency=0.3):

hs := evalindets([op(HS)], specfunc(COLOUR), c-> (c, LEGEND("N(0,1)")) ):
ht := evalindets([op(HT)], specfunc(COLOUR), c-> (c, LEGEND("N(1,1)")) ):

PLOT(op(hs), op(ht))



But this rather long a way to proceed (Note: it seems that the overrideoption  that acer suggested in this prevous thread doesn't "work" here?)
Do you have any idea if there is a simpler solution?

TIA

Hi, 
 

Trying to change the color of the plot that Statistics:-Sunflower produces is not trivial:

restart:
interface(version);
Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895

# This example comes from the help page
with(Statistics):
data := Vector[row]([2, 5.3, 4.6, .88, 2.5, 5.9, 5, 10, 1.7, 7.8, 7.2, 9.42, 9.01, 3.42, 4, 11.59, 8, 10.3, 1.5, 8.5, 11.4]):
a := SunflowerPlot(data, length = 4, size = [600,200], color=red):
a;     # navy blue plot
op(a); # look at the structure of a to see why red is not accounted for

After having examined the structure of 'a', I circumvent this problem by doing this:

b1 := SunflowerPlot(data, length = 4, size = [600,200]):  #no more color specified
c  := op(select(has, op(1, b1), COLOUR));
b2 := eval(b1, c=COLOUR(RGB, 1, 0, 0)):

# Red sunflowers!!!
plots:-display(b2)  


Does it exist a simpler way to set the color of the sunflowers through some option of  Statistics:-Sunflower ?

TIA

I recently found this piece of code while using showstat:

if type(i,{'symbol', not ('symbol')}) then
...
end if

At first glance, this felt strange to me, because it looked like if we were checking whether "i" was of the "symbol" type or of a type other than "symbol", and therefore the test was still true.

Doing a simple test I obtain this

if type(s,{'symbol', not ('symbol')}) then "TRUE" else "FALSE" end if;
                             "TRUE"
if type(cos(c),{'symbol', not ('symbol')}) then "TRUE" else "FALSE" end if;
                            "FALSE"

Could you explain me what  not ('symbol') really means?

TIA

Here is a simple example which generates a loss of the connection to the kernel.

A few words to help you understand what this simplified code is aimed to do.
The inputs are:

  • a matrix (10 by 2 in the example given above), 
  • a "slave" column p,
  • a "master" column q,
  • a list of rangesr.

Let nr the number of elements of r.
The goal is to separate the elements of M[.. ,p] in nr sorted lists L1, ..., Lnr according to the rule

  • M[n ,p] is in Lk  if M[n ,q] is in r[k]  

A notional example is given in the snippet code below.
The variable num contains nr lists, the kth one contains the values of such that M[n ,q] is in r[k] .

As soon as one element of num is empty list the line S := ... generates the Connection to Kernel lost message.

I have made sure that this no longer happens by coding more carefully.

However, since some recent posts have mentioned this type of connection loss (usually difficult to trace), I thought it might be useful to publish this example (a census of connection loss situations might help make Maple more robust)

restart
interface(version)
Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895

LTB := ListTools:-BinaryPlace:
 
M  := LinearAlgebra:-RandomMatrix(10, 2):
p  := 1:
q  := 2:
r  := [-100..-1, -1..1, 1..100]:
nr := numelems(r):

Y_x, Y_ix := sort(M[.., q] , output=[sorted, permutation]):  
bounds    := map(u -> 1+LTB(Y_x, op(1, u))..LTB(Y_x, op(2, u)), r);
Y_nb      := map(u -> op(2, u)-op(1, u)+1, bounds);
            [2, 0, 8]

num       := [ seq(Y_ix[bounds[k]], k=1...nr) ];
            [[9, 1], [], [3, 2, 6, 7, 10, 4, 8, 5]]

S := [ seq(sort(convert(M[num[k], p], Vector)), k=1..nr) ];

KernelConnectionLost.mw

Hi, 

I have always asked myself this question: why do the colon after the proc(...) statement generate an error if the following statement is local or global?
(the third example is here to show that no error occurs if local is omitted... the warning is of course obvious)

restart:
interface(version);
Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895

f := proc(x) local y: y:=x+1 end proc:

g := proc(x): local y: y:=x+1 end proc:
Error, unexpected `local` declaration in procedure body

h := proc(x): y:=x+1 end proc:
Warning, `y` is implicitly declared local to procedure `h`

TIA

First 8 9 10 11 12 13 14 Last Page 10 of 33