Maple 2015 Questions and Posts

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

Hi!

I am using a proceure to conpute de integral of a function by he Simpson's rule. My function is defined from a function and a procedure, but I am getting the error  "Error, (in w) invalid input: hfun2 expects its 1st argument, t, to be of type numeric, but received (1/10)*i+1/20"

As you can see in the attaxhed file, I have tried several ways to compute the integral but always returns the above error. Please, can yo help me?

Thanks

forum.mw

Hi Dear,

I hope everyone is fine here. In the attached file, I have generated a square matrix "Q" using two-dimensional polynomials. The dimension of the square matrix "Q" depends on M1 and M2 parameters. In my simulation, sometimes I need this matrix of 1000 by 1000 dimensions. Using the attached method, it took a lot of time to compute two-dimensional polynomials and then to compute the general square matrix "Q." I wanted to write this matrix using proc (procedures). Maybe by using this way, I don't need to compute the polynomials, and it took less time to compute the square matrix "Q." I know how to generate a matrix using proc when its dimension depends on one parameter. However, here, the dimension of matrix "Q" depends on two parameters, M1 and M2. So, I am a little bit confused about how to adjust them in proc. Please see the attached file and share your useful ideas. 

help.mw

Thanks in advance

Hi
I hope you are doing well. I have plotted (in the attached file) the contour plot of the function and its density plot; both have the same behavior but different appearances (error in direction may be rotation needs to apply). I don't know why it happens because this code works well for other solutions. Kindly have a look and fix the issue. I shall be waiting for your positive response. Please take care.
Help.mw

It seems that Maple needs more help than necessary:

restart:

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

expr:= A+B*limit(f(x), x=+infinity);
eval(expr, limit(f(x), x=+infinity)=1)

A+B*(limit(f(x), x = infinity))

 

A+B

(2)

expr:= A+B*limit(2*f(x), x=+infinity);

eval(expr, limit(f(x), x=+infinity)=1);     # Shouldn't this return A+2*B
eval(expr, limit(2*f(x), x=+infinity)=2);   # Can I avoid doing this?

A+B*(limit(2*f(x), x = infinity))

 

A+B*(limit(2*f(x), x = infinity))

 

A+2*B

(3)

expr:= A+B*limit(f(x)^2, x=+infinity);

eval(expr, limit(f(x), x=+infinity)=1);     # Shouldn't this return A+B
eval(expr, limit(f(x)^2, x=+infinity)=1);   # Can I avoid doing this?

A+B*(limit(f(x)^2, x = infinity))

 

A+B*(limit(f(x)^2, x = infinity))

 

A+B

(4)

expr:= A+B*limit(2*f(x)^2, x=+infinity);

eval(expr, limit(f(x)^2, x=+infinity)=1);    # Shouldn't this return A+2*B
eval(expr, limit(2*f(x)^2, x=+infinity)=2);  # Can I avoid doing this?

A+B*(limit(2*f(x)^2, x = infinity))

 

A+B*(limit(2*f(x)^2, x = infinity))

 

A+2*B

(5)
 

 

Download limits.mw

Why don't the commands labelled "Shouldn't this return.." do the job?

TIA

I have an expression equal to the sum of N terms of the form Int(fn=1..N(x), x) and I want to replace each fn(x) by its Taylor (or series) expansion.

When the integrals are definite, like J1 below, I can easily obtain a new expression (K1) where the integrand has been replaced by some expansion.
But when the integral is indefinite, like J2, I get an evaluated expression for K2.

It seems I have to do some gymnastic (J3 --> K3) to get what I want

restart

J1 := Int(sin(p*x), x=0..1);
K1 := eval(J1, Int = ((a, b) -> Int(mtaylor(a, x=0, 5), b)));

Int(sin(p*x), x = 0 .. 1)

 

Int(p*x-(1/6)*p^3*x^3, x = 0 .. 1)

(1)

# undefined integration

J2 := Int(sin(p*x), x);

`Expected result` = Int(p*x-(1/6)*p^3*x^3, x);

K2 := eval(J2, Int = ((a, b) -> Int(mtaylor(a, x=0, 5), b)));

Int(sin(p*x), x)

 

`Expected result` = Int(p*x-(1/6)*p^3*x^3, x)

 

eval(Int(sin(p*x), x), {Int = (proc (a, b) options operator, arrow; Int(mtaylor(a, x = 0, 5), b) end proc)})

(2)

# undefined integration using Intat

J3 := Intat(op(1, J2), op(2, J2)=y);
eval(%, Intat = ((a, b) -> Intat(mtaylor(a, x=0, 5), b))):

K3 := IntegrationTools:-Change(convert(%, Int), y=x, x)

Intat(sin(p*x), x = y)

 

Int(p*x-(1/6)*p^3*x^3, x)

(3)
 

 

Download Integration.mw

Why do I get this unevaluatedform for K2?
Do I have to use Intat to get K3?

Thanks in advance


For years I observe that package orthopoly is not considered as a package within a procedure.
Finally I have decided to ask for clarifications: Can someone explain me why procedure f generates an error?
 

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)


Without any procedure

restart

H(2, x)

H(2, x)

(2)

with(orthopoly):

H(2, x)

4*x^2-2

(3)


Within a procedure

restart

type(orthopoly, package)

true

(4)

f := proc(m)
  uses orthopoly:
  H(m, x)
end proc:

Error, `orthopoly` is not a module or member

 

g := proc(m)
  orthopoly:-H(m, x)
end proc:

g(2)

4*x^2-2

(5)

 


Download meaning.mw

TIA

 


This post is inspired by minhthien2016's question.

The problem, denoted 2/N/1, for reasons that will appear clearly further on, is to pack N disks into the unit square in such a way that the sum of their radii is maximum.

I replied this problem using Optimization-NLPSolve for N from 1 (obvious solution) to 16, which motivated a few questions, in particular:

  • @Carl Love: "Can we confirm that the maxima are global (NLPSolve tends to return local optima)?
    Using NLPSolve indeed does not guarantee that the solution found is the (a?) global maximum. In fact packing problems are generaly tackled by using evolutionnary algorithms, greedy algorithms, or specific heuristic strategies.
    Nevertheless, running NLPSolve a large number of times from different initial points may provide several different optima whose the largest one can be reasonably considered as the global maximum you are looking for.
    Of course this may come to a large price in term of computational time.

     
  • @acer: "How tight are [some constraints], at different N? Are they always equality?"
    The fact some inequality constraints type always end to equality constraints (which means that in an optimal packing each disk touches at least one other annd, possibly the boundary of the box) seems hard to prove mathematically, but I gave here a sketch of informal proof.



I found 2/N/1 funny enough to spend some time digging into it and looking to some generalizations I will refer to as D/N/M:  How to pack N D-hypersheres into the unit D-hypercube such that the sum of the M-th power of their radii is maximum?
For the sake of simplicity I will say ball instead of disk/sphere/hypersphere and box instead of square/cube/hypercube.

The first point is that problems D/N/1 do not have a unique solution as soon as N > 1 , indeed any solution can be transformed into another one using symmetries with respect to medians and diagonals of the box. Hereafter I use this convention:

Two solutions and s' are fundamental solutions if:

  1. the ordered lists of radii and s'  contain are identical but there is no composition of symmetries from to s',
  2. or, the ordered lists of radii and s'  contain are not identical.
     

It is easy to prove that 2/2/1 and 3/2/1, and likely D/2/1, have an infinity of fundamental solutions: see directory FOCUS__2|2|1_and_3|2|1 in the attached zip file..
At the same time 2/N/2, 3/N/3, and likely D/N/D, have only one fundamental solution (see directory FOCUS__2|N|2 for more details and a simple way to characterize these solutions

 (Indeed the strategy ito find the solution of D/N/D  in placing the biggest possible ball in the largest void D/N-1/D contains. Unfortunately this characterization is not algorithmically constructive in the sense that findind this biggest void is a very complex geometrical and combinatorial problem.
 it requires finding the largest void  in a pack of balls)


Let Md, 1(N)  the maximum value of the sum of balls radii for problem d/N/1.
The first question I asked myself is: How does Md, 1(N) grows with N?

 

(Md, 1(N) is obviously a strictly increasing function of N: indeed the solution of problem d/N/1 contains several voids where a ball of strictly positive radius can be placed, then  Md+1, 1(N) > Md, 1(N) )


The answer seems amazing as intensive numerical computations suggest that
                                      

See D|N|M__Growth_law.mw in the attached sip file.
This formula fits very well the set of points  { [n, Sd, 1(n) , n=1..48) } for d=2..6.
I have the feeling that this conjecture might be proven (rejected?) by rigourous mathematical arguments.


Fundamental solutions raise several open problems:

  • Are D/2/1 problems the only one with more than one fundamental solutions?

    The truth is that I have not been capable to find any other example (which does not mean they do not exist).
    A quite strange thing is the behaviour of NLPSolve: as all the solutions of D/2/1 are equally likely, the histogram of the solutions provided by a large number of NLPSolve runs from different initial points is far from being uniform.
    F
    or more detail refer ro directory FOCUS__2|2|1_and_3|2|1
     in the attached zip file
    I do not understand where this bias comes from: is it due to the implementation of SQP in NLPSolve, or to SQP itself?

     
  • For some couples (D, N) the solution of D/N/1 is made of balls of same radius.
    For N from 1 to 48 this is (numerically)
     the case for 2/1/1 and2/2/1, but the three dimensional case is reacher as it contains  3/1/13/2/1,  3/3/1,  3/4/1 and 3/14/1 (this latter being quite surprising).
    Is there only a finite number of values 
    N such that D/N/1 is made of balls with identical radii?
    If it is so, is this number increasing with
     D?
    It is worth noting that those values of
    N mean that the solution of problems D/N/1 are identical to those of a more classic packing problem: "What is the largest radius N identical balls packed in a unit bow may have?".
    For an exhaustive survey of this latter problem see
    Packomania.

     
  • A related question is "How does the number of different radii evolves as N increases dor given values of D and M?
    Displays of 2D and 3D packings show that the set of radii has significantly less elements than
    N... at least for values of N not too large. So might we expect that solution of, let us say, 2/100/1 can contain 100 balls of 10 different radii, or it is more reasonable to expect it contains 100 balls of 100 different radii?

     
  • At the opposite numerical investigations of  2/N/1 and  3/N/1 suggest that the number of different radii a fundamental solution contains increases with N (more a trend than a continuous growth).
    So, is it true that very large values of N correspond to solutions where the number of different radii is also very large?

    Or could it be that the growth of the number of different radii I observed is simply the consequence of partially converged results?
     
  • Numerical investigations show that for a given dimension d and a given number of balls n,  solutions of d/n/1 and d/n/M (1 < M < d) problems are rather often the same. Is this a rule with a few exceptions or a false impression due to the fact that I did not pushed the simulations to values of n large enough to draw a more solid picture)?


It is likely that some of the questions above could be adressed by using a more powerful machine than mine.


All the codes and results are gathered in  a zip file you can download from OneDrive Google  (link at the end of this post, 262 Mb, 570 Mb when unzipped, 1119 files).
Install this zip file in the directory of your choice and unzip it to get a directory named
PACKING
Within it:

  • README.mw contains a description of the different codes and directories
  • Repository.rtf must contain a string repesenting the absolute path of directory PACKING


Follow this link OneDrive Google

Hi,

I hope everyone is fine here. I want to write the following nested loop in my code

restart; TOL := 10^(-3); v[i] := 10^(-4); u[i] := 10^(-4);
if abs(v[i]-1)<=TOL then    if abs(u[i])<=TOL then break    else t[i+1]:=t[i]+alpha; else; fi; fi;

it is not working. If the first condition (v[i]-1)<=TOL is fulfilled, then we have to check the second condition, u[i]<=TOL. That’s why I don’t use “and” here. If both conditions are fulfilled, then stop the loop and if second the condition not fulfilled (but first fulfill) then t[j+1]=t[j]+alpha. 

I shall be waiting for your positive response.


Why sorting these 4 vectors wrt L(+oo) norm returns a correct result bur sorting them wrt L2 norm doesn't (unless if I evaluate the norms as floats)?
 

restart:

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

V := [seq(LinearAlgebra:-RandomVector(2, generator=1..10), k=1..4)];

N2   := evalf(norm~(V, 2));
Ninf := norm~(V, +infinity);

V := [Vector(2, {(1) = 3, (2) = 5}), Vector(2, {(1) = 8, (2) = 7}), Vector(2, {(1) = 4, (2) = 5}), Vector(2, {(1) = 6, (2) = 2})]

 

[5.830951895, 10.63014581, 6.403124237, 6.324555320]

 

[5, 8, 5, 6]

(2)

Sorting wrt L(+oo) norm

sort(V, key=(t -> norm(t, +infinity)));  # correct

[Vector(2, {(1) = 3, (2) = 5}), Vector(2, {(1) = 4, (2) = 5}), Vector(2, {(1) = 6, (2) = 2}), Vector(2, {(1) = 8, (2) = 7})]

(3)

Sorting wrt L(2) norm

sort(V, key=(t -> norm(t, 2))); # not correct
is(norm(V[4], 2) < norm(V[3], 2));

[Vector(2, {(1) = 3, (2) = 5}), Vector(2, {(1) = 4, (2) = 5}), Vector(2, {(1) = 8, (2) = 7}), Vector(2, {(1) = 6, (2) = 2})]

 

true

(4)

sort(V, key=(t -> evalf(norm(t, 2)))); # correct

[Vector(2, {(1) = 3, (2) = 5}), Vector(2, {(1) = 6, (2) = 2}), Vector(2, {(1) = 4, (2) = 5}), Vector(2, {(1) = 8, (2) = 7})]

(5)

 


 

Download SortingVectors.mw


TIA

I have a surface defined by C(x, y, x) = 0 that I visualize with implicitplot3d.
Using shading=shue does not suits me and I would like to define my own coloring function F(x, y, z).

The first error I got made me think that a coloring function cannot depend on 3 parameters.
But a simpler (and not visually satysfying function) F(x, y) already leads to an error, which makes me wonder if it is possible to use a colorig function with  implicitplot3d?

implicitplot3d_coloring.mw

Thanks in advance

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

_R

(1)

[Mean, Variance](A);

[mu[1], sigma[1]^2]

(2)

Mean(p*A+q);
Mean(p*(A+q))

p*mu[1]+q

 

p*(mu[1]+q)

(3)

# But

Mean(A-q);
Mean(A/p)

FAIL

 

FAIL

(4)
 

 

Download Mean_operator.mw

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

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

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.

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