Message Boards Message Boards


Recalling an output or assigning a new variable from another variable

Posted 10 years ago
1 Reply
0 Total Likes
Hi I am new to Mathematica and I don't understand how to compute my request;

I have learned how to use the Switch function and trying to integrate it into a test project. My aim is to be able to select a parameter from a switch, then use that value of the selected parameter to output several variables; In this case, I am using the temperature (K) of several Suns to output a wavelength (nm) and spectrum output (UV, V, IR) individually.

SunB = 29000
SunC = 10000
SunD = 2900
N[2900000/Switch[Star, SunB, SunB, SunC, SunC, SunD, SunD]],
{{Star, SunB, "Star"}, {SunB -> "Sun B", SunC -> "Sun C", SunD -> "Sun D"}}

(example output - SunB selected)

I have tried integrating a Which function into the coding, where it give a spectrum output based on which parameter is selected;
Which[Star <=100, "Ultraviolet", Star >100 && Star <1000, "Visible", Star =>1000, "Infrared"]

I am aware that using this function as is, calls the value of Star, which is either SunB, SunC or SunD, whichever is selected. I am unable to find a way which it can call the value or whichever 'Star' is selected, similarly used in notebook using a % to recall the value which was last output. I can integrate a Which function with defined parameters such as;
Which[Star == SunB, "Ultraviolet", Star == SunC, "Visible", Star == SunD, "Infrared"]

(example output - SunB selected)

However I want to develop the demonstration further which requires being able to output the two different variables, I could see two options; one being able to recall the wavelength to compute its spectrum, the other which can put the wavelength into another variable which I can then use, neither I have had any success with.
POSTED BY: Ashley James
Posted 10 years ago
I worked this out a few hours after posting it; as it was using a single variable I was able to remove the Switch function and replace it with just a Which function. The other solution was just to reapply the equation a second time for wavelength, computing the equation for each output.
POSTED BY: Ashley James
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract