Maple 2015 Questions and Posts

These are Posts and Questions associated with the product, Maple 2015

Hi, 

The present work is aimed to show how bayesian inference methods can be used to infer (= to assess) the probabilility that a person detected infected by the SARS-Cov2  has to die (remark I did not write "has to die if it" because one never be sure of the reason of the death).
A lot of details are avaliable in the attached pdf file (I tried to be pedagogic enough so that the people not familiar with bayesian inference can get a global understanding of the subject, many links are provided for quick access to the different notions).

In particular, I explain why simple mathematics cannot provide a reliable estimate of this probability of death (sometimes referred to as the "death rate") as long as the epidemic continues to spread.

Even if the approach presented here is rather original, this is not the purpose of this post. 
Since a long time I had in mind to post here an application concerning bayesian methods. The CoVid19 outbreak has only provided me with the most high-profile topic to do so.
I will say no more about the inference procedure itself (all the material is given in the attached pdf file) and I will only concentrate on the MAPLE implementation of the solution algorithm.

Bayesian Inference uses generally simple algorithms such as MCMC (Markov Chain Monte Carlo) or ABC (Approximate Bayesian Computation) to mention a few, and their corresponding pseudo code writes generally upon a few tens of lines.
This is something I already done with other languages but I found the task comparatively more difficult with Maple. Probably I was to obsess not to code in Maple as you code in Matlab or R for instance.
At the very end the code I wrote is rather slow, this because of the allocated memory size it uses.
In a question I posed weeks ago (How can I prevent the creation of random variables...) Preben gave a solution to limit the burst of the memory: the trick works well but I'm still stuked with memory size problems (Acer also poposed a solution but I wasn't capable to make it works... maybe I was too lazzy to modify deeply my code).

Anyway, the code is there, in case anyone would like to take up the challenge to make it more efficient (in which case I'll take it).

Note 1: this code contains a small "Maplet" to help you choose any country in the data file on which you would like to run the inference.
Note 2: Be careful: doing statistics, even bayesian statistics, needs enough data: some countries have history records ranging over a few days , or no recorded death at all; infering something from so loos date will probably be disappointing

The attached files:

  • The pdf file is the "companion document" where all or most of it is explained.It has been written a few days ago for another purpose and the results it presents were not ontained from the lattest data (march 21, 2020 coronavirus)
  • xls files are data files, they were loaded yesterday (march 28, 2020) from here coronavirus
  • the mw file... well, I guess you know what it is.
     

Bayesian_inference.pdf

total-cases-covid-19_NF.xls

total-deaths-covid-19_NF.xls

Bayesian_Inference_ABC+MCMC_NF_2.mw


 

Hi, 

Suppose you have to do some sequence of operations on a random variable (RV), and that you need to repeat this for several RV of the same family (e.g. exponential RV), differing only in the values of their parameters.

Here are two examples do code this.
1/ probably the most natural way to proceed (?)
restart:
with(Statistics):
X := a -> RandomVariable(Exponential(a)):
for n from 1 to 100 do
  S := X(n);
  # here are some operations to do
end do:
anames(alluser);

The last instruction indicates that 103 user variables have been created (X, n, S and 100 random variables).
Note that adding one of the commands S := 'S'; or unassign('S') before the end of the loop just unassigns S but not remove the variables named _ProbabilityDistribution, ..., _ProbabilityDistribution98.


2/ To prevent this inflation of random variables I thought to use the procedure Specialize:
restart:
with(Statistics):
X := RandomVariable(Exponential(a)):
for n from 1 to 100 do
  S := Specialize(X, [a=n]):

  # here are some operations to do
end do:
anames(alluser);

This doesn't change the situation.

So my (multiple) question: 

  • How can I prevent the creation of the objects _ProbabilityDistribution, ..., _ProbabilityDistribution98 given only one of them is used for a given value of the loop counter (once the operations have been done I pass to another random variable) ?
  • How can I unassign a random variable ?
    Maybe it is not possible as suggested by the help page about "_": "Any symbol beginning with an underscore (_) is effectively reserved for use only by library code. It is not available to users." ?

Thanks in advance

Hi, 

Here is an example where evalf ( Int(....) ) fails to compute an in integral.
The function to integrate is very smooth and, except method=_Gquad, all the others seem to fail (even method=_MonteCarlo fails, which is probably the most surprising thing!)

Is it a weakness of evalf+Int or a misusse of my own ?

restart:

interface(version)

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

(1)

plot3d(cos(x*y), x=-1..3, y=-1..-0.2)

 

int(cos(x*y), [x=-1..3, y=-1..-1/5]);
evalf[15](%);

Si(3)+Si(1)-Si(3/5)-Si(1/5)

 

2.00705070023234

(2)

CodeTools:-Usage( evalf[10](Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_Gquad)) );

memory used=1.24KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns

 

2.007050700

(3)

CodeTools:-Usage( evalf[10](Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_CubaVegas)) );

memory used=22.14KiB, alloc change=0 bytes, cpu time=16.99s, real time=17.01s, gc time=0ns

 

Int(Int(cos(x*y), x = -1. .. 3.), y = -1. .. -.2)

(4)

CodeTools:-Usage( evalf[10](Int(cos(x*y), [x=-1..3, y=-1..-0.2], method=_MonteCarlo)) );

memory used=12.79KiB, alloc change=0 bytes, cpu time=1000.00us, real time=0ns, gc time=0ns

 

Int(Int(cos(x*y), x = -1. .. 3.), y = -1. .. -.2)

(5)

N := 10^6:
X := Statistics:-Sample(Uniform(-1, 3), N):
Y := Statistics:-Sample(Uniform(-1, -0.2), N):
Z := cos~(X*~Y):
add(Z) / N * (4*0.8);

HFloat(2.0076470771803545)

(6)

 


 

Download evalf_Int.mw

 

Hi everybody, I’m Helena

I have a function with the following general characteristics:

y= const*M*[Int_def (from a to b) [f(x)*g(x, M)*p(x, t, M,K)]dx]

::::::::::::::::::::::::::::::::::::::::::::::::::

y= dependent variable

a= 1.76E-7

b= 1.76E-9

x= integration variable

M= unknown parameter

K= unknown parameter

t= independent variable

::::::::::::::::::::::::::::::::::::::::::::::::::

... and I'm trying to fit it to my experimental data (421 values), to determine the best values for M and K. In order to do that I’m using the package Statistic and the NonlinearFit command from maple, however, it seems that NonlinearFit cannot fit the model (y(t)) to the experimental data. It gives an error: “Error, (in Statistics:-NonlinearFit) integration range or variable must be specified in the second argument, got HFloat(1.0) = 0 .. 1” for which I could not find any explanation or solution on the internet. Could you please give me some advice or ideas about how can I solve this problem?

Thank you so much in advance for your attention and help.

Hi, 

Here is the minimal situation that reveals which that could be a (little) bug in the MAPLE 2015 version of Explore.

In the attached file y is a list of numbers and val(r) a procedure that just print the value the rth element of y.
Changing the value of r is done with Explore (of course of no interest at all).
If I define the parameter r as a list ( r=[1..numelems(y)] ), only the value of y[1] is displayed: changing the value of r generates an error.
This doesn(t happen if r is defined as a slider ( r=1..numelems(r) ).

I discovered than the initial instance of Explore defines r as an integer while all the others (due to a change of r) define r as a string.
In the last command of the attached file you will see hjow I have circumvent this problem.

Is it a bug in Explore or does it exist some way to force the values of r to the implicit type they have in r=[$1..numelems(y)] ?

TIA

Download explore.mw

 

 

 

Hello,

I am looking help for solving this integral equation using the collocation method with 1.5<= x<=3.5 ? 

I have used the successive approximation method and the solution seems to be increasing.

Thanks

Hi, 

I have a list of integers (>1) and for all of them I define an alias (in the attached file I've tried two different names for them : a[n] or a||n) wich represents the nth roots of the unity.
When I apply the procedure allvalues to a specific alias it returns the algebraic values of the corresponding roots of the unity.
But when aplied to the list of aliases it gives me back only the name of the alias, not the algebraic values.

How can I fix this ?

TIA

restart:

interface(version)

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

(1)

for n from 2 to 3 do
  alias(a[n]=RootOf(z^n-1)):
end do:

alias();

a[2], a[3]

(2)

allvalues(a[2]);
allvalues(a[3]);

seq(allvalues(a[n]), n=2..3)

1, -1

 

1, -1/2+((1/2)*I)*3^(1/2), -1/2-((1/2)*I)*3^(1/2)

 

a[2], a[3]

(3)

for n from 2 to 3 do
  alias(a||n=RootOf(z^n-1)):
end do:

alias();

allvalues(a2);
allvalues(a3);

seq(allvalues(a||n), n=2..3)

a[2], a[3], a2, a3

 

1, -1

 

1, -1/2+((1/2)*I)*3^(1/2), -1/2-((1/2)*I)*3^(1/2)

 

a2, a3

(4)

A := [alias()]:
map(allvalues, A);

[a[2], a[3], a2, a3]

(5)

 


 

Download allvalues.mw

 

 

Hello,

I have the general function F(x,g(y)), and I don't understand the following notation of the derivative of  F w.r.t  y in Maple ?  What is D2(F) ?  Can we provide a concrete example ?

Thank you!

Dear Users!

Hope you would be fine with everything. I want to evaluate an expression (diff(u(y, t), y)+diff(diff(u(y, t), y), t)) for various values of b at y = 0, t=1. Please help me to evaluate it. Thanks in advance,

restart; with(plots); a := .7; L := 8; HAA := [0, 2, 5, 10];

for i to nops(HAA) do

b := op(i, HAA);

PDE1[i] := diff(u(y, t), t) = diff(u(y, t), y, y)+diff(diff(u(y, t), y, y), t)-b*u(y, t)+T(y, t);

PDE2[i] := diff(T(y, t), t) = (1+(1+(a-1)*T(y, t))^3)*(diff(T(y, t), y, y))+(a-1)*(1+(a-1)*T(y, t))^2*(diff(T(y, t), y))^2+T(y, t)*(diff(T(y, t), y, y))+(diff(T(y, t), y))^2;

ICandBC[i] := {T(L, t) = 0, T(y, 0) = 0, u(0, t) = t, u(L, t) = 0, u(y, 0) = 0, (D[1](T))(0, t) = -1};

PDE[i] := {PDE1[i], PDE2[i]}; pds[i] := pdsolve(PDE[i], ICandBC[i], numeric)

end do;
 

with(RegularChains):
with(ChainTools):
with(MatrixTools):
with(ConstructibleSetTools):
with(ParametricSystemTools):
with(SemiAlgebraicSetTools):
with(FastArithmeticTools):
R := PolynomialRing([x,y,z,a,b]):
sys := [x^2 + y^2 - x*y - 1 = 0, y^2 + z^2 - y*z - a^2 = 0, z^2 + x^2 - x*z - b^2 = 0,x > 0, y > 0, z > 0, a - 1 >= 0, b-a >= 0, a+1-b > 0]:

dec := RealTriangularize(sys,R): # very slow
Display(dec, R);

dec := LazyRealTriangularize(sys,R): # it is faster
dec2 := value(dec): # very slow
value(dec2); 

find a , b to satisfy sys have real solution

expect  one of solution is below, but above function are very slow, load a very time still no result, where is wrong?

R1 = a^2+a+1-b^2;
R1 = a^2-1+b-b^2;

[R1 > 0, R2 > 0]


 

Hi,

Is it possible to force Maple to simplify these Sum(s) ?
SimplifySum.mw
 

s := Sum(a*X[n]+b, n=1..N);
simplify(s);
value(s);  # part of the job done  but...


IWouldLikeToHave = a*Sum(X[n], n=1..N) + b*N; # or +N*b, it doesn't matter

Sum(a*X[n]+b, n = 1 .. N)

 

Sum(a*X[n]+b, n = 1 .. N)

 

N*b+sum(a*X[n], n = 1 .. N)

 

IWouldLikeToHave = a*(Sum(X[n], n = 1 .. N))+N*b

(1)

s := Sum(X[n]+Y[n], n=1..N);
(expand@value)(s);


IWouldLikeToHave = Sum(X[n], n=1..N) + Sum(Y[n], n=1..N);

Sum(X[n]+Y[n], n = 1 .. N)

 

sum(X[n]+Y[n], n = 1 .. N)

 

IWouldLikeToHave = Sum(X[n], n = 1 .. N)+Sum(Y[n], n = 1 .. N)

(2)

 

 

 

Thanks in advance

 

Hi, 

I can't find a unique way to define a mixture of two random variables that enables at the same time to compute its PDF and generate a sample.
In the attached file you will find two methods :

  1. the first one is the most formal and only CAS are supposed to be able to allow its implementation:
     it enables computing the PDF and the CDF (trivial) but fails to generate a sample.
    (PS : in a first attempt I had defined only the PDF, which should have been enough for method=envelope does work... ... at my opinion)
     
  2. the second method is the one one would use in non CAS languages (for instance Matlab, R, ...). It enables generating a sample (of course) but fails to compute the PDF (which is not very surprising).

So my question: does anyone here would have some suggestions to make one these two methods capable to compute both the PDF (eventually the CDF) and generate samples ?

PS: still have this kind of problems (tomleslie suggested months ago that using interface(rtablesize=10) could help but it's not the case here)
Maple Worksheet - Error
Failed to load the worksheet /maplenet/convert/Mixture_of_random_variables.mw .

 

Download Mixture_of_random_variables.mw

 

Hi 

I got, a bit by mistake, a weird result that seems to come from the way "Maple" manipulates infinity (please have a look at the results below)
I couldn't find a correct explanation to these results in the help pages dedicated to infinity or evaluation.

Could anyone explain me why, in some circumstances, 'infinity' seems to be a name (for instance infinity*Pi; does not return  infinity but infiniy/Pi).
Thanks in advance

 

restart:

with(Statistics):

f := PDF(Cauchy(0, 1), x)

1/(Pi*(x^2+1))

(1)

m := int(x*f, x=-infinity..+infinity);

undefined

(2)

p := int(x*f, x);

(1/2)*ln(x^2+1)/Pi

(3)

# Naive "proof" : eval(..., infinity) seems to consider infinity as a name (consistent with
# the first line in help(infinity) without any particular property.
# This seems to be confirmed by the value of p1 and p2 : I expected to get infinity instead
# of infinity/Pi.

p1 := eval(p, x=-infinity);
p2 := eval(p, x=+infinity);
p2 - p1;

infinity/Pi

 

infinity/Pi

 

0

(4)

# Correct "proof" :

a := limit(p, x=-infinity);
b := limit(p, x=+infinity);
b-a

infinity

 

infinity

 

undefined

(5)

# Does Maple treat 'infinity' as a number ?

infinity         - infinity;
infinity*2       - infinity*2;
infinity*(1/3)   - infinity*(1/3);
infinity*0.333   - infinity*0.333;
infinity*sqrt(2) - infinity*sqrt(2);
infinity/Pi      - infinity/Pi;

undefined

 

undefined

 

undefined

 

Float(undefined)

 

0

 

0

(6)

limit(sqrt(2)/x, x=0) - limit(sqrt(2)/y, y=0);
limit(Pi/x, x=0)      - limit(Pi/y, y=0);

undefined

 

undefined

(7)

 


 

Download Infinity.mw

Dear Users!

Hope you would be fine with everything. I have following code to generate marix A of order M by M

restart; with(LinearAlgebra); with(linalg); Digits := 30; M := 10; nu := 1;

for k1 while k1 <= M do

C[k1] := simplify(sum((-1)^(k1-1-i1)*GAMMA(k1-1+i1+2*nu)*GAMMA(nu+1/2)*x^i1/(GAMMA(i1+nu+1/2)*factorial(k1-1-i1)*factorial(i1)*GAMMA(2*nu)), i1 = 0 .. k1-1))

end do;

A := evalm(Matrix(M, M, proc (i, j) options operator, arrow; eval(C[j], x = (i-1)/(M-1)) end proc))

I want to split (or decompose) A into two parts Ad and Ab 

A = Ab + Ad

where Ad is M by M matrix of all entries of A but first and last rows of Ad shoud be zero

and Ab is M by M matrix with zero entries expect first and last rows.

For exmaple for M = 5, A, Ab and Ad are given as,

Ab := Matrix(5, 5, {(1, 1) = 1, (1, 2) = -2, (1, 3) = 3, (1, 4) = -4, (1, 5) = 5, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (3, 5) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 0, (4, 5) = 0, (5, 1) = 1, (5, 2) = 2, (5, 3) = 3, (5, 4) = 4, (5, 5) = 5});

Ad := Matrix(5, 5, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (2, 1) = 1, (2, 2) = -1, (2, 3) = 0, (2, 4) = 1, (2, 5) = -1, (3, 1) = 1, (3, 2) = 0, (3, 3) = -1, (3, 4) = 0, (3, 5) = 1, (4, 1) = 1, (4, 2) = 1, (4, 3) = 0, (4, 4) = -1, (4, 5) = -1, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 0});

Please help me to fix this problem.
Special request @acer @Carl Love @Kitonum @Preben Alsholm

Hi,

How can I force the command InsertContent(Worksheet(Group(Input( T )))) to display the variable eq as it appears in label (2) ?

(a screen capture of the output of InsertContent(Worksheet(Group(Input( T )))) is given after the Maple code)

restart:

interface(version)

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

(1)

with(DocumentTools):

with(DocumentTools[Layout]):

eq := piecewise(t < 1, sin(t), cos(t));

C := Cell( Textfield(style=TwoDimOutput,Equation(eq)) ):
T := Table(Column(), widthmode=percentage, width=40, Row(C)):
InsertContent(Worksheet(Group(Input( T )))):

eq := piecewise(t < 1, sin(t), cos(t))

(2)

 



Download Layout.mw

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