Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Hi there.

It seems like EllipticCPi(n,k) has a bug when n close to 1:

Both answers should be equal by definition and first is true.

ell_error.mw

I have the following program in Maple:

with(plots);
my_array := [[.1, .1], [.3, .45], [.55, .78], [.8, .9]]; #define an array of points
my_graph := pointplot(my_array, connect = true); #plot the array on a graph, connecting points
line := plot(.7, x = 0 .. 1); #plotting a horizontal line
display(my_graph, line); #displaying on the same graph

The output looks as follows:

 

I want to add a vertical line corresponding to the intersection of these two lines. Is there a way to do it?

Hi,

I have two coupled algebraic equations (not differential equations; but only simple algebraic equations; call them "equ1" and "equ2") in which there are three parameters: "x", "y", and "z".

I want to use "fsolve" (Numerical solve) for solving them and then plotting. But since there are three parameters and two equations hence one of the parameters must be given. I want to give a range for "z", for example [2..9], and step size, for example "0.5", such that maple first puts "2" in both equations and solve them numerically and get the values of "x" and "y" and then record them, and then set the value "2.5" for "z" and again repeat the above cycle until the value "z=9". Finally plot both "x" and "y" in terms of "z".

How do I write this?

Thanks in advance

hello dear fellows maple users,

I need help to find a relation between multiples expressions (A,B..etc) and one term (R). (otherwise, I want to write those expressions in terms of R).

#A is given by

A:=nu^(2/3)*B/(g^(1/3)*(sin(beta))^(1/3)*h):

#and R is defined as:

R:=h^3*g*sin(beta)/(3*nu^2):

I hope I expressed myself clearly.

thank you for any help you can offer.

Is there any way to use DIFF for the function formula in IF..THEN..?

g := proc(x) if x <= 0 then x^2 + x; else if x < 3*Pi then sin(x); else x^2 - 6*x*Pi + 9*Pi^2 - x + 3*Pi; end if; end if; end proc;

diff(g, x);
                              

Like the above example, but the diff result is 0.....

Vector calculus is very nicely handled in Maple's Physics package:

with(Physics[Vectors]):

The gradient of a scalar field in Cartesian coordinates

Gradient(f(x,y,z));

(diff(f(x, y, z), x))*_i+(diff(f(x, y, z), y))*_j+(diff(f(x, y, z), z))*_k

The gradient of a scalar field in cylindrical coordinates

Gradient(f(rho,phi,z));

(diff(f(rho, phi, z), rho))*_rho+(diff(f(rho, phi, z), phi))*_phi/rho+(diff(f(rho, phi, z), z))*_k

But the gradient of a vector field is not available:

Gradient(_rho*f(rho,phi,z) + _phi*g(rho,phi,z) + _k*h(rho,phi,z));

Error, (in Physics:-Vectors:-Nabla) Physics:-Vectors:-Gradient expected a scalar function, but received the vector function: _rho*f(rho, phi, z)+_phi*g(rho, phi, z)+_k*h(rho, phi, z)

I suppose this is because the gradient of a vector field needs to be
expressed in terms a basis consisting of the dyadic products  of the basis vectors

as in _i  _j, _rho_phi, etc., which does not seem to be implemented.

 

That said, it is quite possible that this is already done and I have missed it in
the documentation since the Physics package is so huge.  But if it's truly not there,
it would be a very useful feature to add.  Calculating gradients of vector fields

is central to continuum mechanics (including elasticity and fluid mechanics).

They are easy to represent in Cartesian coordinates but their calculation in the

frequently needed cylindrical and spherical coordinates are nontrivial and can use

Maple's help.

 

Hi,

 

I want my vector field plot to have more arrows, and am wondering how to do this.  Here is the file:

How_to_add_more_arrows.mw

 

Thanks in advance!

 

The changecoords command in the procedure below executes the plots:-changecoords command despite the preceding unwith(plots) command.

How can I execute the non-plot version of the changecoords command in the procedure. It would be very inconvenient of all the various commented plot commands had to be preceded by plots:-

restart; with(plots):   # first command in the worksheet


  # many statements executing various plot commands

 
P := proc()

unwith(plots):

changecoords([x, y, z], [x, y, z], spherical):

with(plots):

end proc:


P();
Error, (in plots/changecoords) changecoords does not accept plot options or other additional arguments
 

  # many more statements executing various plot commands

 

 # last command in the worksheet

Hello everybody

In a course on numerical calculation in seismology (with jupyter notebook but I tried to adapt them in Maple), we use the Lagrangian interpolation:

First, have done the calculation and get the right answer. But I had to do it manually in Maple (see document below for the question and my solution. The question is describe more explicitly. What I want to do is to make Maple do it automatically and taking into account that there is the restriction i<>j. Then when the lagrangian is calculated, it will be easy to calculate u bar.

Thank you in advance for your help.

Mario

Lagrange_interpolation.mw

I got some planar graphs and I 'd like show their planar drawing. But the graph layout displayed by maple may not so balanced.

In the example below, we can see that the area of ​​the triangle 678 is too small, vertices 9, 10, 11 are crowded inside. I need to reduce the vertex size to better show it. Three vertices, say 9,10,11, in following planar drawing are not the right size.

with(GraphTheory):
d:=ConvertGraph("J|tZHkD@gF_"):
DrawPlanar (d, stylesheet=[ ],font=["Courier",10])

 

 

 

 

 

 

Vertexpadding doesn’t seem to help with vertex size reduction.

Ps:The algorithm used is Tutte's spring (or rubber) method. 

 

Maybe there is a better solution.

If we don’t adjust the vertex size, I don’t know if there is any other solution to improve the overall layout. It is best not to appear crowded.

 

I am solving this question :the line joining the ends of 2 rectangular diameters of an ellipse, remains tangent to a fixed circumference. My code is :

restart; with(geometry); with(plots); unprotect(O);
_EnvHorizontalName := x; _EnvVerticalName := y;
ell := x^2/a^2+y^2/b^2 = 1;
a := 5; b := 3; alpha := (1/6)*Pi; p := sqrt(a^2*b^2/(a^2+b^2));
PQ := x*cos(alpha)+y*sin(alpha)-p; drPQ := solve(PQ, y);
OPQ := x^2/a^2+y^2/b^2-((x*cos(alpha)+y*sin(alpha))/p)^2;
sol := solve({OPQ, ell}, {x, y}, explicit); P := [subs(sol[1], x), subs(sol[1], y)]; Q := [subs(sol[3], x), subs(sol[3], y)];
O := [0, 0];
Ell := implicitplot(ell, x = -a .. a, y = -b .. b, color = red);
DrOPQ := implicitplot(OPQ, x = -a .. a, y = -b .. b, color = magenta, numpoints = 5000);
DrPQ := plot(drPQ, x = -6 .. 6, color = green);
line(OP, 2*x-y); line(OQ, -(1/2)*x-y);

Points := pointplot([O[],P[],Q[]], symbol = solidcircle, color = red, symbolsize = 10):

T := textplot([[O[], "O"],[P[],"P"],[Q[],"Q"]], font = [times, 15], align = {below, right}):
cir := x^2+y^2 = p^2;
Cir := implicitplot(cir, x = -a .. a, y = -b .. b, color = black);
display([Ell, Cir, DrPQ, DrOPQ, Points, T], view = [-6 .. 6, -4 .. 6], axes = normal, scaling = constrained);
Fig := proc (k) local alpha, PQ, drPQ, DrPQ, OPQ, DrOPQ, sol, P, Q, Points, T; global a, b, p, ell, Ell, Cir; alpha := k; PQ := x*cos(alpha)+y*sin(alpha)+p; drPQ := solve(PQ, y); OPQ := x^2/a^2+y^2/b^2-(x*cos(alpha)+y*sin(alpha))^2/p^2; sol := solve({ell, OPQ}, {x, y}, explicit); P := [subs(sol[1], x), subs(sol[1], y)]; Q := [subs(sol[3], x), subs(sol[3], y)]; Points := pointplot([P[], Q[]], symbol = solidcircle, color = red, symbolsize = 10);
T := textplot([[P[], "P"], [Q[], "Q"]], font = [times, 15], align = {below, right}); DrPQ := plot(drPQ, x = -6 .. 6, color = green);µ DrOPQ := implicitplot(OPQ, x = -a .. a, y = -b .. b, color = magenta, numpoints = 5000);
display([Ell, Cir, DrPQ, DrOPQ, Points, T], view = [-a .. a, -b .. b], axes = normal, scaling = constrained) end proc;

Fig((1/4)*Pi);
Error, (in Fig) invalid subscript selector
nframes := 100; plots:-display([seq(Fig(2*Pi*i/nframes), i = 0 .. nframes)], insequence, scaling = constrained);
Error, (in Fig) invalid subscript selector
Explore(Fig(n), n = 0 .. 2*Pi);
Thank you for your help.

Can anyone please help with this?  I don't know what is the problem in this code.

 

restart; _EnvExplicit := true; with(DEtools); with(PDEtools); with(plots)

true

(1)

NULL

Check*the*constraint

eq1 := diff(X(z), z, z)+((diff(H(z), z))/H(z)-2/(1+z))*(diff(X(z), z))+exp(-sqrt(2/3)*X(z))*ZETA*(diff(Y(z), z))^2/(2*sqrt(6))-Y(z)*exp(-sqrt(2/3)*X(z))*(1-exp(-sqrt(2/3)*X(z)))/(2*H(z)^2*sqrt(6)*(1+z)^2) = 0

eq2 := diff(Y(z), z, z)+((diff(H(z), z))/H(z)-2/(1+z))*(diff(Y(z), z))-(1/3)*sqrt(6)*(diff(X(z), z))*(diff(Y(z), z))+(1-(1/2)*exp(-sqrt(2/3)*X(z)))/(2*ZETA*H(z)^2*(1+z)^2) = 0

eq3 := -2*H(z)*(1+z)*(diff(H(z), z))+3*H(z)^2+(1/2*((diff(X(z), z))^2+(1/2)*ZETA*exp(-sqrt(2/3)*X(z))*(diff(Y(z), z))^2))*H(z)^2*(1+z)^2-(1/4)*exp(-sqrt(2/3)*X(z))*Y(z)*(1-(1/2)*exp(-sqrt(2/3)*X(z))) = 0

-2*H(z)*(1+z)*(diff(H(z), z))+3*H(z)^2+((1/2)*(diff(X(z), z))^2+(1/4)*ZETA*exp(-(1/3)*6^(1/2)*X(z))*(diff(Y(z), z))^2)*H(z)^2*(1+z)^2-(1/4)*exp(-(1/3)*6^(1/2)*X(z))*Y(z)*(1-(1/2)*exp(-(1/3)*6^(1/2)*X(z))) = 0

(2)

NULL

``

NULL

NULL

diffux := solve(eq1, dif(H(z), z))

diffur := solve(eq2, dif(H(z), z))

NULL

NULL

NULL

NULL

NULL

NULL

``

Numeric*code

with(ListTools)

Seed := randomize()

with(stats[random])

sys := {subs(ZETA = 10, eq1), subs(ZETA = 10, eq2), subs(ZETA = 10, eq3)}

NULL

vv := 10^100; savf := []; L := 0; Digits := 30; MM := []; MMM := []; N := 1; kkk := []; MM; []; MMM := []

"for hh  from 1 by 1 to 1 do:L:=0: F:=0: b:=1: t:=2:while (t>b)do:"

n := 1.9; ZETA := 10; i := uniform[.60658, 1](N); ics := Y(i) = 1.8, (D(Y))(i) = 0, X(1) = .4, (D(X))(i) = 0, H(i) = .7; solution := dsolve({ics, op(subs(ZETA = 10, sys))}, {H(z), X(z), Y(z)}, type = numeric, method = bvp, output = listprocedure); m := [subs(solution, X(z))]; kk := [subs(solution, Y(z))]

"if op(kk(0))>.7 then  t:=(b)/(5): else t:=5*b :end if:end do: for T  from i by 10^(-1) to 1 do ls[T] := sqrt(0.29995*(1+ T)^(3)+5*10^(-5)*(1+ T)^(4)+0.7): sr[T] := op(kk(T)): L := L+(sr[T]-ls[T])^2 end  do:F:=sqrt(L): if F<vv  then vv:=F; sol:=solution:MM:=[op(MM),[vv,op(kk(1))]]:hhh:=vv:Pa:=[g,i]:else vv:=vv: MMM:=[op(MMM),vv]:end if:end do:"

Error, (in unknown) solution is only defined in the range .88696222680754726..1.

 

NULL

``

RH := subs(sol, Y(z)); Ry := subs(sol, X(z))

Error, invalid input: subs received sol, which is not valid for its 1st argument

 

Error, invalid input: subs received sol, which is not valid for its 1st argument

 

1-Mrad(1)+Rx(1)+Ry(1)

1-Mrad(1)+Rx(1)+Ry(1)

(3)

with(plots)

defHLCDM := sqrt(.29995*(1+z)^3+5*10^(-5)*(1+z)^4+.7)

plotqLCDM := plot((1+z)*(diff(defHLCDM, v))/defHLCDM-1, z = 0 .. 10, color = green, legend = ["q LCDM"])

plotqfR := [odeplot(sol, [z, Pa[1]*y(z)/(Pa[1]-1)+1], z = 0 .. 10, color = blue, legend = ["q R^n"])]; display(plotqLCDM, plotqfR)

plotHLCDM := plot(sqrt(.29995*(1+z)^3+5*10^(-5)*(1+z)^4+.7), z = 0 .. Pa[2], color = green, legend = ["H LCDM"], axes = boxed)

plotHfR := [odeplot(sol, [z, psi(z)], z = 0 .. Pa[2], color = blue, legend = ["H R^n"], axes = boxed)]; display(plotHLCDM, plotHfR)

 

psi*curve*fit

with(plots)

with(ListTools)

with(CurveFitting)

points1 := PolynomialInterpolation([[0, RH(0)], [1, RH(1)], [10, RH(10)], [100, RH(100)], [400, RH(400)], [800, RH(800)], [1200, RH(1200)], [1600, RH(1600)], [2000, RH(2000)], [2400, RH(2400)], [2800, RH(2800)], [3200, RH(3200)], [3600, RH(3600)], [4000, RH(4000)], [4400, RH(4400)], [4600, RH(4600)], [4800, RH(4800)], [5000, RH(5000)], [5200, RH(5200)], [5400, RH(5400)], [5600, RH(5600)], [5800, RH(5800)], [6000, RH(6000)], [6200, RH(6200)], [Pa[2], RH(Pa[2])]], v)

 

sd := plot(points1, z = 0 .. Pa[2], color = red, legend = ["curve fit"])

Error, (in plot) expecting a real constant as range endpoint but received Pa[2]

 

points11 := [[0, RH(0)], [.1, RH(.1)], [1, RH(1)], [10, RH(10)], [100, RH(100)], [400, RH(400)], [800, RH(800)], [1200, RH(1200)], [1600, RH(1600)], [2000, RH(2000)], [2400, RH(2400)], [2800, RH(2800)], [3200, RH(3200)], [3600, RH(3600)], [4000, RH(4000)], [4400, RH(4400)], [4600, RH(4600)], [4800, RH(4800)], [5000, RH(5000)], [5200, RH(5200)], [5400, RH(5400)], [5600, RH(5600)], [5800, RH(5800)], [6000, RH(6000)], [6200, RH(6200)], [Pa[2], RH(Pa[2])]]

sd := plot(points1, z = 0 .. Pa[2], color = red, legend = ["curve fit"], axes = boxed)

pntplot1 := pointplot(points11, symbol = BOX)

polycurve := PolynomialInterpolation(points11, z)

polyplot := plot(polycurve, z = 0 .. Pa[2], axes = boxed)

display([plotHLCDM, sd])

 

``

NULL

``

 

 

``

Luminosity*distnace

eq1h := diff(Hdi1(z), z)-1/points1 = 0

eq2h := diff(Hdi2(z), z)-1/defHLCDM = 0

sysh := {eq1h, eq2h}

icsh := Hdi1(0) = 0, Hdi2(0) = 0; solutionh := dsolve({icsh, op(sysh)}, {Hdi1(z), Hdi2(z)}, type = numeric, output = listprocedure)

plotLDistanceCFIT := [odeplot(solutionh, [z, (1+z)*Hdi1(z)], 0 .. Pa[2], color = blue, legend = ["Luminosity distance Curve fit"])]; plotLDistanceLCDM := [odeplot(solutionh, [z, (1+z)*Hdi2(z)], 0 .. Pa[2], color = red, legend = ["Luminosity distance LCDM"])]; display(plotLDistanceCFIT, plotLDistanceLCDM)

 

``

``

 

 

 

Download DistanceModulus.mw

 

Here is an example of map and flat_map in other scripting languages such as NodeJS:

 

let a = ['a', 'b', 'c']
a.map((e,i)=>[e,i])                    // returns: [['a', 0], ['b', 1], ['c', 2]]
a.flatMap((e,i) => e > 'b' ? [] : [e]) // returns: ['a', 'b']

 

What I do for map_with_index is:

 

map_with_index := (f, a) -> zip(f, to_list(a), [`$`(1..nops(to_list(a)))]);

 

My question is:

 

1) What is the canonical way to achieve map_with_index?

 

2) Is there a builtin procedure for flat_map? If not how to achieve it?

How do you use Maple to get the number of distinct partitions of an integer n, with parts of a maximum value of m? I would like to see how this is done in Maple.

 

Here are some examples obtained  by using SageMath:

 

Partitions(15, max_part=8, max_slope=-1).cardinality()

13

 

Partitions(15, max_part=8, max_slope=-1).list()

[[8, 7],

 [8, 6, 1],

 [8, 5, 2],

 [8, 4, 3],

 [8, 4, 2, 1],

 [7, 6, 2],

 [7, 5, 3],

 [7, 5, 2, 1],

 [7, 4, 3, 1],

 [6, 5, 4],

 [6, 5, 3, 1],

 [6, 4, 3, 2],

 [5, 4, 3, 2, 1]]

 

Partitions(75, max_part=60, max_slope=-1).cardinality()

48336

 

Partitions(100, max_part=35, max_slope=-1).cardinality()

290964

 

Partitions(125, max_part=75, max_slope=-1).cardinality()

3179161

 

—- the end -—
 

Dear all

Please i need your help to add heteroclinic or homoclinic  orbits to my plot 

 

heteroclinic_homoclinic_orbits.mw

 

Many thanks

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