mmcdara

7891 Reputation

22 Badges

9 years, 61 days

MaplePrimes Activity


These are replies submitted by mmcdara

@vv 

Post scriptum : I just realised that in the case of a mixture of two rvs U1 and U2 of disjoint supports it's enough to write the pdf of the mixture this way
pdf := (p,x) -> p*PDF(U__1, x) + (1-p)*PDF(U__2, x);

Of course this doesn't solve the sampling problem... but I just realised (once again) that it is very easy to sample MIXTURE(1/3) with this simple method :
U := Sample(Uniform(0, 1), 10);
map(solve, CDF(MEL(1/3), x)=~U, x); 


Now the question is: how could it be possible to declare this strategy in the definition of the Distribution (a priori by instanciating the attributes RandomSample and RandomSampleSetup) in order  to be able to invoke it while writing Sample(...., method=custom) ?

 

 

@vv 

I see two problems in your worksheet.

1. The distribution corresponding to the RV MIXTURE is not correctly defined. It should be:

pdf := (p,x) -> p*PDF(U1, x)*Heaviside(x+3) + (1-p)*PDF(U2, x)*Heaviside(x-1);
cdf := (p,x) -> int(pdf(p,y), y=-infinity..x);


Right, this was my first attempt but I got an error withe the MIXTURE := p -> RandomVariable(...)  instruction.
I just copy-paste your code and I can't reproduce this error: probably I'd done some typo but the fact is, I came to use this "incorrect" definition of pdf and cdf for it did not return an error.

In any case your correction partially solves my problem (it remains the sampling of the whole "support")

Thank you very much

 

PS : I don't know, me neither, how to define the support of a rv. Just as I don't know how to define a custom sampler: the help page is not very instructive on this point.

 

@Carl Love @vv

Thanks to both of you.

Could I infer from what you said that "arithmetic of infinity" is not completely (could I say "without flaws'?) implemented in Maple and that, in all cas, we must be very carefull while using it?

 

@Kitonum 

In a sense, this is natural, because legend option is associated with the image of curves..." it is what I suspected too.

I'm at home right now with my old Maple 2015 version: in my reply to Carl Love you will see that the error message is very explicit with this version, I do not remember thios is still the case in Maple 2019.

Thanks for the help

@Carl Love 

here it is
 

restart:

Unfortunately I'm home right now and I still use Maple 2015.

The error message is so clear that receiving it with Maple 2019  would not have lead me to ask a question.

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

(1)

plots:-inequal({y > t, y < t^2}, y=-2..2, t=-2..2, legend="test")

Error, (in plots:-display) display does not accept the legend option

 

 


 

Download inequal.mw

@acer 

It works perfectly.
Thanks for the help

@Kitonum 

Why not just write the following 2 lines and it will be beautiful:... because the "structure"  I want to display doesn't have a matrix shape.

An example of this "structure" is given in this help page DocumentTools:-Layout:-Cell :

T := Table(Column(),Column(),Column(),widthmode=pixels,width=90,alignment=center,
           Row( Cell( "A1", columnspan=2 ), Cell("A2", rowspan=2 ) ),
           Row( Cell( "B1", rowspan=2), Cell( "B2" ) ),
           Row( Cell( "C", columnspan=2 ) )):
InsertContent(Worksheet(Group(Input( T )))):

 

... and the cell B1, for instance, must contain the piecewise relation : so Tabulate is useless here

@Carl Love 

Thank you very much, your answer suits me perfectly and the polynomial case is more than enough.
(PS: I wasn't aware about type recursivity).

The  footnote and your conclusion are very clear.

@Carl Love @acer  @Joe Riel

Thank you three for your precious help.

Here is a special comment on Carl's sentence "But mostly I want to draw your attention to the distinction between types and properties because I think that you may be referring to the latter".

 I know a little bit about assume and properties and I think that my question was reallyoriented on types (even if it was perhaps not clear enough). 

Maybe you will have a better understanding of my question if I explain its context.
In one of your replies, months ago, you showed me how to define a type 'RV' (for Random Variable) while using TypeTools:-AddType.
I'm presently working on a course on Statistics and I decided to use Maple to explain some concepts.
The minimal way to define a random variable with package Statistics is 

dist := Distribution(PDF=(t->f(t))):
V := RandomVariable(dist);


And I thought it would have been even better if I could write something like V::RV
where type RV is (your code) :
TypeTools:-AddType(
     RV, 
     {RandomVariable, 
       'RandomVariable^posint', 
        '`*`'({RandomVariable, 'RandomVariable^posint'})
     }
);


Related to this point is the following :

  • Suppose you define 2 rvs X and Y (Statistics:-RandomVariable)
    You can verify that [attributes(X)][2] is RandomVariable (same thing for Y)
  • Now set Z=X+Y ; Z is obviously a random variable, but Z has no attributes and is not the same "type of object" than X or Y.
  • I tought that if it was possible to declare that both X and Y where of some type (RV) then this type could be inhereted by Z ..???

@Samir Khan 

Received five out of five, I took the opportunity to vote up here

@Samir Khan 

Thanks, I'm going to look at it

Nice !
I've seen these types of plots from parameter curves before and I've always wondered how to get the expressions of these curves.
Could you briefly explain to me how you did it?

Happy new year

Fine, 

What is the minimum version of Maple which supports the 'rotation' option in textplot ?

A classical way to compute this integral is to use a serie expansion of the integrand :
 

restart:

J0 := Int(cosh(cos(2*t)), t = 0 .. 2*Pi)

Int(cosh(cos(2*t)), t = 0 .. 2*Pi)

(1)

J1 := IntegrationTools:-Change(J0, t=u/2)

(1/2)*(Int(cosh(cos(u)), u = 0 .. 4*Pi))

(2)

J2 := map(simplify, convert(J1, exp))

(1/4)*(Int(exp(cos(u))+exp(-cos(u)), u = 0 .. 4*Pi))

(3)

# A classical way to compute this integral is to use a serie expansion of the integrand
# formally (N --> + infinity):

L1 := N -> 1/4 * int(add(cos(u)^n/n!, n=0..N), u=0..4*Pi)

proc (N) options operator, arrow; (1/4)*(int(add(cos(u)^n/factorial(n), n = 0 .. N), u = 0 .. 4*Pi)) end proc

(4)

eval(L1(100) + subs(cos(u) = -cos(u), L1(100)));

(494862290230313779810714536331763867748886021312314850235382520276354031282881032749106453076199887040428321869725955993930836848899840675596580259521486096667/195433073004454404037640198313320859318965533267125423756511234573420484197258217148892374914594467610273916848620365158942916187521024000000000000000000000000)*Pi

(5)

evalf[20](%);

7.9549265210128452746

(6)

# speed of convergence

phi := N -> eval(L1(N) + subs(cos(u) = -cos(u), L1(N))):

vals := [ seq([N, phi(N)], N in [seq(1..41, 2)]) ]:
increments := [ seq([N, log[10](vals[N+1][2]-vals[N][2])], N=1..numelems(vals)-1)]:
plot(increments, gridlines=true)

 

 


 

Download Quasi_exact_solution.mw

 

@vv 

I do not completely disagree with you :

  • Your first proposal is awkward because 'diff(f(a+b, a-b), x__2, x__1)' returns    but 
    diff(f(a+b, a-b), x__2, x__1) returns 0... hence an ambiguity in the writing of  : does it means 0 or not?
     
  •   seems reasonable, even if some previous explanation of the meaning of f[1, 2] ought to be necessary (even if all mathematicicians will probably understand it first glance).
     
  •  doesn't satisfy me, it is very close to D[1, 2] which is a little bit abstract (in fact I often faced people that do not have particular knowledge of Maple and that are put off withe this D[...] notation).


The point I completely agree with you is that the Liebniz notation, while very clear, is too verbose and difficult to read whebn applied to complex expressions like the one I presented.

Another possibility (close to your proposal, could be  (\partial_{1, 2]f)(a+b, a-b) (in LaTeX notation).


To conclude, a thing I'm sure of is that the default notation (Maple <= 2016) seems awfull to me.
On the example below, I'm quite satisfied with the notation D[1]f (maybe  (D[1]f) would suit me better), 
but not by what it becomes after using convert(..., Diff).

restart;

T := mtaylor(f(U__1, U__2), [U__1=mu__1, U__2=mu__2], 2);

f(mu__1, mu__2)+(D[1](f))(mu__1, mu__2)*(U__1-mu__1)+(D[2](f))(mu__1, mu__2)*(U__2-mu__2)

(1)

M := convert(T, Diff)

f(mu__1, mu__2)+(Diff(f(mu__1, mu__2), mu__1))*(U__1-mu__1)+(Diff(f(mu__1, mu__2), mu__2))*(U__2-mu__2)

(2)

 


 

Download Awfull.mw

 

First 114 115 116 117 118 119 120 Last Page 116 of 154