1
$\begingroup$

I have a pipe with different insulation sections and a fluid flowing through. I need to calculate the fluid Temperature at the end of every section, to estimate the temperature for the next section. I build my Model with Modules, the equations stay quite the same, but the characteristics (variables) for my insulation varies. For example the Thermal Diffusivity α=λ/(ρ *cp), changes per section. So i dont want to rewrite a Module for every single section. I just want a single Module to call up a Table for the specific section (for simplicitiy and preventing errors). My issue is that the variables i set, are global and hence i have to build many modules and rename my variables. Is there a possibiliy to set same variables, but different value? Is it also possible to set a single Matrix with rows i call up, which represent each section?

For example:

m=Matrix[Section1{λ=1,cp=2,ρ=3},Section2{λ=4,cp=5,ρ=6},Section3{λ=7,cp=8,ρ=9}]

S1[i1_, m_] := Module[{ α=λ/(ρ *cp)}]

S2[i2_, m_] := Module[{ α=λ/(ρ *cp)}]

Thank you in advance

$\endgroup$
1
  • 4
    $\begingroup$ Certainly something can done. But without a concrete minimal(!) example, nobody will be able to help you. Also, the occurence of MatrixForm rang some alarm bells with me. This tells me that you got something fundamentally wrong about its purpose: It is for displaying only. It is not meant as a datatype. $\endgroup$ Commented Mar 2, 2020 at 10:00

1 Answer 1

1
$\begingroup$

There are many ways to go about such calculations. Here is one where the parameter sets are encapsulated with Association, the Wolfram Language's equivalent of what are called hash-tables or dictionaries in other programming languages.

sectionParams =
  {Association[{λ -> 1, cp -> 2, ρ -> 3}],
   Association[{λ -> 4, cp -> 5, ρ -> 6}],
   Association[{λ -> 7, cp -> 8, ρ -> 9}]};
s[sp_] := sp[λ]/sp[ρ] /sp[cp]

Then the calculation is reduced to

s /@ sectionParams

{1/6, 2/15, 7/72}

$\endgroup$
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.