Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

This is an excersise in one of Mathematica's tutorials. The problem is to find from all persumtations of [1,2,3,4] those lists which has 2 in them before 3.

But the idea is that 2 can be anywhere before the 3, with possibly zero or more numbers between.

Will show how to do this in that other software, and ask if there is a way using Maple pattern matching or better way to do this in Maple better than what I did.

L=Permutations[{1,2,3,4}]
Cases[L,{___,2,___,3,___}]

gives

{{1, 2, 3, 4}, {1, 2, 4, 3}, {1, 4, 2, 3}, {2, 1, 3, 4}, 
{2, 1, 4,  3}, {2, 3, 1, 4}, {2, 3, 4, 1}, {2, 4, 1, 3}, 
{2, 4, 3, 1}, {4, 1,  2, 3}, {4, 2, 1, 3}, {4, 2, 3, 1}}

We see in all of the above, 2 is before 3.

In that other software, the ___ means there is zero or more things.  I could not find how to do this in Maple's pattern matching. So had to use has and then find the index of 2 and 3 in each list and check if the index of 2 is smaller than the index of 3. Which is kinda awakard and not as elegent as using a pattern, but it gives same result.

L:=combinat:-permute([1,2,3,4]);
map(X->`if`(has(X,2) and has(X,3) and ListTools:-Search(2,X)<ListTools:-Search(3,X),X,NULL) ,L);

Gives

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

Can you suggest a way using either patmatch or applyrules in Maple to do the same?  

Could this be done easier than what I did using evalindents without the need for pattern?

I find patterns easier to work with myself.

ps. converting each list to string, and then using regular expression or string matching, is not what I am looking for. 

ps. the check in Maple code of has(X,2) and has(X,3) is not really needed here, since we know each list will have 2 and 3 in them. But I kept these to make it more general for other type of problems where these extra checks might be needed.

Hi everyone, is there any source of Maple competitions? Or related questions? I have a hard time finding books on this subject. I am very interested in Maple and hope to improve my Maple programming skills. In addition to frequently browsing this website, I encounter problems on the Internet sporadically, so I think starting with competition questions will be a quick way to improve.

Good morning, please, could you tell me how to graph this solid of revolution using implicitplot and shade the intersection zone as seen in the graph.

x=y-y^2

x=y^2-3

Around x=2

can someone help me curve fitting these parameeters...i only got 1 for all of this 90As4.mw

restart

with(Statistics)with(plots)with(Optimization)with(LinearAlgebra)

E[1] := 126*10^9E[2] := 11*10^9G[12] := 6.6*10^9G_0__12 := 10.1*10^9nu[12] := .28E_0__2 := 15.5*10^9

true_strain := [0, .406915, .710106, .989362, 1.28457, 1.53989, 1.86702, 2.21011, 2.625, 2.99202]; true_stress := [0, 46.0227*10^6, 81.8182*10^6, 109.091*10^6, 138.068*10^6, 163.636*10^6, 194.318*10^6, 219.886*10^6, 248.864*10^6, 267.614*10^6]; epsilon_dot := 10^(-4)

sigma_t := map(proc (epsilon) options operator, arrow; E[instantaneous]*(1-lambda[90*deg]*epsilon*(sum(P[i], i = 1 .. 10)-(sum(P[i]*exp(lambda[i]*epsilon/epsilon_dot), i = 1 .. 10)))/epsilon_dot)*epsilon end proc, true_strain)

``

obj := sum((sigma_t[i]-true_stress[i])^2, i = 1 .. 10)

indets(obj, name)

{E[instantaneous], P[1], P[2], P[3], P[4], P[5], P[6], P[7], P[8], P[9], P[10], lambda[1], lambda[2], lambda[3], lambda[4], lambda[5], lambda[6], lambda[7], lambda[8], lambda[9], lambda[10], lambda[90*deg]}

(1)

Optimization[Interactive](obj)

The solution was obtained with the following warning:
  no iterations performed as initial point satisfies first-order conditions

 

[Float(infinity), [E[instantaneous] = HFloat(1.0), P[1] = HFloat(1.0), P[2] = HFloat(1.0), P[3] = HFloat(1.0), P[4] = HFloat(1.0), P[5] = HFloat(1.0), P[6] = HFloat(1.0), P[7] = HFloat(1.0), P[8] = HFloat(1.0), P[9] = HFloat(1.0), P[10] = HFloat(1.0), lambda[1] = HFloat(1.0), lambda[2] = HFloat(1.0), lambda[3] = HFloat(1.0), lambda[4] = HFloat(1.0), lambda[5] = HFloat(1.0), lambda[6] = HFloat(1.0), lambda[7] = HFloat(1.0), lambda[8] = HFloat(1.0), lambda[9] = HFloat(1.0), lambda[10] = HFloat(1.0), lambda[90*deg] = HFloat(1.0)]]

(2)
 

NULL

Download 90As4.mw

I apologize for putting the equations in image format, but I thought that this way the community could better understand how to interpret the equations.

Below are 6 letters whose solution must be developed step by step so that the periodic extension of each one can then be done. I can solve all the letters by hand (solving in the notebook), but my big question is, how can I do the commands in Maple step by step so that I can solve them as if I were doing them by hand (look like in my notebool)? I need to check step by step. I would be extremely grateful for the help of any of you.

second part

Dear all, how can I get the 1st which is (2) or 2nd element which is (3) of xxx ?

Dear all, I'm struggeling with the regex and special characters in maple. The StringTools:-Subs works but StringTools:-RegSplit not. Why? I do have the same problem wird the double quotes.

I am trying to create the plot for the dynamics of the discrete Klein - the equation gives Gordon equation (DKG) with friction for t=0 and t=3000.

As you can see below, creating the plot for t=0 is pretty easy. However, for t=3000, I tried to create a procedure to produce the desired plots, but when I ran the code, nothing happened. The worksheets are evaluated all the time. There are no results.

I am studying  for my thesis  the dynamics of the discrete Klein - the equation gives Gordon equation (DKG) with friction:

 

diff(U(t), t, t)-K(`U__n+!`-2*U__n+`U__n-1`)+delta*U__n+(D(W))(U__n) = 0, beta > 0, delta > 0

In the above equation, W describes the potential function:

W(U__n) = -(1/2)*`&omega;__d`^2*U__n^2+(1/4)*beta*`&omega;__d`^2*U__n^4

 

to which every coupled unit U__nadheres. In Eq. (1), the variable U__n(t)is the unknown displacement of the oscillator occupying the
n-th position of the lattice, and is the discretization parameter. We denote by the distance between the oscillators of the lattice. The chain (DKG) contains linear damping with a damping coefficient, while β s the coefficient of the nonlinear cubic term.

 

For the DKG chain (1), we will consider the problem of initial-boundary values, with initial conditions

 

U__n(0) = `U__n,0` and U__n(0) = `U__n,1` and `in`(`U__n,1`, 2*real^(k+2))

and Dirichlet boundary conditions at the boundary points x__0 = -(1/2)*Land "`x__k+1`=L/(2),"that is,

U__0 = `U__k+1` and `U__k+1` = 0, t >= 0*3

 

Therefore, when necessary, we will use the short notation `&Delta;__d`or the one-dimensional discrete Laplacian

`U__&Delta;__d__U__n&in;&Zopf;` = `U__Error loading this structure.`-2*U__n+4*`U__n-1`

 

We investigate numerically the dynamics of the system (1)-(2)-(3). Our first aim is to conduct a numerical study of the property of Dynamic Stability of the system, which directly depends on the existence and linear stability of the branches of equilibrium points. 

For the discussion of numerical results, it is also important to emphasize the role of the parameter `&omega;__d`By changing the time variable proc (t) options operator, arrow; 1/h end proc we rewrite Eq.(1) in the form

 

diff(U(t), t, t)-`&Delta;__d`*U(t)+(diff(delta(x), x))*U__n = `&Omega;__d`(-`&beta;U__n`^3+U__n)^2, t > 0, `&Omega;__d`^2 = h^2*`&omega;__d`^2, diff(delta(x), x) = `h&delta;`

 

The change in the scaling of the lattice parameter of the problem makes it important to comment here on the nature of the continuous and anti-continuous limit. For the anti-continuous limit, we need to consider the case in Eq. (1) where proc (`&omega;__d`) options operator, arrow; infinity end procIn the case of nonlinearity present in the governing equations, the continuous limit needs to be taken as well. On the other hand, for small values of the parameter, the system becomes significant. However, because of the model we consider, we take the asymptotic linear limit as

proc (`&omega;__d`) options operator, arrow; 0 end proc

 

We consider spatially extended initial conditions of the form:

U__n(0) = `U__n,0` and `U__n,0` = a*sin(`j&pi;hn`/L), j = 1, () .. K

 

where h = L/(K+1) is the distance of the grid and  a > 0 is the amplitude of the initial condition
We also assume zero initial velocity:

 

"(`U__n`(0)=`U__n,1`=0) "

 

• 

t=0

 

restart; with(plots); a := 2; j := 2; L := 200; K := 99; h := L/(K+1); n := Vector([`$`(-(1/2)*L+h*i, i = 0 .. K+1)]); U_n0 := a*map(proc (x) options operator, arrow; sin(j*Pi*x/L) end proc, h*n)

plot([seq([n[i], U_n0[i]], i = 1 .. K+2)], style = point, color = blue, axes = boxed, gridlines, grid = [true, true], labelfont = [TIMES, 12])

 

Now I am trying to create plot for different values of a.

a = {2, 1.82, 1.85, 1.9, 1.95}, K = 99, L = 200, beta = 1, delta = 0.5e-1, `&omega;__d`^2 = 1

restart; with(plots)

L := 200; K := 99; j := 2; omega_d := 1; beta := 1; delta := 0.5e-1

h := L/(K+1); n := Vector([`$`(-(1/2)*L+h*i, i = 0 .. K+1)])

dt := 0.5e-1; tmax := 3000; tspan := [seq(0+dt*i, i = 0 .. trunc(tmax/dt))]

NULL

a := 1; U0 := a*map(proc (x) options operator, arrow; sin(j*Pi*h*x/L) end proc, n); U0[1] := 0; U0[K+2] := 0; Udot0 := Vector(K+2, 0)

discrete_laplacian := proc (U) local i, Laplacian; Laplacian := Vector(K+2); for i from 2 to K+1 do Laplacian[i] := U[i+1]-2*U[i]+U[i-1] end do; Laplacian[1] := 0; Laplacian[K+2] := 0; return Laplacian end proc

NULL

U := U0; Udot := Udot0; for t to num_steps do Lap := discrete_laplacian(U); Ucube := map(proc (x) options operator, arrow; x^3 end proc, U); for i from 2 to K+1 do Udot[i] := Udot[i]+dt*(2*omega_d^2*U[i]-beta*Ucube[i]-delta*Udot[i]+Lap[i]) end do; for i from 2 to K+1 do U[i] := dt*Udot[i]+U[i] end do; U[1] := 0; U[K+2] := 0; if `mod`(t, 1000) = 0 then plotU := plot(n, U, style = line, color = blue, title = cat("Displacement at t=", t*dt), labels = ["n", "Displacement"], grid = [true, true]); display(plotU) end if end do

NULL


My target is the following plots

Download Numerical_Simulation_of_discrete_Klein-Gordon_Equation.mw

This is an example of what I need to display in Maple:

Notation

Is it possible to display boundary-conditions in Maple like this?

I tried to experiment with maple but I cannot type the lower and upper boundaries on top of each other. Unfortunately, they are not vertically aligned if I try to use superscript and subscript at the end of the right square bracket.

I hope there is a hack or a way to deal with this problem.

I know that the notation is a bit weird but that is how our teachers want us to display the intermediate calculations when we have to deliver our assignments. I know I could skip this intermidiate process but it is a tradition in my country to show the intermidiary calculations like I showed in the link.

Best regards.

Hi everyone!

I am trying to count the number of operations (addition, subtraction, multiplication, division) in object "A".  I have donea lot of searching around, but haven't been able to find out how to do this.  Some help would be appreciated!

Count_the_number_of_operations_in_A.mw

Hi everyone!

I am trying to build a matrix using for loops.  I have been unable to construct a matrix using one "double" for loop using variables i and j.

Instead, I have 5 "single" for loops.  Could someone show me how to do this using a "double" loop over i and j (rows and colums)?

Thanks so much!

How_to_do_this_using_one_double_loop.mw

applyrule is useful but seems limited. I can't do operation such as expand in the RHS of the rule.

For example, I wanted to applyrule that says to take sin(x::anything) and change it to cos(expand(x)), but it does not expand x. 

It seems because in the RHS of the rule, at the instance applyrule sees expand, x remains a symbol and not evaluated. So there is nothing to expand. It gets evaluated at later time, but by then too late for expand to do anything, it is gone. Just a guess.

But is there a trick to allow one to do more things in RHS of applyrule, such as expand or simplify? This would make applyrule much more useful. Otherwise, as it is, applyrule is of limited use. 

I know I can use evalindets ofcourse for this. 

#expand does not work in RHS of applyrule
e1:=sin(2*sqrt(a*b)*(t+mu));
applyrule( sin(x::anything) = cos(expand(x)), e1);

sin(2*(a*b)^(1/2)*(t+mu))

cos(2*(a*b)^(1/2)*(t+mu))

#but other operations worksheetdir
e1:=sin(2*sqrt(a*b)*(t+mu));
applyrule( sin(x::anything) = cos(x^2), e1);

sin(2*(a*b)^(1/2)*(t+mu))

cos(4*a*b*(t+mu)^2)

expand(2*sqrt(a*b)*(t+mu))

2*(a*b)^(1/2)*t+2*(a*b)^(1/2)*mu

#I could do this ofcourse
evalindets(e1,'specfunc'(sin),X->sin(expand(op(1,X))));

sin(2*(a*b)^(1/2)*t+2*(a*b)^(1/2)*mu)

 

 

Download apply_rule.mw


Using other software, there is no such problem using other operations on RHS of a rule

You see, expand worked on RHS of rule. 

I'd like to do same thing using applyrule in Maple. Is there a trick to allow this?

Maple 2024.1

Hi,

When I enter this command into maple and press enter, nothing is produced.  That's the "first" problem.  However, what I am trying to do is to figure out how many calculations (multipication, addition, subtraction, division) are performed for each variable that "solve" is designed to solve.  Basically, how many math operations are performed when calculating A?

Thanks for your help!

Count_operations.mw

What is the name of the procedure that provides the information about which steps Maple is using to solve an equation? 

I ask because I think pdsolve is caught in a loop, but I can't see what it is trying.

(I can't think of this name at the moment. And Google Gemini returns nonsense. So, I am hoping that by answering this question, Google Gemini will be "trained.") 

What is the idea  of getting equation (48),(49), and (50)

First 10 11 12 13 14 15 16 Last Page 12 of 2153