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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Comparing results from multiple runs of same sheet?

ptc-4310378
1-Newbie

Comparing results from multiple runs of same sheet?

How can data resulting from running the same sheet with varying inputs be summarized (graphed) in one sheet?

The Excel boyz have it easy on that and are laughing at me: they are dealing with "name ranges" (variables) which remember what sheets they are coming from and are therefore identifyable although they have the same names. No such luck in the MathCad camp it seems. Have I really lost this battle?

Only scheme I can think off is to write the data to file and change the name of the file for each data run, so they can be called selectively in the summary sheet? Not much data to write size wise, just several small arrays. Would it be best to pack it all in one array to write it to file or can a file take "add on" writes without being overwritten?

I cannot go directly to Excel either as the data must be fed to functions for plotting.

I was ahead of the Excel Pack on this one assignement, but they have caught up with me on this final summary step.....

19 REPLIES 19
RichardJ
19-Tanzanite
(To:ptc-4310378)

Your problem is likely to stem from the way you wrote the worksheet in the first place. I say this both because you are having this problem, and because of the worksheet you recently posted in the other thread.

In Excel there are no user defined functions. Not unless you want to write them in VBA, anyway. The way it works is you calculate an intermediate result for every step of the calculations. The sort of approach that if you were taking a programming class in any significant programming language would earn you a "fail". If you want to run the calculations with different inputs and compare the results you have to make a series of copies in different sheets, all in the same workbook. Huge amounts of manual work, and if you have several hundred inputs to deal with I doubt the Excel guy that has to do it would be laughing.

In Mathcad you can take the Excel approach if you wish. Then you end up with a worksheet with a big string of intermediate results, and there is no way to automatically run the worksheet multiple times and collect those results. Actually, that's not quite true, there are a couple of ways, but they are kludges. This is really not that different to the situation in Excel, where (short of more VBA programming) there is no way to run a workbook multiple times and collect the results. The right way to do it in Mathcad is to write everything as user defined dependent functions. At the end of the worksheet you can write a small program that loads the data, analyzes it, and puts all the results in a matrix. I have worksheets that do this for hundreds, or even thousands, of data files.

Unfortunately, a lot of people write their Mathcad worksheet using the Excel approach, and then run into the problem you have. In many cases that's probably because they came to Mathcad form Excel, where the only option was the long string of intermediate results and copies of worksheets.

So the problem is not Mathcad, it's that Mathcad is being used in the wrong way. A great deal of the power of Mathcad is in the ease of defining a series of functions, something that can only be done in Excel if you get into VBA programming.

I recently went though a similar discussion about dependent functons in another thread. To see the difference it makes in doing it the "Excel way" or the "Mathcad way", see here:

Closing a "Solve Block" around the constraint that a vector cross product be zero

I am very slowly starting to understand the Mathcad way you describe so well: My first attempt at it is in the attached Homework from last semester.

The previous sheet from the other post you are referring to now runs "automatically". The issue while writing it was that one reference function was solver based and was taking too long to recalculate everytime it was needed for a new graph. This is how Luc's solution very much helped, by storing the results of the function and referring the stored values instead of having to go through the lengthy recalculations.

I think I am starting to grasp what you are outlining as far as the multiple comparisons:

-- Just do all the processing in one sheet instead of trying to compile the results of several sheets.

I was somewhat lost as far as how to implement the concept, as the original sheet is already a "comparison" of a few cases with array inputs. But between what MCH, Wayne and Luc offered, I might be able to figure out how to have a program processing a matrix of inputs instead of arrays. I'll give that a try.

I am greatful for all the help here, as I am very much by myself in this 100% Excel crowd. Wouldn't have been able to submit the work on time without the support.

Thanks again.

... can a file take "add on" writes without being overwritten?

Use APPENDPRN() to add more onto a pre-existing file. The additional matrices must be of the same size as the original.

I suggest using WRITEPRN() for the first writing instance so that it overwrites the pre-existing information.

Use the HELP resource for details.

Many thanks MCH. I was looking in the MCad 15 Users Manual for the read/write ref, didn't realize they had moved this info from the manual to Help in the latest releases.....

APPEND won't work in my case as not all WRITE are same sizes.

As Luc pointed out that WRITE/READ handles Nested Arrays, I can just pack the few arrays that needs to be passed over in one Nested Array in one WRITE at the end of the file. Makes it easy to address the data after the READ.

Problem I have now is that I do not know in advance how many cases I will have to graph together for comparison, and I have no idea if there is a way to dynamically generate a graph: ie how to dynamically populate the abscissa in function of the number of cases to compare. Typically, the plots consist of UDFs against a reference array on the Ordinate. I don't see a way for one UDF to generate more than one trace (would be the equivalent of vectorizing the graphing function in a way). That would be great though!

This must be trivial for most experts on this board. But I don't do MCad for a living and am just trying to escape my local Academia Excel craze and stumbling my way through as I can (Although after I convinced myself of the validity of the results with MCad, I still have to plug away in Excel, as it is the required submission format imposed by our good Excel Fanatic Professor Doctor, how does it get funnier!)

RichardJ
19-Tanzanite
(To:ptc-4310378)

how to dynamically populate the abscissa in function of the number of cases to compare. Typically, the plots consist of UDFs against a reference array on the Ordinate. I don't see a way for one UDF to generate more than one trace (would be the equivalent of vectorizing the graphing function in a way). That would be great though!

Does this help?

Neat trick! Drawback is that is all shows as one trace and the needed color contrast for cases differentiation is lost.

Most likely there won't be more than 5 cases to compare (the graph becomes overloaded then anyway and becomes meaningless), so am wondering about prepopulating the abscissa with five indexed UDFs that would be programmed with a flag to return an out of the chart range value if the index is out of range (Does Mcad offer the use of a Null value?). Ugly but would do the trick if it works.

Thanks.

RichardJ
19-Tanzanite
(To:ptc-4310378)

Neat trick! Drawback is that is all shows as one trace and the needed color contrast for cases differentiation is lost.

Yes. Unfortunately, although programmable graphs have been requested more times and by more people than I can remember, we don't have them. This is as good as it gets

Most likely there won't be more than 5 cases to compare (the graph becomes overloaded then anyway and becomes meaningless), so am wondering about prepopulating the abscissa with five indexed UDFs that would be programmed with a flag to return an out of the chart range value if the index is out of range (Does Mcad offer the use of a Null value?). Ugly but would do the trick if it works.

In MC11.2 and later you could use a NaN. I think in 2001 strings will work as non-plotting points (they certainly work in later versions)

At least I know now not to hunt for the programmable graph...

Bad start of the day here. While looking up NaN, the first hit was "NaNcy Grace"! Thanks Google.

I can use 15 for the comparo plots, no prob here.

Thanks.

Here is a little more, in the direction Richard pointed.

This is great, but not the way I am trying to set up. I would like to avoid generating data that need tracking before plotting and to carry the UDF all the way to the abscissa.

I keep the index as part of the UDF, so where your example is showing a Plot of G<i>, I am trying to plot g(x,y,i), if that makes any sense. With x and y often functions themselves you end up with g (x(i),y(i),i) (or deeper if functions of functions) and it sometimes becomes simpler to equate this to gg(i) for instance.

An of course I was dreaming of a function like Plot gg(i).....that would generate i traces. Dream on says Mr Jackson.

By the time of the final comparison, the i index is used up because the original function is already a conglomeration on i. But it looks like from your programming example, that a function could be programmed that would be called ggg(j) for instance, which would run the gg(i) function on the j set of data. I'll try to look at that next week. This way all the cases (currently 3) could be run in one sheet by using Matrices for input data instead of Arrays as for the single cases. This way, no need for data import in a summary sheet, all in one sheet, that would be great.

i is running on 5 layers of rocks in a hydrocarbon reservoir and j on three different type of fluids being produced.

Thanks.

Not much data to write size wise, just several small arrays.

Mathcad has the capability to use nested arrays; that is, an array of arrays.

So is you have N ixj (row x column) matrices in a nested array called M, it is quite easy to specify the ijth element of the nth one by using [Mn]i,j.

There are also some neat time saving tricks, such as using a programming loop and assigning the whole nth M matrix to some ARRAY used in the loop, ARRAY<-Mn, without the need for going through the i and j indices.

Yes, am using this neat trick to pass data out of programs too. Beats tracking with indices. Since Luc advised a few days ago that PRN could handle Nested Arrays (working quite well for me righ tnow!), I was thinking in my top post about using the same method used in programs to exchange data between files via PRN, stacked in nested arrays. Thanks.

LucMeekes
23-Emerald III
(To:ptc-4310378)

Hi Laurent,

I've come across this as well. Here's my solution and, not to surprise, it's been suggested above already:

1. make sure that each result is in the form of a single matrix row. (I've no experience with row elements being other than scalar, but I'm pretty sure that strings as elements are allowed too, not sure about about vectors or matrices)

2. Write the result of the first pass with WRITEPRN

3. Write the result of each subsequent pass with APPENPRN. If you try to append a row of different size, you'll get an error.

4. Now you can read in the datafile with READPRN, you should get a matrix with as many columns as there are elements in your original rows, and as many rows as there are passes saved.

5. Process this matrix as you like.

You should be able to store (e.g. as the first row element) a pass number or even text to describe the row. You can store input variables along with the outputs. You can make the row virtually as wide as you like (until you run into Mathcad limitations).

So it is possible to obtain from the result matrix data to plot results versus input parameters (provided you stored them).

Success!

Luc

I've checked, see attachment.

Thanks.

I ran into a snag with the solver keeping breaking down (unknown error) when applied to a function that itself contains a solver function. Have to shut down MCad and restart to clear the fault, sometimes more than once. So I have to make a manual intervention (copy results of first solver into an array and feed to second solver, which works here without WRITE/READ as it is a small array (so no Matrix too big message). But no automated sheet anymore for now.

The project is due Monday, and still have to write report and presentation, so I have to leave MCad to where it is now and go on with Excel, as it is the required submission format. Most likely the good Professor Doctor won't catch up on the short cuts I take in Excel by using MCad generated data....

Will look further into the method you outlined next week, as I can expect the good Professor to through more of the same our way for the rest of the semester.

Thanks

You can use Mathcad and Excel together!

One example.

When I need a pie-diagramm I calculate in Mathcad and send output data in Excel where I plot this diagramm!

I still would like to learn how to structure the file the way described by Mr Jackson as it seems most efficient.

But for the time being, I am giving serious thoughts to your suggestion here, mainly because our Professor requires the HW to be submitted in Excel format. Today, once I have solved the HW problem with Mathcad, I have to race to duplicate the results in Excel which is a complete waste of time. So why not dump the Mathcad data directly into Excel and plot in Excel, just like you suggested!

I just got a book called "Mathcad for Engineering", where I can see that it is much easier to shake hands with Excel from 15 than it is from 2001. So I will try to learn the Mathcad-Excel techniques with 15 from this book. Although I am hesitant to commit to 15 with my Student license....the night before the project was due, 15 wouldn't start because of a license issue...and the license wizard got me nowhere as the PTC licence site was down for maintenance. I would have been dead in the water if I hadn't had my 2001 running (Licence was eventually renewed, but who knows, this could happen again at crunch time).

Thank you for the suggestion.

Laurent Muller wrote:

I am hesitant to commit to 15 with my Student license....the night before the project was due, 15 wouldn't start because of a license issue...and the license wizard got me nowhere as the PTC licence site was down for maintenance. I would have been dead in the water if I hadn't had my 2001 running (Licence was eventually renewed, but who knows, this could happen again at crunch time).

There is a thread under the "Academic" forum of this site indicating that others may have had issues accessing the server for their Student Licence with PTC products (Storm related event it seems). Not good when it happens so close to due date.

You can also use the "Mathcad Installation & Licensing Support Center" to report a problem with the license, here: http://www.ptc.com/support/mathcad_supportCenter.htm

I did use this link to report the issue when the licence was dropped and did receive an answer with offer to help. But by this time the PTC licence site was back up and the wizard had already guided me to relicensing. The whole incident could have been caused by erroneous licensing the first time around: my licence is now showing as "Academic", where it didn't the first time around. Could be that the Wizard had landed me a trial licence, hence the expiration.

Top Tags