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

Translate the entire conversation x

Analysis of assemblies dynamic thermal performance behaviour under ISO 13786-2023

Ivan_Pat
12-Amethyst

Analysis of assemblies dynamic thermal performance behaviour under ISO 13786-2023

Hi there!

Thanks to the community members for being patient with my questions.

Although a lot of guys in the PTC community gave me  valuable tips,

I still want to improve my code slightly (perfectionism).

 

So, I'll try to list  of what do I want to get from my  code:

  1. Define all the calculus dependencies in the first step.
  2. Define the variables' range (each layer generally has its range). The idea is to account for all possible permutations.
  3. The k1 and f functions should be figured out for each set of thicknesses (variable) iteration of my multilayered assembly (I have no idea how to assign a specific range of thickness to a particular layer; this is my weak point; I’m not confident in this area).
  4. To sort out what of the total k1 and f values fit the restriction condition and arrange the result in a matrix with headers (for convenience, with aggregated values’ Names) (the particular matrix components should be plottable afterwards).
  5. The number of layers varies, so I need to script the sequence of each iteration by indexing (I'm a bit frustrated in this regard right now).
  6. The desired code has to be as compact and optimised ( in terms of machine time consumerance) as possible (the maxima goal).

Firstly, I tried to make it more generalised (with indexing), but the understanding of the leakage of base coding skills became evident very quickly.

 

I also understand that poor code is better than its absence.

 

For clarification, I attached my code in MathCAD Prime 10.0.0 and asked for assistance (advice, somehow) on how to deal with it.

I would appreciate any help.

 

I've attached my modified code and working sample for two layers.

 

PS. I also cannot understand why Chat GPT always creates JS-based code for my appropriate MathCAD prompt.

 

Best regards and thanks in advance.

ACCEPTED SOLUTION

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

But thats nearly exactly what I provided with my generic "doIt" program if you make the two changes indicated in my reply above so that the numbering starts by 1 and not by 0. ????

Whats new and was never mentioned by you so far are the different step widths k (this variable needs to be of unit length!).

Furthermore the values in the vector you call "a" in your last sheet seem to have a different meaning now as they now are one less the number of times the value of d is taken or better its the number of times the new increment/step k is added to the base thicknesses in d, starting with 0!

So to get the 1000 entries for your three element vector d you have to chose "a" to be all 9's and not 10's!

Attached the modified program to accommodate the new changes and I also changed it so that d1 is modified first and the other values stay constant rather than doing it the other way round as in the original "doIt" program.

 

I also added a simple version using nested for-loops. You may change the values in the three vectors but the program will only work for two elements.

Werner_E_0-1738371535423.png

If you want to work it for three-element vectors, you would have to add another for-loop around the already existing ones.

Werner_E_1-1738371891626.png

 

 

View solution in original post

19 REPLIES 19

In kJ definition set label as Unit

Main loop is i = 1..n In the three times through the loop you set delta ’s three elements
in the first time through the loop you use delta 2 and delta 3 but they are not yet initialized as you have not gone second and third time through the loop yet

@terryhendicott 

Thank you, Terry, here it works

Ivan_Pat_0-1737887863468.png

And here also (as I got from your tip)

Ivan_Pat_1-1737887958357.png

 

 

Main loop is i = 1..n In the three times through the loop you set delta ’s three elements
in the first time through the loop you use delta 2 and delta 3 but they are not yet initialised as you have not gone second and third time through the loop yet

 

Capture.JPG

@terryhendicott  Now I see what you mentioned, Terry, but still, I have no idea how to assign symbolic ranges of a1, a2, and a3 for my variables  (ksi_j  the first), (ksi_k the second), and (ksi_p for the third or i-th layers? in general), respectively.

Ivan_Pat
12-Amethyst
(To:Ivan_Pat)

@terryhendicott I probably have to get the basics of FOR loop iteration...

@terryhendicott, I decided to split the global goal into smaller parts.

Unsurprisingly, I have figured out. that even in the beginning, I  cannot get the desired results:

For instance, I expected to receive the list of parameter delta here:

Ivan_Pat_0-1738056207182.png

I got only one of the delta  suppose of the last layer...

The iteration from 1 to n  isn't works as it should ( in terms of my Matchcad experience).

 

Werner_E
25-Diamond I
(To:Ivan_Pat)

The result of a Mathcad programme always is the result of the last calculation done in the program. In your case thats the last assignment in your loop when i=n.

To return the the full vector delta, simply write delta (or return delta) as the last line of your program beneath the for-loop (nit inside the loop).

I am not sure what you intend with the variable dtot. If you want a header for your vector of values on top, you may write stack("delta", delta) as your last line.

The assignment of dtot inside of the loop does not make much sense as you would overwrite each time the last assignment done.

You may use

Werner_E_0-1738071012388.png

or

Werner_E_1-1738071040072.png

And if your dtot assignment should have just been a programmers comment, you may use the string alone without assigning it a variable

Werner_E_2-1738071118525.png

 

BTW, to be independent from the setting of the system variable ORIGIN (you have set it to 1) and also not needing the variable "n", you may define the loop shown in the pic below

Werner_E_3-1738071335297.png

 

Ivan_Pat
12-Amethyst
(To:Werner_E)

@Werner_E Thank you, Werner. You clarified my MAthCAD black box a little bit.

May I  want to create the list of permutations without repeating of two values d1 and d2 being iterated with i-th and j-th increments: 

As I get from the output - its smth huge which is the  values production result...

Nested loop assign to each j-th value i-th value. For instance

d1=0.01m

d2=0.01m

range1:  a1=10

range2: a2 =10

for i E 1... a1

  for j E 1... a2

      d1<-i*a1

       d2<-j*a2

What I'm expecting for  in output

  permut_d = [ "d1" "d2"]

                         [ 0.01 0.01]

                         [ 0.01 0.02]

                         [0.01  0.03]

                         [  ...        ...   ]

                          [0.1      0.1]

If we have 2 positions with 10 possible numbers in each one the  total permutation will be 10^2 =100.

Ivan_Pat_0-1738096059467.png

As well other modification doesn't reflects my expectations:

Ivan_Pat_1-1738096467249.png

I convinced that there are simple  and  elegant solution does  exist.

Ivan_Pat
12-Amethyst
(To:Ivan_Pat)

@Werner_E  I guess that the proposed code in this thread could be modified a little:

https://community.ptc.com/t5/Mathcad/Combinations-without-repetition/m-p/350033#M136821 

but as you probably got from my queries, I'm unfamiliar with MathCAD coding. Unfortunatelly...

Werner_E
25-Diamond I
(To:Ivan_Pat)

A similar table could be created a bit simpler with a code like the following

Werner_E_0-1738115681056.png

 

When I used "r" and "c" I was thinking on "row" and "column", when using "R" I had Result or Return in the back of my head.

 

Because I collected the d-values in a vector I could use a second loop for the columns.

 

If you have distinct variables and don't want to collect them in a vector, you could use just one for-loop for the rows and use the row-operator when assigning the three values. As usual there are many ways to skin a cat ...

Werner_E_1-1738116249062.png

 

If you need further assistance, please ask a specific question and attach the Mathcad sheet if necessary.

 

 

Ivan_Pat
12-Amethyst
(To:Werner_E)

@Werner_E  Thank you a lot for the desire to assist.

This is a pretty cool and compact code, but I'd like to obtain all the possible arrangements (permutations) of my layers with repetitions. Each layer is described as iterable for a varied range from 1 to AI value.

The math equation sample is represented here:

Ivan_Pat_0-1738165918477.png

In the attached Prime 10.0.0.0 sample you can see my considerations.

Werner_E
25-Diamond I
(To:Ivan_Pat)

To get the 1000 x 1 vector which you seem to expect, you could program 3 nested loops (for the 3 thicknesses d), each running from 1 to 10 (or better from 1 to a_i). Maybe the loops should run from 0 to a_i if you want to also deal with the case that one of the layers is not present at all.

 

This approach with nested loops of course is quite inefficient, especially if you think of modifying the number of available layers (d). You mayl find more efficient, general and elaborate algorithms for programming permutations in the literature and may try to duplicate them in a Mathcad program.

 

Here is the brute force approach with nested loops for the example with the three letter words. As you can see it would be quite easy to change the number of available letters, but it would require to change the program code if you intended to change the number of letters in the final word.

Werner_E_0-1738181143287.png

 

 

Ivan_Pat
12-Amethyst
(To:Werner_E)

@Werner_E

Thanks a lot for your assistance, Werner. It is more acceptable than nothing for my goal function. Yes, I have heard of the significance of increasing time consumption when nested loops are calculated.

 

Werner_E
25-Diamond I
(To:Ivan_Pat)

My concerns were not about time consuming calculations - after all you have to calculate 1000 results anyway.
My concerns were about the need to change the program in case you add more layer thicknesses (d).

 

Here's a quick hack (sure could be done shorter and more elegant) but I am not sure if you are looking for something like that.

Werner_E_0-1738202893590.png

In case you don't like that the quantities also include zero, you have to make two modifications

Werner_E_1-1738202958091.png

 

 

Ivan_Pat
12-Amethyst
(To:Werner_E)

@Werner_E 

I'm trying to "digest" the proposed code, but there is probably a big gap between the code level and my understanding...
What I'm expecting is the possibility to assign each d-th layer sequences of ai range and  make the matrix of all the permutations (arrangements) with repeats.


Thanks a lot for your patience. I tried to modify your sample a bit, but I haven't had any positive outcomes yet.

I know that my code looks ugly. I need to master my coding skills and understand basic concepts.

Can you recommend such guidelines or relevant literature ( particularly in MathCAD coding)?

Werner_E
25-Diamond I
(To:Ivan_Pat)

As far as I understand the code I posted does what you demand (maybe you are just looking for the last column of my table2 ?).

Otherwise you would have to explain much more precisely what you need and not just ‘assign each d-th layer sequences of ai range and make the matrix of all the permutations’ which at least to me is totally unclear.
Preferably with a very specific complete example of the desired output result. Perhaps only with two thicknesses (but please make them different) and  with a-values of just 3 instead of 10.
Then you should specify the desired nine-row matrix that you expect as output (type in manually).

 

Unfortunately I am not aware of any literature on Prime or Mathcad that I would /could recommend. Just doing it by trial and error.

Ivan_Pat
12-Amethyst
(To:Werner_E)

@Werner_E Sorry for the unclear explanation of my issue.

I suppose in the attachment now, you'll get it 

Werner_E
25-Diamond I
(To:Ivan_Pat)

But thats nearly exactly what I provided with my generic "doIt" program if you make the two changes indicated in my reply above so that the numbering starts by 1 and not by 0. ????

Whats new and was never mentioned by you so far are the different step widths k (this variable needs to be of unit length!).

Furthermore the values in the vector you call "a" in your last sheet seem to have a different meaning now as they now are one less the number of times the value of d is taken or better its the number of times the new increment/step k is added to the base thicknesses in d, starting with 0!

So to get the 1000 entries for your three element vector d you have to chose "a" to be all 9's and not 10's!

Attached the modified program to accommodate the new changes and I also changed it so that d1 is modified first and the other values stay constant rather than doing it the other way round as in the original "doIt" program.

 

I also added a simple version using nested for-loops. You may change the values in the three vectors but the program will only work for two elements.

Werner_E_0-1738371535423.png

If you want to work it for three-element vectors, you would have to add another for-loop around the already existing ones.

Werner_E_1-1738371891626.png

 

 

Ivan_Pat
12-Amethyst
(To:Werner_E)

@Werner_E

 Thank you for your patience and desire to help, Werner!

It looks pretty cool and could be used and intended for several coding realisations.

This code (sample2) looks more understandable (as for me).

 

 

 

Announcements

Top Tags