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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Programmable Matrix Load For Symbolic Analysis ?

VinceC
1-Newbie

Programmable Matrix Load For Symbolic Analysis ?

Application Overview:
I have an application that requires the use of matrix math and symbolic analysis functions of MathCad. The size of the matrices and symbolic variable names to be used in the analysis are various and are set by user inputs.
Application Issue:
Is it possible to create a matrix in a programmable (automated) way and load it with variable names that could be subsequently used in symbolic analysis? It is not desired to load the matrix manually by hand or use the matrix creation pull down box on the tool bar.
Conclusions to date:
What I have found is that MathCad has powerful matrix and symbolic analysis capabilities, yet being able to access these capabilities in an automated way (loading matrices with variables) is problematic. Any help here is appreciated.

Regards,

Vince C
20 REPLIES 20

"save as " 11 or lower.
That will enlarge the doctoring audience.
Long discours are not productive.

jmG

Vince,

Loading symbols (rather than numerical data) in mathcad has always been a desire as well as a problem.

Look at the attached. Put the .mcd and the .xls in the same directory and then open the .mcd

There is away to convert text strings into mathcad symbolic formulae, but that only works in Mathcad 2001i and 11 and relies on undocumented functionality.

Success!
Luc

Dear Luc,

Thanks for your input.
However, there are still issues.
See attached MathCad13 file.


Regards,

Vince C.

Vince,

I think I can understand your problem regarding the symbolic names with the quotes. I do not see any "mc" terms: are you sure you've updated to the latest update of Mathcad 13? You should be on Service Release 1, if necessary download from the PTC site.
It's already indicated in my first reply: what you want is not provided for in Mathcad. As said, there exists a way to remove the quotes, but that only works in some older Mathcad versions and relies on undocumented functionality. If you do have access to Mathcad 11 the attached sheet shows you how it can work; NOTE: it will not work as intended in Mathcad 12 and up.

As for this forum: It's not necessary to upload the same file twice. Most people will read all posts. If you upload a Mathcad file, try to upload it as a Mathcad 11 (or earlier) .MCD file for broadest audience, unless your question is specific to a version. For versions 12 and up, instead of the .XMCD use the Mathcad Compressed .XMCDZ file type: saves internet bandwidth.

Success!

Luc

The array constructors (insert matrix) are of limited use and should not be used when there is some sort of pattern to the values (whether numeric or purely symbolic). Arrays can be defined element by element and this applies to symbolic as well as numeric usage.

If you have a more specific example of what you want to do (preferably in the form of a worksheet) you could get more specific answers.

As a neatness note this topic does not belong in the application server section (the Mathcad Application Server is a specific product for web servers) but should be in the mathcad usage or programming section.
__________________
� � � � Tom Gutman

Dear Tom,

Sorry for the misplaced document and any confusion it may cause. This is my first time in the user forum.

Please see attached MathCad13 file for questions regarding automated matrix loading. Hopefully there is a solution. Thank you in advance for any help.

Regards,

Vince C.

The basic answer to how to remove the quotes is not to include them in the first place. Enter the expressions as expressions.

A few more forum usage notes: There is little point to uploading the same file more than once. You should assume that anybody taking part in a thread is reading everything in the thread. Sometimes you can use a single post to answer several posts, and even where individual answers are appropriate any common information (or uploads) can be included in one of them and referenced in the other.

XMCD file formats are way bloated and oversized. They very quickly become large enough to be uncomfortable to download (or upload). For collaboratory purposes the compressed XMCDZ format, without large results or rendered pictures, is a much better choice.
__________________
� � � � Tom Gutman

Dear Tom,

There is still some confusion regarding the goal of this exercise. The goal of the exercise was to find an automated way of loading the matrix terms to find a solution set. That is why I provided an automated way of inserting the expressions with strings and a manual way as well. So, it appears that the results between the two concepts are equivalent. However, the solution with automated way of inserting matrix terms are ugly with the quotes and are not useable beyond that point without some kind of manual or automated processing apparently provided by Luc's email via MathCad 11. I agree that in order to not have the quotes in the final solution is to not insert them. But, not inserting the quotes means a manual way of creating the matrix terms. I am very surprised (according to Luc's response) that MathCad>11 does not allow an automated or programmable way of inserting matrix terms with expressions. Is this true? Any comments, guidance or help is very appreciated.

Kind Regards,

Vince C.

Hard to see what you are trying to do. A matrix, a carrot... they are the same thing if you do nothing with them, particularly a matrix. A matrix does not exist by itself, a matrix of values, Ah ! yes. Then make a blank matrix of any values that you will address appropriately and then operate on it. But that is a unique classroom case. The attached is oriented to be productive, fast.

jmG

I'm not sure what you mean. Perhaps you need to provide a bit more context for your request.

There are two differences between what you call the manual and automated sides in your sheet. In one you use array constructors (requires manually setting the array bounds, limited to no more than 100 elements), in the other you use assignments to individual elements. Also, in one you typed in expressions, in the other you typed in strings (starting by using the " key). But both involved manually typing in some representation of the expression. Why type the " if you don't really want strings?

The expressions need not be directly typed in. They can be generated programmatically. But you show neither the input data nor the methodology used to generate the arrays, hence it was not possible to demonstrate how to generate them programmatically. Lou (lpoulo) has posted some sheets for analyzing electrical networks (from the names I deduce that that is what you are working with). Those can be extended to be very automated, starting with a logical description of the network (list of elements with types, parameters, and connections) and generating the arrays needed for a solution.

Do remember that symbolic matrix inversion is in terms of determinants and that determinants generate a number of terms on the order of n factorial, with the result that for networks too large to be easily solved by hand a symbolic solution is usually too large to be of any actual use (and not infrequently too large to be actually created).
__________________
� � � � Tom Gutman

Vince,

Mathcad, below, at and above version 11, DOES allow to input matrices from other sources (e.g. MsExcel), as long as the matrix data involves numbers. In my first reply to you, if you change all cell contents of the Excell file to numbers the sheet should work just fine.
The ability to input symbols (as opposed to pure numeric data) was NEVER purposely implemented in any version of Mathcad. Neither is the reverse: you cannot export symbolic expressions from Mathcad; but you can export numeric data in many ways.

I understood from your original request that you have some kind of tool (external to Mathcad) that produces matrices with symbols that you want to input into, and subsequently process in Mathcad.
I interpret Tom's suggestion in the sense that:
If you want to work symbolically in Mathcad, you are advised to construct the matrices in Mathcad as well. This means that you'd have to implement your (external) tool within Mathcad.
If your matrices become large enough the usability of the symbolic results will deteriorate.

(still) Success!
Luc

Dear Luc,

Thank you for the summary.

Thank you to all (Tom and Luc) for your guidance.

Regards,

Vince C.

Is Luc correct that what you really want is to import expressions from an external file? That is doable.

For MC11 I have a sheet that reads the NIST standard regression data sets, including the expression defining the regression, and processes it. It uses a compiler completely written in Mathcad (not relying on the hole allowing Maple's compiler to be used). But Mathsoft introduced a whole slew of new (and unecessary) restrictions in MC12 (chief source is SUC, but they managed quite a few others along the way) that broke that sheet three ways to Sunday. Since SUC disallows the fundamental data structure used in the compiler, it would have to be completely rewritten (in a much messier form) to work in any of the later MC releases. I had, and have, no intention of doing so. Neatness counts.

In MC12+ you have access to a text form of expressions in XML format. My variable definition sheet (and the related AISC steel shapes sheet) use that to define variables. There is a limited amount of expression parsing involved, but it is limited to expressions I expect to find in the unit definitions of Excel data bases similar to the AISC steel shapes. Quite limited, and also not standard expressions (in4 is taken to mean in4, used for some moments). But the principle could be applied, with a more general compiler, to general expressions.
__________________
� � � � Tom Gutman

Dear Tom,

Luc is correct that I want to import expressions from an external file.

Maybe if you could provide what you have in MC11 and MC12 , I could try to adapt your sheets accordingly. This sounds hopeful.

Also , thank you for your time with the other spreadsheets provided. However the use is limited for me since they don't have the capability to import expressions from an external file.


Regards,

Vince C.

>However the use is limited for me since they don't have the capability to import expressions from an external file <<br> _______________________

An expression (i.e: an equation) written in script style, Mathcad imports ... rather pastes in same script style appended with quote marks " y=.....".

In fact you have not shown any of your matrix design. At least you can create and manipulate as posted before. And the great question is: are they "matrix" or simply collecting arrays ? By collecting array, I mean: an array that collects all sorts of equations that you want to address later on .

jmG

Dear Tom,

This analysis starts with processing a file which contains lines of component description.
There are arrays used to do this. This works quite well because the text strings can be processed with existing MathCad routines.
For each component , there is a description that indicates what type of component it is, where it is connected and has a variable name or function associated with it.
Example
V1 1 0 Vin
R1 1 2 Rx
R2 2 0 Ry
The number of connections and the component type will set the size of the matrices used to solve for the desired response.
There are three general matrices used:
************************************************
When generating these matrices the issue is that the terms from the variable name (Rx,Ry, Vin) or function (not shown: but is an expression like (G*(V1-V2)) ) for each component will need to be able to be:
A) Simply inserted into appropriate matrix location.
B) Inverted (1/Rx) and then inserted into appropriate matrix location.
C) Inverted (1/Rx) and then added ((1/Rx)+(1/Ry)) or subtracted ((1/Rx)-(1/Ry)) to other terms for components connected to same point and then inserted into appropriate matrix location.

**********************************************
I was using text strings and concatenating terms to do steps A, B and C outlined above. Unfortunately, the result achieved is ugly as you could see from the simple spreadsheet provided.

So your answer is that arrays are used to hold the expressions (Rx,Ry,Vin, (G*(V1-V2))) and then the matrices are loaded by steps A,B,C above followed subsequently by symbolic analysis.

So in summary, the inputs are text strings like �Rx� or �Ry� or �Vin� or �(G*(V1-V2))� from an input file like excel and then to load appropriate matrix locations with 1/Rx or 1/Ry or Vin or 1/(G(V1-V2)) or 1/Rx + 1/Ry or 1/Rx � 1/Ry or 1/Rx + 1/(G(V1-V2)) .

Re-stating some previous thoughts:
If there is a way to strip the quotes ("") from the symbolic response post symbolic processing then goal is achieved.
If there is a way to programmable way to provide steps A,B,C without quotes ("") during load of matrices, then goal could be achieved. Basically, if a programmable version of the windows drop down box to create a matrix could be created, then this is also ok.


Regards,

Vince C.

What I have has all been posted previously. Look for my posts on compilers. I have two versions, one that is just for numeric evaluation, and one that has been adapted to allow symbolic evaluation. Both are MC11 only, MC12 thoroughly broke them. The symbolic compatible compiler is used in my NIST standard regression data work sheet (with some additional front end processing to deal with some special notation used in those sheets, like the ellipses). That has also beeon posted previously, in several versions (same compiler, though). There are also various versions of my AISC steel shapes posted, the later ones, for MC13+, have a very limited compiler for unit expressions (done in a scripted component using VBS rather than Mathcad).
__________________
� � � � Tom Gutman

Please read lightly, my understanding is limited. Mathcad is not a push button to land on the moon. What you want is near speech recognition. If you accept to cut the mustard, here is what you can do:

1. Create a vector, a vector of the length that will represent the future matrix by rows/cols as you will specify.

2. This vector has a single letter name, it is indexed

3. This vector, you pack it under a function name.

4. At this point, you extract it symbolic, copy/paste into a wild matrix.

5. You then address the elements and operate on the matrix.

What I don't understand is why you need such a gear instead of a matrix of all 0's that you address, it will do the same . The other point about a blank matrix is that you can fill in the blank with pieces of formulas for doing more than the few traditional matrix operations ... you see my point ?
What I have not tried is to address pieces of equations at specific addresses in that "wild matrix" resulting from the vector construct. The other point is about your version. The attached is 11.2a .

The vector construct is not unusual, simply a back-fill.

Good luck, cheers.

jmG

Revised for clarity.

Pack(V,p,q) is a function, C is an algo construct... you can collapse both in utilities at the top of the work sheet and operate locally because 'j' is globally defined. Remark K3 is not assigned and defaulted to 0.

jmG

This Matrix/Array construct is now complete, fully automated, ready for the user to input the data for whatever analysis. It constructs all sorts of rows/cols size ... square/rectangular.



1. Watch the green

2. Don't mind the red

3. Size in yellow

4. User @ beige

5. Collapse... put in oven !

6. Perform analysis



The attached is 11.2a, in case upper versions caught on that: the *.gif it there for attempting the rescue.



! DO NOT DO !

Don't attempt defining globally the user data, the M construct is assigned locally so it won't take. Not taking is innocent, not so ! In my XP_S2 e_Machine, not only it kills the box it makes it ring like a bell every 's' (second) with a loud and terrifying song announcing the rope and gallows...


Enjoy this superb tool.



jmG
Top Tags