dharr

Dr. David Harrington

9152 Reputation

22 Badges

21 years, 260 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are replies submitted by dharr

@C_R Converting the lprint(%) to 1-D resolves the issue. But I was not able to generate it with a fresh 2026.1 worksheet (I didn't try document mode). But I have a recollection that recently 2D math with % in has not worked consistently. So it might not be to do wth lprint but with % in 2D. Unfortunately I can't get it to not work when I try a few examples. If I come up with one I'll post it here.

You added a second question with the uploaded file instead of editing your own question and uploading the file to it. So I did this for you, moving your file to where it should have been. I then deleted the now redundant question, with the reason "duplicate question" and not "spam", though perhaps the system shows you that.

I am happy to accept donations for my brain upgrade. On the other hand you may wish to delete this post.

Maple's standard diff can differentiate with respect to theta, but not to theta(s). However diff is modified to accept theta(s) when the Physics package is loaded. So with(Physics) solves the error and returns some output, but I don't know if it is what you wanted.

@Mth2026 That download page for the assistant implies that it is not included with Maple Flow but has to be downloaded separately.

There is a link to download it at https://www.maplesoft.com/products/mapleflow/migration-assistant/ 

If you are having diffculties with the download and installation, you should contact technical support.

@Ronan Well one documented way to stay in the superscipt mode after x^2 is to enter a space; then + stays on the same line as 2. The same works here, i.e.,  1/2 ! works as expected. But one doesn't want to have to think about this non-intuitive solution.

A version or two ago, 2D math was modified so that the keystrokes x^2+ automatically brought the + sign back to the baseline. At that time, the behaviour you observed was introduced. I assume this was an unintended side effect of the changes, and I consider it a bug. There was some discussion of this before and I am assuming it is on a list of things to be fixed; but if not please add it to the list, Maplesoft.

My recollection is that there are other cases where the cursor jumps out of the denominator, but now that I try to find them I'm out of luck, so maybe I'm wrong about this.

@Harry Garst So if I have some Matrices, I might want to manipulate them with their entries. In your Zehfuss example, I can see why you might want to use that rule to evaluate Determinant(Kronecker(A,B) since using that rule gives a much simpler expression than the direct evaluation. But for that purpose, you could write a procedure DetKron:=(A,B)->Determinant(A)^etc.

I can see a different application where you want to simplify some expression with abstract matrices A,B that are just the symbols A,B but have the properties of matrices (in particular non-cummutativity) - such as implementing these Knonecker properties.

You seem to want to make your life difficult by wanting to have A,B real matrices and then not use that fact - requiring uneval and uneval quotes. So everything has to be done inside a call to ZehfussReplace or similar. Or you can use inert operators and then use value on your result. But it is awkward and not the way I tend to use Maple.

For the abstract case, you can do some things with define or pattern matching. But I think the physics package is a better option. QuantumOperators act like matrices, and I suspect that Knonecker products are also there somewhere since in an abstract sense they are just tensor products. So these rules may already exist. I don't use the package much so I can't be more specific.

In general (for symbols or real matrices), if I want to know if two things are equal, I simplify their difference and see if it is zero (or the zero matrix). And in general I manipulate things in abstract form and when I get to the end of those manipulations I put in the numbers with eval. That is a bit harder with matrices, but try

A . B;
eval(%, {A = Matrix(2, 2, symbol = a), B = Matrix(2, 2, symbol = b)});

or for an expanded polynomial

2*x^3 + x^2 + 2;
eval(%, x = Matrix(2, 2, [1, 0, 3, 5]));

@acer That's much better. I struggled with getting the two square matrices into the same type specification. For the inerts, I was thinking that the OP might be wanting an inert output, e.g.,

ZehfussReplace := proc(expr::uneval)
  uses LinearAlgebra;
  subsindets(expr,
    specfunc(specfunc('KroneckerProduct'),'Determinant'),
    proc(q)
      local AB;
      AB:=op(op(q));
      if not eval([AB])::['Matrix'('square'),'Matrix'('square')] then return eval(q) end if;
      %Determinant(AB[1])^(upperbound(AB[2])[1])*%Determinant(AB[2])^(upperbound(AB[1])[1])
    end proc
   );
end proc:

(or using @acers version),and then value could be used on the output.

@Harry Garst Yes you can have such a type, as I illustrate in the answer I posted.

@Alfred_F Here's a relatively simple way to get a reasonable estimate. Interesting that many of the parameters are zero.

NLPSolveMatrixForm2.mw

@Harry Garst You need an extra eval in the evalb. I guess verify does that internally.

There is no point doing expr:= something; and then ZehfussReplace(expr) since expr is already evaluated. So you have to put the expression you want directly in the ZehfussReplace call - see the example in the attached.

Maple has the usual scoping rules for nested procedures - the inner ones can see the variables in the more outer ones. But the question you asked has more to do with subsindets, which scans through an expression and applies the inner procedure whenever it comes across "Determinant"

Dharr_reply2.mw

@Alfred_F You want Maximize not maximize to use the routine in the Optimization package. Your -50 in the constraint should be outside the integral, which solves the issue that @sand15 was having.

The integrals make the problem much more difficult. You have three ways to use NLPSolve (which is what Maximize uses if the problem is nonlinear) - enter the objective and constraints as expressions (your method), enter as procedures, or use the Matrix Form. I could only get it to work in the expression form if the integrals were solvable symbolically. The procedure form incorrectly counts the dummy integration variable as a problem variable, which leaves the more complicated MatrixForm. I use NLPSolve a lot, but not with constraints and I didn't get the constraintjacobian feature to work. In the end I couldn't get your very complicated expression to work. One could implement the third argument "needc" feature in the procedures, but it wasn't immediately obvious to me how to proceed.

It is worth formulating the problem with all parameters positive if you can and then use assume = nonnegative.

I think you also want to formulate the problem so your function wn comes down to zero at xend. Otherwise the integrals will capture a part of the function going below the axis. Perhaps piecewise could solve this.

I think your nested procedures confuse NLPSolve's attempts to process the objective and constraints, so I put everything as just simple expressions.

Here's some notes on how to use the various modes. Suggest you work up in complexity. 7 variables in a very nonlinear problem that isn't nondimensionalized is a very difficult problem. I'd guess the presence of the exp is a problem.

NLPSolveMatrixForm.mw

@Harry Garst By Maple's full evaluation rule, if A and B are already matrices, then after

expr := Determinant(KroneckerProduct(A,B));

expr is a number with the Determinant of the Kronecker product already done, i.e., it is too late to process it.

So the processing routine has to use ZehfussReplace := proc(expr::uneval)

With that modification your ZehfussReplace routine works at least for the simple case of providing

ZehfussReplace(Determinant(KroneckerProduct(A, B)))

It could be made more robust, e.g. checking for square matrices etc, only two matrices, allowing for symbolic A,B etc. Not sure what your precise requirements are.

If I convert the first line to 1D math you see it is

dim := 1;
A := Matrix(dim, dim, symbol = a);
evalb(factor(Determinant(`⨂`(A, A))) - abs(A)^(2*RowDimension(A)) = 0);

so I think the |A| in the 2D math is being interpreted as abs and not Determinant the first time. Somehow if you leave it as 2D, it interprets as abs the first time and then if you reexecute the same line it "has now figured out" that A is a Matrix and you get the determinant. Very mysterious. The solution is to write out Determinant(A).

for dim = 4, the Kronecker product is 16x16 and the determinant has 16! = 20922789888000 terms, and then you are trying ro factor the result so it isn't unexpected that it takes too long.

I'm not clear about what you mean by "detect whether there is a determinant of a Kronecker product present in an expression."

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