emendes

515 Reputation

6 Badges

8 years, 334 days

MaplePrimes Activity


These are questions asked by emendes

Hello,

I need to sort a list of monomials in a custom order based on two criteria:

  1. Increasing total degree (e.g., x<x^2)

  2. Lexicographic order within the same degree, using a specified variable order such as x<y<z.

For example, given the list:

L := [z^2, y*z, x*z, z, y^2, x*y, y, x^2, x, 1] 

and the variable order (which can be changed by the user):

vars := [x, y, z]; 

I would like the output to be:

[1, x, y, z, x^2, x*x, x*y, x*z, y^2, y*z, z^2]

Is there a built-in function or a recommended way to achieve this in Maple?

Thank you!

Hello,

I would like to determine the level of nested lists within a list.

For example, given:

L := [[1, 2, 3], [], [[1, 2], [3, 4], [5, 6]], [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]];

I would like to compute:

nL := [1, 1, 2, 3];

That is, for each element in L, return the depth of nesting.

Additionally, I would like to write a procedure that takes L and returns a flattened version at the first non-empty list level:

L1 := [[1, 2, 3], [], [1, 2], [3, 4], [5, 6], [1, 2], [3, 4], [5, 6], [7, 8]];

Thank you in advance for your help!

Ed

Hello,

I'm using CodeGeneration:-C in Maple to translate the coefficients of a dynamical model into C++ code. However, I'm running into an issue when trying to assign the output in a way that matches the format of the coef vector used in the main C++ file (which is set up to simulate any 3D quadratic model).

For context, ans is a Maple vector containing all 30 coefficients.
Taking ans[12] as an example:

ans := [0, -sigma, xi[1, 2], xi[1, 3], 0, 0, 0, 0, 0, 0, 0, -sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)*rho*sigma/(2*xi[1, 2]) + sigma*rho/(2*xi[1, 2]), -sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)*beta/2 + sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)/2 - beta/2 - 1/2, -sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)*beta*xi[1, 3]/(2*xi[1, 2]) + sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)*xi[1, 3]/(2*xi[1, 2]) + beta*xi[1, 3]/(2*xi[1, 2]) - xi[1, 3]/(2*xi[1, 2]), 0, xi[2, 5], -sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)/(2*xi[1, 2]^2) + xi[1, 3]*xi[2, 5]/xi[1, 2] + 1/(2*xi[1, 2]^2), 0, 0, 0, 0, sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)*rho*sigma/(2*xi[1, 3]) + sigma*rho/(2*xi[1, 3]), sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)*beta*xi[1, 2]/(2*xi[1, 3]) - sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)*xi[1, 2]/(2*xi[1, 3]) + beta*xi[1, 2]/(2*xi[1, 3]) - xi[1, 2]/(2*xi[1, 3]), sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)*beta/2 - sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)/2 - beta/2 - 1/2, 0, -xi[1, 2]*xi[2, 5]/xi[1, 3] - sqrt(-4*xi[1, 3]^2*xi[1, 2]^2 + 4*xi[1, 2]*xi[1, 3]*xi[2, 5] + 1)/(2*xi[1, 3]^2) - 1/(2*xi[1, 3]^2), -xi[2, 5], 0, 0, 0]

When I run the command:

CodeGeneration:-C(ans[12],resultname="coef21");

the output is:

coef21 = -0.1e1 / (double) xi[0][1] * sqrt((double) (-4 * xi[0][2] * xi[0][2] * xi[0][1] * xi[0][1] + 4 * xi[0][1] * xi[0][2] * xi[1][4] + 1)) * rho * sigma / 0.2e1 + 0.1e1 / (double) xi[0][1] * sigma * rho / 0.2e1;

This is syntactically fine, but what I actually need is an assignment to coef[21] instead of coef21, to be consistent with the structure in my C++ code.

To clarify, the resultname must reflect an offset: ans[12] should become coef[12 + 9], ans[1] becomes coef[1 + 9], and so on. I realize this isn’t ideal, but the current C++ code has been working reliably for years, and adapting it would require unnecessary refactoring.

Do you have any suggestions on how to direct CodeGeneration:-C to generate the assignment with coef[21] as the left-hand side?

Many thanks in advance!

Ed

P.S. Using CodeGeneration:-C(ans[i], resultname = sprintf("coef%d", i + 9)) displays the coefficients on the screen as needed, but they still require some additional editing.

Hello,

I am working with the following overdetermined system of nonlinear equations in Maple and attempting to solve it for the unknowns xi[3] and xi[8].

 [sqrt(beta*rho*xi[8]^2 - beta*xi[8]^2)/xi[8] = sqrt(beta*rho - beta), (-rho + 1 + sqrt(beta*rho*xi[8]^2 - beta*xi[8]^2))/(xi[3]*xi[8] - 1) = sqrt(beta*rho - beta), -(-rho*xi[3]*xi[8] + sqrt(beta*rho*xi[8]^2 - beta*xi[8]^2) + xi[3]*xi[8])/(xi[8]*(xi[3]*xi[8] - 1)) = rho - 1]

Maple returns the following solution:

{xi[3] = (-rho + sqrt(beta*(rho - 1)) + 1)/sqrt(beta*(rho - 1)), xi[8] = -(-rho + sqrt(beta*(rho - 1)) + 1)/(rho - 1)}

However, when I substitute the solution back into the original equations, the left-hand side should equal the right-hand side. Yet, using simplify(subs(solution, equation)) does not reduce the expression sufficiently to verify the equality.

Am I missing something in the simplification process?

Many thanks,

Ed

Hello,

I have several sets of nonlinear equations that need to be solved for certain unknowns. In many cases, the equations admit more than one solution, and Maple is sometimes able to find different solutions by changing the order of the unknowns.

However, in one particular case, I haven't been able to get Maple to find a known solution that was obtained elsewhere.

Below are the equations, the list of unknowns, the solution returned by Maple, and the alternative solution I'm trying to obtain.

Is there a way to guide Maple to find this other solution?

 

eqjerkAB:=[-alpha[9, 1, 1] - alpha[9, 2, 2] - alpha[9, 3, 3] = -alpha[14, 1, 1] - alpha[14, 2, 2] - alpha[14, 3, 3], alpha[9, 1, 1] + alpha[9, 2, 2] = alpha[14, 1, 1] + alpha[14, 2, 2], -alpha[9, 2, 6]*alpha[9, 3, 5] = -alpha[14, 2, 6]*alpha[14, 3, 5], alpha[9, 1, 1]*alpha[9, 3, 3] + alpha[9, 2, 2]*alpha[9, 3, 3] = alpha[14, 1, 1]*alpha[14, 3, 3] + alpha[14, 2, 2]*alpha[14, 3, 3], alpha[9, 1, 1]*alpha[9, 2, 6]*alpha[9, 3, 5] - alpha[9, 1, 2]*alpha[9, 2, 6]*alpha[9, 3, 4] = alpha[14, 1, 1]*alpha[14, 2, 6]*alpha[14, 3, 5], -alpha[9, 1, 1]*alpha[9, 2, 2]*alpha[9, 3, 3] - alpha[9, 1, 2]*alpha[9, 2, 6]*alpha[9, 3, 0] = -alpha[14, 1, 1]*alpha[14, 2, 2]*alpha[14, 3, 3] + alpha[14, 1, 2]*alpha[14, 2, 1]*alpha[14, 3, 3]]:
incA:={alpha[9, 1, 1], alpha[9, 1, 2], alpha[9, 2, 2], alpha[9, 2, 6], alpha[9, 3, 0], alpha[9, 3, 3], alpha[9, 3, 4], alpha[9, 3, 5]}:
solM:=[alpha[9, 1, 1] = (alpha[9, 1, 2]*alpha[9, 2, 6]*alpha[9, 3, 4] + alpha[14, 1, 1]*alpha[14, 2, 6]*alpha[14, 3, 5])/(alpha[14, 2, 6]*alpha[14, 3, 5]), alpha[9, 1, 2] = alpha[9, 1, 2], alpha[9, 2, 2] = (-alpha[9, 1, 2]*alpha[9, 2, 6]*alpha[9, 3, 4] + alpha[14, 2, 2]*alpha[14, 2, 6]*alpha[14, 3, 5])/(alpha[14, 2, 6]*alpha[14, 3, 5]), alpha[9, 2, 6] = alpha[9, 2, 6], alpha[9, 3, 0] = alpha[14, 3, 3]*(-alpha[14, 1, 2]*alpha[14, 2, 1]*alpha[14, 2, 6]^2*alpha[14, 3, 5]^2 + alpha[9, 1, 2]*alpha[14, 3, 5]*alpha[9, 2, 6]*alpha[9, 3, 4]*(alpha[14, 1, 1] - alpha[14, 2, 2])*alpha[14, 2, 6] + alpha[9, 1, 2]^2*alpha[9, 2, 6]^2*alpha[9, 3, 4]^2)/(alpha[9, 1, 2]*alpha[9, 2, 6]*alpha[14, 3, 5]^2*alpha[14, 2, 6]^2), alpha[9, 3, 3] = alpha[14, 3, 3], alpha[9, 3, 4] = alpha[9, 3, 4], alpha[9, 3, 5] = alpha[14, 2, 6]*alpha[14, 3, 5]/alpha[9, 2, 6]]:
solother:={alpha[9,2,2]=-alpha[9,1,1] + alpha[14,1,1] + alpha[14,2,2],
alpha[9,3,0] = (((alpha[9,1,1] - alpha[14,1,1])*(alpha[9,1,1] - alpha[14,2,2]) - alpha[14,1,2]*alpha[14,2,1])*alpha[14,3,3])/(alpha[9,1,2]*alpha[9,2,6]),
alpha[9,3,3] = alpha[14,3,3],
alpha[9,3,4] = (alpha[9,1,1] - alpha[14,1,1])*alpha[14,2,6]*alpha[14,3,5]/(alpha[9,1,2]*alpha[9,2,6]),
alpha[9,3,5] = alpha[14,2,6]*alpha[14,3,5]/alpha[9,2,6]}:

Many thanks.

Ed
 

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