cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Searching a symbolic element in a square matrix (Using MATHCAD 15)

-MFra-
21-Topaz II

Searching a symbolic element in a square matrix (Using MATHCAD 15)

A big hello to everyone here,

I'm looking for a little program that receives as parameters only a square matrix of alphanumeric elements and a symbolic element to search in it. The program must return the row and column indices of the element searched. Is anyone able to make it? It seems simple to me. I thank very much whoever wants to do it.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:-MFra-)

The numerics can not distinguish between -L.0*s and -0.000005

So a numerically evaluated "match" command will give you the position of both and also, depending on the setting of the system variable TOL even others which are "close" enough.

A symbolically evaluated "match" will give you the result you probably are looking for.

Werner_E_2-1726670642542.png

 

Werner_E_3-1726670950307.png

 

And, no, you can't look for just L.0, you have to use the full exact expression.

 

 

 

View solution in original post

9 REPLIES 9
LucMeekes
23-Emerald III
(To:-MFra-)

That's quite the challenge:

LucMeekes_0-1726669400087.png

The 'item'

LucMeekes_1-1726669439915.png

does not occur (as an element) in the matrix, in contrast to

LucMeekes_2-1726669515422.png

Luc

Werner_E
25-Diamond I
(To:-MFra-)

The numerics can not distinguish between -L.0*s and -0.000005

So a numerically evaluated "match" command will give you the position of both and also, depending on the setting of the system variable TOL even others which are "close" enough.

A symbolically evaluated "match" will give you the result you probably are looking for.

Werner_E_2-1726670642542.png

 

Werner_E_3-1726670950307.png

 

And, no, you can't look for just L.0, you have to use the full exact expression.

 

 

 

StuartBruff
23-Emerald III
(To:Werner_E)

Argh, me hearty! I'm in full on pirate mode, today, and 'tis capturing your worksheet I being!

 

A random thought was making its merry way through the aether and got tangled up in my skull.  Poor thing.  However, whilst it was there it wondered what would happen if I looked for coefficients of the desired variable.  Sooo, ....

 

2024 09 18 B.png

 

2024 09 18 C.png

 

Stuart

Werner_E
25-Diamond I
(To:StuartBruff)

Congratulations on your pirate genes and the 'random thought' in your head. That really is a very clever approach!

Due to the nature of "coeffs" it will work pretty well as long as the variable is in a polynomial term. It will not find the position if its inside a function like sin or exp as then coeffs returns just a 1x1 matrix.
maybe if we combine it with "series" ....

Werner_E_0-1726688833331.png

It fails if L.0^2 is replaced by L.0^3 because of the modifier "3" in "coeffs".

 

I also came across an effect with "coeffs" which I was not aware of and which puzzled me at first - I seem to have completely forgotten about the additional "degree" modifier 🙂

Werner_E_3-1726689348001.png

 

 

 

 

StuartBruff
23-Emerald III
(To:Werner_E)

Nice.   I was aware of the limitations of coeffs but a savvy pirate sticks to raiding lone, silver-heavy carracks with scurvy-ridden crews, and leaves fully tooled-up and escorted galleons to others. 

 

It would have been a far easier task if the symbolic engine could split expressions into atomic symbols.  Indeed, it may well have that capability (almost certainly must have), but it just does not make it public.

 

IIRC, the Vanilla Mathcad 11 symbolic engine "leaked" a few undocumented Maple functions into the wild.  I think ops and subsop were some of them, as was eval (OK, I found a couple of old .mcd worksheets that used them). ops was useful for getting at elements of an expression, and subsop allowed substitution of elements in an expression. Needless to say, they were soon corralled and put to work in the employ of various Mathcadders.  

 

Stuart

 

https://www.maplesoft.com/support/help/Maple/view.aspx?path=op&cid=663

https://www.maplesoft.com/support/help/view.aspx?path=subsop

 

LucMeekes
23-Emerald III
(To:StuartBruff)

Yep, I make use of those features frequently.

On the other hand, Mathcad 11's match() function doesn't work the way Werner showed. It's not equipped to work symbolically:

LucMeekes_0-1726765795969.png

No symbolic result was found. 😞

 

Luc

 

 

StuartBruff
23-Emerald III
(To:LucMeekes)



@LucMeekes wrote:

Yep, I make use of those features frequently.

On the other hand, Mathcad 11's match() function doesn't work the way Werner showed. It's not equipped to work symbolically:

LucMeekes_0-1726765795969.png

No symbolic result was found. 😞

 

Luc


 

I've had a sporadic play with trying to find a way to get MP10 to return better symbolic expression "resolution" of names.  Unfortunately, I've had little joy (for values of little → 0).

 

However,  in partial compensation, I posted a crisp, new numeric match function here:

 

https://community.ptc.com/t5/Mathcad/Match-Function-Error/m-p/974363/highlight/true#M213922

 

(When I say "new", I mean an old M11-version, restructured for MP10 and with a general tidy-up)  

 

The added IsRange function uses the type exhaustion method because it doesn't look as ugly as the try-else alternative of trapping a non-range operator error (eg, sum)).  And I could use MP's IsFunction to reduce error by type omission.  Original Mathcad 11's on error construct allows for nice, compact code, so an error-trapping IsRange might be the better route to go for M11. I know I used to do some form of check for ranges in M11, but I can't remember what.  

 

Stuart

StuartBruff
23-Emerald III
(To:Werner_E)


@Werner_E wrote:

 

I also came across an effect with "coeffs" which I was not aware of and which puzzled me at first - I seem to have completely forgotten about the additional "degree" modifier 🙂

Werner_E_3-1726689348001.png


What I have long thought would be a decent enhancement along the same lines is returning prime factorization in that format.

 

2024 09 27 J.png

 

Mathcad goes to all the trouble of working out the prime factorization, and then all you can do is look at how pretty the result is.  Sure, I can copy the factors out by hand, but once again, we're into buy-dog, bark-yourself territory. Wuff!

 

Stuart

 

Werner_E
25-Diamond I
(To:StuartBruff)

Looks like my version of Prime is broken

Werner_E_0-1727457879724.png

From your description I would have expected the result

Werner_E_1-1727457911089.png

Maybe in Prime 11, 12, 13, ...

 

Announcements

Top Tags