Joe Riel

9660 Reputation

23 Badges

20 years, 5 days

MaplePrimes Activity


These are replies submitted by Joe Riel

Yes, that is the straightforward approach.  I was thinking more along the lines of having already created the expression.

Welcome aboard, Carl.

@jjrohal While not particularly convenient, for the toy problem you use expand's optional arguments

 expand([1,2] + [3,4]*(x-1)^2,x-1);                       
                                              2               2
                                    [3 (x - 1)  + 1, 4 (x - 1)  + 2]

@jjrohal While not particularly convenient, for the toy problem you use expand's optional arguments

 expand([1,2] + [3,4]*(x-1)^2,x-1);                       
                                              2               2
                                    [3 (x - 1)  + 1, 4 (x - 1)  + 2]

@luigidavinci I feared this might be an issue and should have mentioned it originally.  Maple Vectors are mutable data structures; as such, two Maple Vectors can have identical content but have different addresses.  That is not the case for, say, lists.  As such, one cannot generally use a table to lookup a Vector, as I suggested, because the indexing is done on the address of the index, not on its content. 

A method I suggested below is to sort the collection of Vectors by norm, then use that to restrict a search to a subset. That assumes the Vectors have different norms. Another possibility, probably faster, is to sort the Vectors lexicographically, using the slots of the Vectors. 

@luigidavinci I feared this might be an issue and should have mentioned it originally.  Maple Vectors are mutable data structures; as such, two Maple Vectors can have identical content but have different addresses.  That is not the case for, say, lists.  As such, one cannot generally use a table to lookup a Vector, as I suggested, because the indexing is done on the address of the index, not on its content. 

A method I suggested below is to sort the collection of Vectors by norm, then use that to restrict a search to a subset. That assumes the Vectors have different norms. Another possibility, probably faster, is to sort the Vectors lexicographically, using the slots of the Vectors. 

A few comments. nops(basis) doesn't not return what you might expect. The print function isn't useful here, though as a demo it is acceptable.  The test for equality (using Norm and ?is) is expensive.  This technique is fundamentally different than using ?member or the table-lookup method I suggested in that it compares the content rather than the address of the Vectors.  That may or may not be desired. On reflection (but knowing nothing about what the original poster is doing), comparing content is probably better, though it will be slower.  An interesting practical question is whether there is a relatively efficient way to test for membership based on content of a Vector in a collection of Vectors.  For starters, one could sort the collection by norms and then use a binary search.

A few comments. nops(basis) doesn't not return what you might expect. The print function isn't useful here, though as a demo it is acceptable.  The test for equality (using Norm and ?is) is expensive.  This technique is fundamentally different than using ?member or the table-lookup method I suggested in that it compares the content rather than the address of the Vectors.  That may or may not be desired. On reflection (but knowing nothing about what the original poster is doing), comparing content is probably better, though it will be slower.  An interesting practical question is whether there is a relatively efficient way to test for membership based on content of a Vector in a collection of Vectors.  For starters, one could sort the collection by norms and then use a binary search.

It would be helpful to post the actual problem, or, even better, a simplified version of it. Preferably as text, or a Maple worksheet.

@paul7dxb Glad that helped.  Finding bugs by inspection can be challenging. For that reason I generally use the Maple debugger.  If this code were wrapped in a procedure, you would be able to tell the debugger to trap errors.  Then, when the error occurred, querying the loop counter would reveal the problem.  Actually, in this case, because the loop counter is a global, you could have queried the loop counter after the error occurred and seen that its value was N+1, which would have been a useful clue.

@paul7dxb Glad that helped.  Finding bugs by inspection can be challenging. For that reason I generally use the Maple debugger.  If this code were wrapped in a procedure, you would be able to tell the debugger to trap errors.  Then, when the error occurred, querying the loop counter would reveal the problem.  Actually, in this case, because the loop counter is a global, you could have queried the loop counter after the error occurred and seen that its value was N+1, which would have been a useful clue.

There is a bug in MapleSim's code that handles the parameters with "funny" names.  To work-around it, do not create a parameter with a subscript that also uses non-alphabetic characters in the base (or subscript). Here you are using the typeset rho in the base of the subscripted name. I'll submit this bug to Maplesoft's bug tracker.

I locally fixed the Modelica that is generated [the problem lies not with the Modelica generated in the Custom Component template, but the modelica generated for the entire model].  Alas, that led to an inconsistent initialization problem. So there may be issues with the model itself, independent of this bug.

There is a bug in MapleSim's code that handles the parameters with "funny" names.  To work-around it, do not create a parameter with a subscript that also uses non-alphabetic characters in the base (or subscript). Here you are using the typeset rho in the base of the subscripted name. I'll submit this bug to Maplesoft's bug tracker.

I locally fixed the Modelica that is generated [the problem lies not with the Modelica generated in the Custom Component template, but the modelica generated for the entire model].  Alas, that led to an inconsistent initialization problem. So there may be issues with the model itself, independent of this bug.

Substitution, as you've done, is how I would normally handle this. A modification is to let Maple do the work in the call to solve:

(**) eq1 := z = y*log(x): eq2 := z = y + x*log(x):    
(**) solve({eq1,eq2},[x,y,z]);
                                                       2
                                  x ln(x)       x ln(x)
                    [[x = x, y = ---------, z = ---------]]
                                 ln(x) - 1      ln(x) - 1

Substitution, as you've done, is how I would normally handle this. A modification is to let Maple do the work in the call to solve:

(**) eq1 := z = y*log(x): eq2 := z = y + x*log(x):    
(**) solve({eq1,eq2},[x,y,z]);
                                                       2
                                  x ln(x)       x ln(x)
                    [[x = x, y = ---------, z = ---------]]
                                 ln(x) - 1      ln(x) - 1

@acer I haven't thought of anything significantly better. Negligibly better was looping through all indices using programming indices [A(j) with j from 1 to numelems(A)] and breaking on a hit.

Addendum: the difference isn't entirely negligible. Most of the time in the loop is generating Matrix B, not doing the comparison.  With that in mind, the for-loop is a better approach.

First 56 57 58 59 60 61 62 Last Page 58 of 195