Maple 2015 Questions and Posts

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

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. 

Here is an example where evalf[n] doesn't operate on the argument of the undefined function f.

x := rand(0. .. 1.)()
                          0.2342493224
y := x+f(x):
evalf[4](y)
                    0.2342 + f(0.2342493224)

# but, as soon as f is a known function:
evalf[4](cos(x))
                             0.9727


Here is a way to force evalf[4](f(x)) to return f(0.2342)?

I found only two ways to do this:
First: declare interface(displayprecision=4) 

interface(displayprecision=4):
y;
                 0.2342 + f(0.2342)

Or: do this (which is relatively cumbersome)

Evalf := proc(expr, n)
  local i := [indets(evalf[n](expr), numeric)[]]:
  eval(expr, i =~ evalf[4](i))
end proc:

Evalf(y, 4)
                 0.2342 + f(0.2342)

Thanks in advance.

PS:  I do not like setting displayprecision to some value because its effect is remnant: if you execute again the same worksheet (begining with a restart), the value of displayprecision is not reset to 10 but keeps the value you gave it previously, somewhere in the worksheet.

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.



In case this error has been corrected in more recent versions, please feel free to delete this question.

In the felp page relative to anames this example is given

restart:
test1 := 1: test2 := 2: test3 := 3.2: testall := 3.2:
select(type,{anames()},suffixed(`test`));
                 {test1, test2, test3, testall}

Note the backward quotes in suffixed(`test`).
This works only if test is not an assigned name itself:

restart:
test := 0: test1 := 1: test2 := 2: test3 := 3.2: testall := 3.2:
select(type,{anames()},suffixed(`test`));
Error, (in type/suffixed) expecting a 1st argument of type {string, symbol, list(symbol, string), set(symbol, string)}

With simple quotes:

select(type,{anames()},suffixed('test'));
              {test, test1, test2, test3, testall}

 

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;

proc (N) Statistics:-Distribution(Statistics:-PDF = (proc (x) options operator, arrow; varphi(seq(x[n], n = 1 .. N)) end proc)) end proc

 

_R

 

_R0

(1)

F := (U1, U2) -> U1/(U1+U2);
T := mtaylor(F(X__1, X__2), [X__1=1, X__2=1], 2):

proc (U1, U2) options operator, arrow; U1/(U1+U2) end proc

(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;

[1/2, (1/4)*x[1], -(1/4)*x[2]]

 

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

 

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

(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))

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 := %

1/2+int(int((1/4)*x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity)+int(-(1/4)*x[2]*(int(varphi(x[1], x[2]), x[1] = -infinity .. infinity)), x[2] = -infinity .. infinity)

(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;

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

(6)

 

Download Int_int.mw

A case where simplify(...) and simplify~(...) both return the wrong result.
Should we consider this a simplify bug?

restart:


A simple case

J := Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity)
     *
     Int(r[2]^2*varphi[2](r[2]), r[2] = -infinity .. infinity)

(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[2]^2*varphi[2](r[2]), r[2] = -infinity .. infinity))

(1)

# OK

op(1, J) = simplify(op(1, J))

Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity) = Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity)

(2)

# OK

op(2, J) = simplify(op(2, J))

Int(r[2]^2*varphi[2](r[2]), r[2] = -infinity .. infinity) = Int(r[2]^2*varphi[2](r[2]), r[2] = -infinity .. infinity)

(3)

# But...
#
# Not OK

simplify(J)

(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[1]^2*varphi[2](r[1]), r[1] = -infinity .. infinity))

(4)

# Not OK

simplify~(J)

(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[1]^2*varphi[2](r[1]), r[1] = -infinity .. infinity))

(5)

# OK

map(simplify, J)

(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[2]^2*varphi[2](r[2]), r[2] = -infinity .. infinity))

(6)


A slightly more complex case

J := (Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[2]^2*varphi[2](r[2]), r[2] = -infinity .. infinity))-(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[2]*varphi[2](r[2]), r[2] = -infinity .. infinity))^2;

(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[2]^2*varphi[2](r[2]), r[2] = -infinity .. infinity))-(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[2]*varphi[2](r[2]), r[2] = -infinity .. infinity))^2

(7)

is(J=simplify(J))

false

(8)

is(J=simplify~(J))

false

(9)

is(J=map(simplify, J));
map(simplify, J);

false

 

(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[1]^2*varphi[2](r[1]), r[1] = -infinity .. infinity))-(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[1]*varphi[2](r[1]), r[1] = -infinity .. infinity))^2

(10)

add(map(u -> map(simplify, u), [op(J)]));

is(J=%);

(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[2]^2*varphi[2](r[2]), r[2] = -infinity .. infinity))-(Int(r[1]^2*varphi[1](r[1]), r[1] = -infinity .. infinity))*(Int(r[2]*varphi[2](r[2]), r[2] = -infinity .. infinity))^2

 

true

(11)

 

Download Simplify_is_wrong.mw

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.

Is it possible to enlarge the sliders in Explore(plot(...), ...) and increase their "resolution" (meaning to have a higher precision when the slider is moved)?
If Maple does offer this option, could you tell me from what version this is the case

TIA

Hi Users!

I hope everyone is fine here. I have plotted the density plot below:

restart; Digits := 20; with(LinearAlgebra); with(plots); N := 20; Mx := 20; L := 1; `&Delta;x` := L/Mx; T := 2; `&Delta;t` := T/N; for i from 0 while i <= Mx do u[i, 0] := 0 end do; for n from 0 while n <= N do u[0, n] := 0; u[Mx, n] := 0 end do; for n from 0 while n <= N-1 do for i while i <= Mx-1 do Ru[i, n] := eval((u[i, n+1]-u[i, n])/`&Delta;t` = (u[i+1, n+1]-2*u[i, n+1]+u[i-1, n+1])/`&Delta;x`^2-u[i, n+1]+.5) end do; Sol[n] := fsolve({seq(Ru[i, n], i = 1 .. Mx-1)}); assign(op(Sol[n])) end do;

Digits := 10; NP := 100; XX := [seq(seq(i1/Mx, i1 = 0 .. Mx), i2 = 0 .. N)]; TT := [seq(seq(i2, i1 = 0 .. Mx), i2 = 0 .. N)]; ZZ := [seq(seq(u[i1, i2], i2 = 0 .. N), i1 = 0 .. Mx)]; interfunc := subs(__M = Matrix(Matrix(Mx+1, N+1, ZZ), datatype = float[8]), proc (x, y) options operator, arrow; CurveFitting:-ArrayInterpolation([[`$`(i1, i1 = 0 .. Mx)], [`$`(i2, i2 = 0 .. N)]], __M, [[x], [y]], method = cubic)[1, 1] end proc); newz := CurveFitting:-ArrayInterpolation([[`$`(i1, i1 = 0 .. Mx)], [`$`(i2, i2 = 0 .. N)]], Matrix(Mx+1, N+1, ZZ, datatype = float[8]), [[seq(Mx*(i3-1)/(NP-1), i3 = 1 .. NP)], [seq(N*(i3-1)/(NP-1), i3 = 1 .. NP)]], method = cubic); nminz, nmaxz := (min, max)(newz); C := .666*(1-ImageTools:-FitIntensity(newz)); PC := PLOT(GRID(0 .. Mx, 0 .. N, newz, COLOR(HUE, C)), STYLE(PATCHNOGRID)); numcontours := 15; PP := (proc (P) options operator, arrow; (op(0, P))(op(P), ROOT(BOUNDS_X(0), BOUNDS_Y(0), BOUNDS_WIDTH(600), BOUNDS_HEIGHT(500))) end proc)(plots:-display(PC, plots:-contourplot(interfunc, 0 .. Mx, 0 .. N, thickness = 0, contours = [seq(nminz+(nmaxz-nminz)*(i3-1)/(numcontours+2-1), i3 = 1 .. numcontours+2)]), seq(plot(ZZ[1], nminz .. nminz, thickness = 15, color = COLOR(HUE, .666*(1-i3/(numcontours+1))), legend = sprintf(" %.3f", nminz+i3*(nmaxz-nminz)/(numcontours+1))), i3 = numcontours+1 .. 0, -1), legendstyle = [location = right, font = [Helvetica, 14]], font = [Helvetica, 16], labelfont = [Helvetica, bold, 16], labels = [x, t], labeldirections = [horizontal, vertical]));
plots[display](PP, size = [500, 400]);

Here the t-axis is from 0 to 20 but its actual value is from 0 to 2 and the x-axis is from 0 to 20 but its actual value is from 0 to 2. How can I change the axis? Moreover, I used the following way to extract the data in a dat file to plot the function (say f) in some professional software.

with(plots); f := plot(sin(x), x = -Pi .. Pi); dat1 := `~`[plottools:-getdata]([f]); for i while i <= 1 do A[i] := dat1[i, 3]; Y[i] := A[i][1 .. -1, 2] end do; X := A[1][1 .. -1, 1]; MM1 := `<|>`(X, `$`(Y[j2], j2 = 1 .. 1)); ExportMatrix("C:/Users/Usman/Desktop//Graph f.dat", MM1);

How I can, I extract data in the form of a dat file to plot in some professional software? 

(I would prefer a solution for Maple 2015, but answers relative to newer versions are welcome)

Is there a simple way to force the result -y(1) + y(2) without using one of these two tricks?

# how can I get the expression of
int(diff(y(x), x), x=1..2);
                      / d                  \
                   int|--- y(x), x = 1 .. 2|
                      \ dx                 /

# Trick 1
int(diff(y(x), x), x);
eval(%, x=2)-eval(%, x=1)
                              y(x)
                          -y(1) + y(2)

# Trick 2
J := Int(diff(y(x), x), x = 1..2): 
value(IntegrationTools:-Parts(J, 1));
                          -y(1) + y(2)

TIA

Dear Users!

I hope everyone is fine. I want to plot the following sequence in 3d for t=0..1 and x=-pi..pi;

[0., 0.4995839572e-1*sin(x), 0.9966865249e-1*sin(x), .1488899476*sin(x), .1973955598*sin(x), .2449786631*sin(x), .2914567945*sin(x), .3366748194*sin(x), .3805063771*sin(x), .4228539261*sin(x), .4636476090*sin(x), .5028432109*sin(x), .5404195003*sin(x), .5763752206*sin(x), .6107259644*sin(x), .6435011088*sin(x), .6747409422*sin(x), .7044940642*sin(x), .7328151018*sin(x), .7597627549*sin(x), .7853981634*sin(x)];

In the sequence first entry (0) for t=0, second (0.4995839572e-1*sin(x)) for t=0.05, third (0.9966865249e-1*sin(x)) for t= 0.1 and so on the last entry (.7853981634*sin(x)) for t=1. In addition, how do I plot if the number of points exceeds in the sequence for example 100 or 1000 points, but the difference between two consecutive values for t is the same here the difference is Delta*t=0.05.

Note: I would -prefer an answer for Maple 2015, but I can accommodate an answer for a more recent version.

I have a function Gpdf from IR2 to IR+ of class C1 (this comes from the way this function is built).
Although its level curves are continuous, their display show discontinuities for some level values. 

The reason is that  Gpdf contains a term whose denominator vanishes and so, even if the left and right limits of Gpdf are the same at the vanishing point, the resulting plot is dicontinuous.

More details are given in the attached file Discontinuous_contours.mw.

I have tried to adjust the plotting grid, or even to superimpose contours drawn in domains containing no singularities, but I wasn't capable to get continuous drawings (see the attached file).

Do you have any idea to achieve this?

TIA

Hi!

I have M number of linear differential equations. I have solved this system using the 1,2,3,4 stag RK method in the attached file but did not find a significant difference in the accuracy. Kindly see what's wrong there. 

Thank you!

s-stage.mw

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

Dear Users!

I hope everyone is fine here. I have three vectors say V[1], V[2] and V[3] as:

restart; with(LinearAlgebra); with(linalg);
V[1] := Vector([3, 2, -4]);
V[2] := Vector([1, 2/3, 7]);
V[3] := Vector([-9, 0, 1/2]);

I can define a Vector V have V[1], V[2] and V[3] using blockmatrix command as:

C := blockmatrix(3, 1, [V[1], V[2], V[3]]);

My question is that how I can extract vectors V[1], V[2] and V[3] from C? Thanks in advance

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