Message Boards Message Boards

0
|
6291 Views
|
6 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Simpler expression and Legends

Posted 9 years ago

Hi all,

Here is what I wrote, but it is not beautiful. Do you think you can write it in a simpler and better way? Another question is I'd like to add Legends saying dashed line is "Receiver efficiency" and solid line is "system efficiency", but I couldn't do that. Any help will be very appreciable. Thank you.

ClearAll
\[Sigma] = 5.67 10^-8; "Stefan-Boltzmann Constant";
\[Epsilon] = 1; "Emissivity";
\[Alpha] = 1; "Absorbtivity";
\[Tau] = 1; "Transmittance";
g = 1 10^3; "Solar radiation 1Kw/m^2";
c = Range[10, 50, 10]; "Concentration";
receff[x_] = \[Alpha] \[Tau] - (\[Sigma] \[Epsilon] (x^4 - 
      293.15^4))/(c g);
syseff[x_] = (\[Alpha] \[Tau] - (\[Sigma] \[Epsilon] (x^4 - 
        293.15^4))/(c g)) (1 - 293.15/x);
Plot[Evaluate[{receff[x], syseff[x]}], {x, 293.15, 1073.15}, 
 PlotStyle -> {Directive[Dashed, Black], Directive[Dashed, Red], 
   Directive[Dashed, Blue], Directive[Dashed, Green], 
   Directive[Dashed, Purple], Directive[Thick, Black], 
   Directive[Thick, Red], Directive[Thick, Blue], 
   Directive[Thick, Green], Directive[Thick, Purple]}, Frame -> True, 
 PlotRange -> {{250, 1000}, {0, 1.05}}, 
 FrameLabel -> {"Temperature (K)"  , "Efficiency (%)"}, 
 LabelStyle -> Directive[Black, Bold, {16, GrayLevel[0.3]}]]

enter image description here

POSTED BY: Sungwoo Yang
6 Replies
Posted 9 years ago

You're right. I just try again by replacing @@ # & /@ with @@@, now, it does not give me any error. I don't understand why there was the error before. But I had similar issue before. There was several codes I wrote and they worked fine initially and at some point stopped working because they generated errors. I think I need more learning to eventually understand this issue. In addition, I also replace = with :=, which also works well. I'm still not good enough to see the difference between = and := in real usage. Your suggested code definitely looks better. Thank you so much for your help. I really appreciate it.

POSTED BY: Sungwoo Yang
Posted 9 years ago

It actually gives me an error saying "An improperly formatted option was encountered. The left-hand side of the option was not a symbol or string." I will take a look at the documentation about "Apply @@@" Thank you for your help.

POSTED BY: Sungwoo Yang

Dear Sungwoo Yang,

I cannot verify any error. I would like to propose some further changes. In particular below I replaced in your definition of the functions receff and syseff "=" with ":=", which might be important. So your already nice code together with Davids improvements and my minor remarks now looks like:

ClearAll["Global`*"]
\[Sigma] = 5.67*^-8;            (* Stefan-Boltzmann Constant*)
\[Epsilon] = 1;                 (* Emissivity *)
\[Alpha] = 1;                   (* Absorbtivity *)
\[Tau] = 1;                     (* Transmittance *)
g = 1*^3;                       (* Solar radiation 1Kw/m^2" *)
c = Range[10, 50, 10];          (* Concentration *)

receff[x_] := \[Alpha] \[Tau] - (\[Sigma] \[Epsilon] (x^4 - 293.15^4))/(c g);
syseff[x_] := (\[Alpha] \[Tau] - (\[Sigma] \[Epsilon] (x^4 - 293.15^4))/(c g)) (1 - 293.15/x);
Plot[Evaluate[{receff[x], syseff[x]}], {x, 293.15, 1073.15}, 
 PlotStyle -> (Directive @@@ Transpose[{Join[ConstantArray[Dashed, 5], ConstantArray[Thick, 5]], 
      Flatten[ConstantArray[{Black, Red, Blue, Green, Purple}, 2]]}]),
  Frame -> True, PlotRange -> {{250, 1000}, {0, 1.05}}, 
 FrameLabel -> {"Temperature (K)", "Efficiency (%)"}, 
 LabelStyle -> Directive[Black, Bold, {16, GrayLevel[0.3]}]]

Henrik

POSTED BY: Henrik Schachner
Posted 9 years ago

Hi David, Yes, this is what I was looking for. It looks simpler and better. I don't fully understand "@@ # & /@", but I guess it takes time. Thank you so much for your help.

POSTED BY: Sungwoo Yang

... Well, in the context of a speech bubble in comics this would mean "swearing", but here it means the same as @@@, i.e. you can write

PlotStyle -> (Directive @@@ 
   Transpose[{Join[ConstantArray[Dashed, 5], ConstantArray[Thick, 5]],
      Flatten[ConstantArray[{Black, Red, Blue, Green, Purple}, 2]]}])

Look for Apply in the documentation.

Henrik

POSTED BY: Henrik Schachner

On the contrary, this is nice concise code!

You could pack up your plot style specification if you really wanted:

PlotStyle -> (Directive @@ # & /@ 
   Transpose[{Join[ConstantArray[Dashed, 5], ConstantArray[Thick, 5]], Flatten[ConstantArray[{Black, Red, Blue, Green, Purple}, 2]]}])
POSTED BY: David Gathercole
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract