Message Boards Message Boards

0
|
2811 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Recalling an output or assigning a new variable from another variable

Posted 11 years ago
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.

eg.
(initialization)
SunB = 29000
SunC = 10000
SunD = 2900
(manipulate)
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)
100

I have tried integrating a Which function into the coding, where it give a spectrum output based on which parameter is selected;
eg.
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;
eg.
Which[Star == SunB, "Ultraviolet", Star == SunC, "Visible", Star == SunD, "Infrared"]

(example output - SunB selected)
100.Ultraviolet

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 11 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
Attachments
Remove
or Discard

Group Abstract Group Abstract