## Why does Statistics:-Mean fails computing the mean...

Asked by:

For a lesson I'm preparing, I want to illustrate some probability concepts using Maple.
In particular, I need to use the fact that the Expectation operator(let say the Mean operator) is a linear operator with respect to random variables.
However, I don't want to particularize my demonstration by using this or that statistical distribution but simply the notion of random variable.
I have therefore created a specific Distribution named  MinimalAbstractDistribution in which only the mean and variance are defined.

When Statistics:-Mean is applied to the expression (A*p+q) where p and q are names and A is a random variable with distribution MinimalAbstractDistribution, linearity is effectively used.
But not when it is applied to A/p or A-q.

Why that?
Is there a way of defining a statistical distribution so that Mean behaves as expected?

(You will easily understand that no workaround of the form

```Mean(A+q);
eval(%, q=-q);

# or
add(Mean~([op(A-q)]))
```

can be accepted in a lesson).

Thanks for your attention

 > restart
 > with(Statistics):

 > MinimalAbstractDistribution := proc(i)   Distribution(Mean=mu[i], Variance=sigma[i]^2) end proc:
 > A := RandomVariable(MinimalAbstractDistribution(1))
 (1)
 > [Mean, Variance](A);
 (2)
 > Mean(p*A+q); Mean(p*(A+q))
 (3)
 > # But Mean(A-q); Mean(A/p)
 (4)

Download Mean_operator.mw

## Customize surface plot...

Asked by:

Dear Users!

I hope everyone here is fine. In the attached file I have a list of points in three dimensions. I want to plot surfaceplot (also in Dimension=2) of only those points which are less than 1.

But I want to plot the density plot for all points with the range on x-axes 5 to 15 and the range on y-axes 50-1000

Help.mw

## A numerical algorithm for SFC and its pseudo-inver...

Asked by:

Hi!

I am trying to implement the algorithms given in this paper (free for download) in Maple 2015

https://www.researchgate.net/publication/374636058_A_simple_algorithm_for_computing_a_multi-dimensional_the_Sierpinski_space-filling_curve_generalization

Such algorithms, apparently very easy, provides an approximation of  a sapce-filling curve and its pseudo-inverse. I am interesting in this space--filling curve for its properties. Please, find attached the Maple file, I am not sure if the code of the paper is not fine or I am doing something wrong.

Many thanks un advsnce for your help

Sierp_v1.mw

## How to calculate time and memory ...

Asked by:

Dear Users!

I hope everyone is fine here. In the attached file I have solved a partial differential equation using the finite difference method for different mesh in spatial directions (i.e., for different Mx). I want to compute the time and memory to compute the solution against each Mx and want to plot it. Kindly help me how to compute the time and memory for each value of Mx.

TIME.mw

I shall be waiting. Thanks in advance.

## Statistics:-Specialize can produce wrong results...

Asked by:

The Statistics package contains a function named Specialize (which quite strangely doesn't appear when you expand the sections of this package).
Here is what help(Specialize) says:

```The Specialize function takes a random variable or distribution data structure that contains symbolic parameters, and performs a substitution to specialize the given random variable or distribution.
```

My goal was to work with mixtures of two random variables. There are many ways to do that depending on the what you really want to achieve, but an elegant way is to define such a mixture this way:

• Let X and Y two random variables representing the two components to be mixed.
For instance X = Normal(mu, sigma) and Y = Normal(nu, tau).

• Let B a Bernoulli random variable with parameter P.

• Then M = B*X + (1-B)*Y represents a random mixture of the two components in proportions (p, 1-p).
Note that M is a 5-parameters random variable.

Doing the things this way enables getting a lot of formal informations about M such as its mean, variance, and so on.

In order to illustrate what the mixture is I draw the histogram of a sample of M.
To do this I Specialized the three random variables X, Y, B.

I used parameters

`mu=-3, nu=3, sigma=1, tau=1, p=1/2`

My first attempt was to draw a sample of the random variable Mspec defined this way

```Mspec := Specialize(B, [p=1/2])*Specialize(X, [mu=-3, sigma=1]) + (1-Specialize(B, [p=1/2]))*Specialize(Y, [nu=3, tau=1]);
```

As you see in the attached file (first plot) the histogram is wrong (so is the variance computed formally).

I changed this into

```Mspec := Specialize(B, [p=1/2])*(Specialize(X, [mu=-3, sigma=1])-Specialize(Y, [nu=3, tau=1])) + Specialize(Y, [nu=3, tau=1]);
```

without more significative success: while the variance is nox corrext the histogram still remains obviously wrong (plot number 2)

My last attempt, which now gives q correct result (plot 3) was:

```Bspec := Specialize(B, [p=1/2]);
Mspec := Bspec*Specialize(X, [mu=-3, sigma=1]) + (1-Bspec)*Specialize(Y, [nu=3, tau=1]);
```

Specialize.mw

I agree that one can easily do this stuff without using  Specialize.
For instance by using the procedure given at the end ofthe attached file.
Or by truly constructing a mixture Distribution (which would be more elegant but more complex).

I also agree that Specialize is in itself of a relative low interest except for educational purposes (you present the theoritical results and next you run a numerical application while giving numeric values to the formal parameters).

But why providing such an anecdotal function if it doesn't do the job correctly?

Note that these results were obtained with Maple 2015, but I doubt they'll be any better for more recent versions, given the confidential nature of Specialize.

## Why am I not able to get the desired integral form...

Asked by:

There are things that seem simple but rapidly turn into a nightmare.

Here is an example: what I want is to the expression given at equation (4) in the attached file.

Using Int gives a wrong result.
Using int gives a right one but not of the desired form (some double integrals are nested while others are not).

I've been stuck on this problem for hours, can you please help me to fix it?

TIA

 > restart
 > use Statistics in   # For more generality defina an abstract probability distribution.   AbstractDistribution := proc(N)     Distribution(       PDF = (x -> varphi(seq(x[n], n=1..N)))     )   end proc:   # Define two random variables pf AbstractDistribution type.   X__1 := RandomVariable(AbstractDistribution(2)):   X__2 := RandomVariable(AbstractDistribution(2)): end use;
 (1)
 > F := (U1, U2) -> U1/(U1+U2); T := mtaylor(F(X__1, X__2), [X__1=1, X__2=1], 2):
 (2)

Error: x[2] is droped out of the double integral in the rightmost term

 > use IntegrationTools in J := eval([op(expand(T))], [seq(X__||i=x[i], i=1..2)]); L := add(        map(          j ->            if j::numeric then            j          else            (Expand@CollapseNested)(              Int(                j * Statistics:-PDF(X__1, x)                , seq(x[i]=-infinity..+infinity, i=1..2)              )            )          end if          , J        )        ): ET := % end use;
 (3)

I want this

 > 'ET' = 1/2        +        (1/4)*(Int(Int(x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))        -(1/4)*(Int(Int(x[2]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))
 (4)

With int instead of Int one integral is double the other is double-nested

 > L := add(        map(          j ->            if j::numeric then            j          else              int(                j * Statistics:-PDF(X__1, x)                , seq(x[i]=-infinity..+infinity, i=1..2)              )          end if          , J        )        ): ET := %
 (5)

As the expression of ET is now correct, I tried to use IntegrationTools to get the
form I want (equation (4)).

But as soon as I replace int by Int x[2] is again droped out.

So it's not even worth thinking about using CollapseNested!

 > use IntegrationTools in   eval(ET, int=Int);   end use;
 (6)
 >

Download Int_int.mw

## Why is the output of printf delayed?...

Asked by:

When there are print commands in a loop their content is printed as soon as this command is executed.
This is not the case with printf whose displays are delayed (buffered?).
Is there a way to force the display of printf when the command is executed?

TIA

Motivation: I want to display intermediate execution times in a prettier way than print offers.

## System of equation into matrix for each "n"...

Asked by:

Dear Users!

I hope you are doing well. I have the following discretized form

for n>=1 and j=0..M. We obtained the following matrix equation for any "n" and j=0..M as:

I want matrix proc of any useful way to define A^n, u^n, and b^n. I am waiting for your positive response. Thanks in advancs

## Why are the level curves wrong when axis mode is ...

Asked by:

Using plot3d(..., style=surfacecontour, ...) or contourplot3d(...) displays wrong level curves when some axis are switched to a log mode.

Example:

 > restart:
 > interface(version)
 (1)
 > X := (0.4000000000e-4*(-R+80.00))/(R*(0.4e-1+M__a)):
 > plot3d(X, R=0..10, M__a=10^0..10^4, style=surfacecontour, color=gold)
 > plot3d(X, R=0..10, M__a=10^0..10^4, axis[2]=[mode=log], axis[3]=[mode=log], style=surfacecontour, color=gold)
 > plots:-display(   plots:-contourplot3d(X, R=0..10, M__a=10^0..10^4, axis[2]=[mode=log], axis[3]=[mode=log], color=red),   plot3d(X, R=0..10, M__a=10^0..10^4, style=surface, color=gold) )
 >

Download WrongLevelCurves.mw

The problem is not dramatic because there is a workaround.

 > restart:
 > interface(version)
 (1)
 > X := (0.4000000000e-4*(-R+80.00))/(R*(0.4e-1+M__a)):
 > fig := plot3d(X, R=0..10, M__a=10^0..10^4, style=surfacecontour, color=gold): Tr  := plottools:-transform((x, y, z) -> [x, log[10](y), log[10](z)]): plots:-display(Tr(fig), axis[2]=[tickmarks=[seq(i=10^i, i=0..4)]], axis[3]=[tickmarks=[seq(i=nprintf("%1.0e", 10.^i), i=-7..-1)]])
 >

Download WrongLevelCurves_Workaround.mw

## Why does dsolve return a solution with a singular...

Asked by:

I don't understand why the solution of sys_2 isn't those of sys_1 when M__p=1 and M__a=0 ?

Traces of the computation seem to indicate that dsolve proceeds exactly the same for sys_2 and sys_1 .

Please note that sol_1 contains a term of the form t*cos(t) that sol_2 doesn't, thus the question: "Is sol_2 correct?"

Could you help me to fix this?
TIA

 > restart
 > infolevel[dsolve] := 4;
 (1)
 > sys_1 := {diff(x(t), t\$2)=sin(t)-x(t), x(0)=0, D(x)(0)=0}; sol_1 := dsolve(sys_1)
 Methods for second order ODEs: --- Trying classification methods --- trying a quadrature trying high order exact linear fully integrable trying differential order: 2; linear nonhomogeneous with symmetry [0,1] trying a double symmetry of the form [xi=0, eta=F(x)] -> Try solving first the homogeneous part of the ODE    checking if the LODE has constant coefficients    <- constant coefficients successful    -> Determining now a particular solution to the non-homogeneous ODE       building a particular solution using variation of parameters <- solving first the homogeneous part of the ODE successful
 (2)
 > sys_2 := {(M__p+M__a)*diff(x(t), t\$2)=M__p*sin(t)-x(t), x(0)=0, D(x)(0)=0}; sol_2 := dsolve(sys_2)
 Methods for second order ODEs: --- Trying classification methods --- trying a quadrature trying high order exact linear fully integrable trying differential order: 2; linear nonhomogeneous with symmetry [0,1] trying a double symmetry of the form [xi=0, eta=F(x)] -> Try solving first the homogeneous part of the ODE    checking if the LODE has constant coefficients    <- constant coefficients successful    -> Determining now a particular solution to the non-homogeneous ODE       building a particular solution using variation of parameters <- solving first the homogeneous part of the ODE successful
 (3)
 > eval(sol_2, [M__p=1, M__a=0])
 >

Download SomethingWrong.mw

PS: Already, in the following case, dsolve doesn't return the solution of sys_1.

```sys_3 := {(A+B)*diff(x(t), t\$2)=(A+B)*sin(t)-x(t), x(0)=0, D(x)(0)=0};
sol_3 := dsolve(sys_3)
```

If I do this

```sys_4 := {(A+B)*diff(v(t), t)=(A+B)*sin(t)-x(t), diff(x(t), t)=v(t), x(0)=0, v(0)=0}:
sol_4 := dsolve(sys_4)
```

I get a very complex solution wich contains a piecewise function which separates the cases A+B=1 and A+B<>1.
Evaluating sol_4 for A+B=1 gives the same expression than sys_1:

```simplify(eval(sol_4, A=1-B), trig)
/       1                  1          1         \
{ v(t) = - sin(t) t, x(t) = - sin(t) - - cos(t) t }
\       2                  2          2         /
```

Here is a workaround to get the correct solution of sys_2:

```sys_5 := {(M__P+M__A)*diff(v(t), t)=(M__P+C)*sin(t)-x(t), diff(x(t), t)=v(t), x(0)=0, v(0)=0}:
sol_5 := dsolve(sys_5):
simplify(eval(sol_5, [M__P=1, M__A=0, C=0]), trig)
/       1                  1          1         \
{ v(t) = - sin(t) t, x(t) = - sin(t) - - cos(t) t }
\       2                  2          2         /
```

e

## How to setup pacemaker and Corosync to maple work?...

Asked by:

Can pacemaker and corosync work with maple?

How to setup pacemaker and Corosync to maple work in Amazon EC2?

i had only one installed License in linux

how to make it work in clusters ?

what is the difference with supercomputing in Amazon ?

which consulting company in Hong Kong can help to use supercomputing in Amazon in my case ? I would like to run batch of batch total 100 script running maple in one instance , but total numbers need to run around 60 years. Any consultant to calculate and setup this supercomputing or pacemaker to make calculations into one day or a few days ?

## How can i see maple calculations?...

Asked by:

How can i see analytical maple calculations?

## Solve command Issue due to Computational Cost...

Asked by:

Hello Everyone;

Hope you are fine. I am solving system of odes using rk-4 method. For this purpose I formulate the "residual" (on maple file) which is further function of "x" and "y". With the help of discritization point further I convert "residual" into system of ode's. Then i used "sys111 := solve(odes_Combine, `~`[diff](var, t))" to simplify the system. Finnally i applied RK-1. Code is pasted and attached. This all process is for "N=4". When i increase the value of "N", number of Odes increase accordingly. With increasing value of "N" the comand "sys111 := solve(odes_Combine, `~`[diff](var, t))" taking a lot of time due to heavy computation. Is that any way to proceed without this comand for rk-1?

Question1.mw

 >
 (1)
 >
 >
 (2)
 >
 >
 >
 >
 (3)
 >
 >
 >
 >
 >
 >

Download Question1.mw

## Numerical Scheme for Integro-differential equation...

Asked by:

Hello;

Hope you are fine. Can i apply numerical scheme on maple for the following problem. This in integro-differential equation i think. Waiting for kind response.

Thanks

## How to declare variables local with assign?...

Asked by:

I need to declare a whole set of variables as local. The variable names are generates algorithmically using assign. Like so:

`seq(seq(assign(cat(S,i,j)=Vector(datatype=float)),i=1..9),j=1..9);`

Stand-alone, this works and creates all these Vectors for later use. But this:

`local seq(seq(assign(cat(S,i,j)=Vector(datatype=float)),i=1..9),j=1..9);`

does not work; I get an "error; '(' unexpected".

I really do not want to type all these by hand... on the other hand, if I do not declare these as local I get 99 warnings about implicit local declaration; not nice.

Is there a way to do this?

Thanks,

M.D.

PS: I do not upload as the one line really is all that is needed. At the lowest level one does not get the implicit-declaration warning, but with "local" it still fails.

 1 2 3 4 5 6 7 Last Page 1 of 72
﻿