mmcdara

7891 Reputation

22 Badges

9 years, 52 days

MaplePrimes Activity


These are questions asked by mmcdara


Let's suppose I define a procedure P which uses a Maple built-in procedure BP.
BP is a procedure which uses optional parameters, let's say a and b.

I would like to call P with the same optional parameter names than BP, that is to write something like this

P := proc(....., {a::a_type:=a:-default, b::b-type:=b_default)
       ....
       BP(...., 'a'=a, 'b'=b)
     end proc.

The execution of P(..., a=1) leads to the error unexpected option: 1=1
 

A workaround is to define P this way

P := proc(....., {P_a::a_type:=a_default, P_b::b-type:=b_default)
       ....
       BP(...., a = P_a, b = P_b)
     end proc.

# example

P(..., P_a=1, P_b="yes")

This works but it would be easier for the users to use the same option names in the definition of P than in the definition of BP.

Question: Is that possible?

Here is an illustrative example where I would prefer to write

ecdf(S, color="red", thickness=3)

instead of

ecdf(S, ecdf_color="red", ecdf_thickness=3)


 

restart

ecdf := proc(S, {ecdf_color::string:="blue", ecdf_thickness::posint:=1})
  local N   := numelems(S):
  local M   := sort(S):
  local opt := [color=ecdf_color, thickness=ecdf_thickness]:
  plots:-display(
    plot([ seq(op([[M[i], (i-1)/N], [M[i], i/N], [M[i+1], i/N]]), i=1..N-1) ], opt[])
    , plot([ [M[N], (N-1)/N], [M[N], 1] ], opt[])
    , plot([ [M[N], 1], [(max+(max-min)*0.2)(S), 1] ], opt[], linestyle=3)
    , plot([ [M[1], 0], [(min-(max-min)*0.2)(S), 0] ], opt[], linestyle=3)
  )
end proc:

S := Statistics:-Sample(Uniform(0, 1), 10):
ecdf(S)

 

ecdf(S, ecdf_color="red", ecdf_thickness=3)

 

 


 

Download ecdf.mw


Thanks in advance

 

Let X1, ...XN  names of RandomVariable type and R a random variable defined as a function of  X1, ...XN.
(In Maple type(R, RandomVariable) returns false as R doesn't inherit the RandomVariable type.)

Given an expression of R I would like to determine if R is :

  • either a linear combination of X1, ...XN ,
    example R = a*X+ X+ 1
    (I know how to handle this situation)
     
  • or a linear combination of products of the X1, ...XN ,
    example R = a*X1*X+ b*X3
    (I feel I know how to handle this situation too)
     
  • or a linear combination of functions, or products of functions, of  X1, ...XN .
    example R = a*f(X1, X2) + b*X3*g(X4) + c*X1 + d*X1*X2
    (here I've no idea at all)

In the command hastype(R, some_type), how can I construct type some_type in order it returns an answer which matches the reqierements above?

RV_Type.mw

Thanks in advance for any suggestion

Could you explain me why the three forms of patmatch behave identically (which seems natural) but the three forms of type do not.
Is there a way to define the type in type such that this latter returns the same thing for a*f(x)+b, f(x)*a+b, b+a*f(x), b+f(x)*a ?

Z := f(x)*a+b;
t1 = type(Z, `&+`(algebraic, `&*`(algebraic, function)));
t2 = type(Z, `&+`(`&*`(algebraic, function), algebraic));
t3 = type(Z, `&+`(`&*`(function, algebraic), algebraic));

f(x)*a+b

 

t1 = false

 

t2 = false

 

t3 = true

(1)

p1 = patmatch(Z, A::algebraic*f(X::algebraic) + B::algebraic, 'pat');
pat;
p2 = patmatch(Z, B::algebraic + A::algebraic*f(X::algebraic), 'pat');
pat;
p2 = patmatch(Z, B::algebraic + f(X::algebraic)*A::algebraic, 'pat');
pat;

p1 = true

 

[A = a, B = b, X = x]

 

p2 = true

 

[A = a, B = b, X = x]

 

p2 = true

 

[A = a, B = b, X = x]

(2)
 

 

Download type_vs_patmatch.mw

TIA

I'd like to know the details of the method Statistics:-Mean uses to numerically estimate the expectation of a random variable.

showstat seems of no use and neither seems to be LibraryTools[Browse]();

Here are two examples: the first one (1D) suggests  Statistics:-Mean could use some evalf/Int method, but the conclusion to draw from the second example (R2 --> R) is less clear.

How_does_Mean_proceed.mw

Thanks in advance

PS: I already asked a similar question months ago but didn't get any reply.
       Even answers such as “We don't know” or “We don't care” would suit me better than their absence.

Let us suppose I open Maple, write a worksheet, save it in a folder A and then quit Maple.

Now I run a new session by double clicking on some mw file located in folder B, let us say //B/test_1.mw.
Once opened I do some modifications and decide to save this worksheet into a new file, let us say test_2.mw in the same folder B test_1.mw belongs to (which means I use Save As from the menu bar)

I'm regularly fooled by the fact that the default folder is not B, but the folder A I used in the previous session.

I find this very unpleasant.
Is this a Maple (2015) issue or something related to my operating system (Mac OSX Catalina)?
In case it is a Maple issue which is still present in more recent Maple versions, Would it be possible to set the default backup folder to be the folder to which the active worksheet belongs?

Thanks in advance

1 2 3 4 5 6 7 Last Page 2 of 48