0
$\begingroup$
Clear[Rth, Phex];Rth[tmax_, tin_, qmax_] := N[(tmax - tin)/qmax];Dynamic[Manipulate[Panel[Column[{"Rth:", Style[Rth[tmax, tin, qmax], Red, Bold, 14]
 }, Frame -> True, Background -> LightBlue, FrameStyle -> Red],"Calculated Values :"],Text[Style["Calculator", 20, Background -> LightBlue, 
FontWeight -> Bold]],Delimiter,{{tmax, 80, "Temperature (\[Degree]C): "},ControlType -> InputField, FieldSize -> 5},{{qmax, 5000, "Load (W): "}, ControlType -> InputField, FieldSize -> 5},{{tin, 50, "Inlet Temperature (\[Degree]C): "},ControlType -> InputField, FieldSize -> 5},{{tamb, 25, "Ambient air Temperature (\[Degree]C): "},ControlType -> InputField, FieldSize -> 5},{{m, 1.0, "Flow Rate : "}, {0.5, 1, 1.5, 2},ControlType -> RadioButtonBar, FieldSize -> 5},Item[Button["Calculate", Nothing, BaseStyle -> {15}], Background -> Blue],LabelStyle -> {20}, ContentSize -> 500, Frame -> True,TrackedSymbols :> All,Frame -> True, FrameMargins -> Automatic]]

In the above code, we get the output as a calculated value of Rth (0.006 by default). This value will change as per the user inputs.

I also have one table given below:

CP =  TableForm[{{0.0078, 0.0066, 0.0088, 0.0082, 0.0078},{0.0058, 0.0049, 0.0073, 0.0067, 0.006},{0.0054, 0.0046, 0.0068, 0.0065, 0.0056},{0.0051, 0.0041, 0.006, 0.006, 0.0051}},TableHeadings -> {{"0.5 GPM", "1.0 GPM", "1.5 GPM", 
 "2.0 GPM"}, {"CP-1000", "CP-1001", "CP-1002", "CP-1003", 
 "CP-1004"}}]

Now I want to display one more output beside the calculated value, which will be the table's heading. I have Rth 0.006 as the computed value at 1 GPM in the default case. Now I want to make logic such that the calculated value goes to the table and sees where this value is matched. And display the column heading.

Example: Rth =0.006 at 1GPM (Row). The output will be CP-1004 (2nd row & 5th column). And if the output is not matched with the table value, it should show the nearest smaller value column heading name.

Like: The calculated value of Rth= 0.005 (For different user input), The closest smaller value at 1 GMP Row is 0.0049. At that condition, the Column heading CP-1001 will be displayed as output.

The logic should work the same if the user changes GPM or Row values like 0.5,1.5,2 GPM.

Does anyone have any idea how I can make this logic?

I appreciate any help you can provide.

$\endgroup$
1
  • $\begingroup$ Please improve the title of your post. $\endgroup$
    – Syed
    Mar 23, 2022 at 12:46

1 Answer 1

1
$\begingroup$

Here is a quick and dirty routine to get the heading. It uses the table CP:

Input: rth== calculated value, m== flow rate

getHeading[rth_, m_] := Module[{pos, col},
  pos = Position[ToExpression[StringTake[#, 3] & /@ CP[[2, 2, 1]]], 
    N[m]];
  col = Position[CP[[1, pos[[1, 1]]]], 
     Nearest[CP[[1, pos[[1, 1]]]], rth][[1]]][[1, 1]];
  CP[[2, 2, 2, col]]
  ]

Here is an example:

getHeading[0.0052, 1.5]
(*"CP-1000"*)
$\endgroup$
31
  • 1
    $\begingroup$ E.g.: Row[{Panel[ Column[{"Rth:", Style[tmp = Rth[tmax, tin, qmax], Red, Bold, 14]}, Frame -> True, Background -> LightBlue, FrameStyle -> Red], "Calculated Values :"], getHeading[tmp, m]}] $\endgroup$ Mar 23, 2022 at 13:10
  • 1
    $\begingroup$ Simply change "Neareast" to "Min" $\endgroup$ Mar 23, 2022 at 13:53
  • 1
    $\begingroup$ I think you should make an effort to learn the mathematica language. Here is a function that gets the value from row and column headings: getValue[row_, col_] := CP[[1, Position[CP[[2, 2, 1]], "1.5 GPM"][[1]], Position[CP[[2, 2, 2]], "CP-1001"][[1]]]][[1, 1]]and the is an example: getValue["1.5 GPM", "CP-1001"] $\endgroup$ Mar 31, 2022 at 11:44
  • 1
    $\begingroup$ Sorry, here is the correct function: getValue[row_, col_] := CP[[1, Position[CP[[2, 2, 1]], row][[1]], Position[CP[[2, 2, 2]], col][[1]]]][[1, 1]] $\endgroup$ Mar 31, 2022 at 19:09
  • 1
    $\begingroup$ Try e.g.: getValue["1.5 GPM", getHeading[0.0052, 1.5]] This gives 0.0054. I think your mistake are the quotation marks around getHeading[..]. If you really want to give "getHeading[ rth,m]" as a string, you need to wrap ToExpression around it. $\endgroup$ Apr 2, 2022 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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