Mathematica Basics - Using Variables
Introduction
MathematicaÌýhandle's variables in a subtly different way to the way we handle them in ordinary written mathematics. Let's go over the details:
MathematicaÌývariables can have multiple letters in their names, and even numbers (except numbers are not allowed in the first position.) e.g. valid variable names areÌýx, orÌýpressure, or evenÌýsample4. A variable name likeÌý4sampleÌýwould not be allowed, however, and in fact this would be interpreted byÌýMathematicaÌý²¹²õÌý4*²õ²¹³¾±è±ô±ð.
MathematicaÌýhas a built in spelling checker that can sometimes prove a little irritating. Say you were using four variables for a particular analysis, and you wished to name theseÌýsample1,Ìýsample2,Ìýsample3, andÌýsample4. Mathematica would accept the first use of one of these names without complaint, but each subsequent variable's use would generate a warning that the new variable's name may be spelled incorrectly due to the fact that its name is so similar to a variable that has already been used.
Variable names beginning with a capital letter shouldÌýnotÌýbe implemented by the user inÌýMathematica. The reason for this is thatÌýMathematica's own built-in commands and variables all begin with capital letters. Using lower-case when creating your own variables guarantees that you'll experience no conflicts with built-in commands. Having said that,ÌýMathematicaÌýwill not actaully complain even if you do use a capitalized user-variable.
Pay careful attention as you complete these exercises to the differences betweenÌýdelayedÌý²¹²Ô»åÌýimmediate assignmentÌýwhen assigning values to variables.
Evaluating Commands
Remember, as we said in the introduction to the last notebook, in order to tellÌýMathematicaÌýthat you want it to actually evaluate what you have typed, hit the ENTER key over on the extreme right side of your keyboard on the numeric keypad. Again, don't confuse this with the RETURN key, which merely starts a new line of text.
You can now switch to an actualÌýMathematicaÌýpractice notebook by clicking on the icon on the left. It may take a while to start up! Don't forget to come back here when you're done! (You can also return here just to reread the instructions.) See you in a few minutes.
Welcome back! You may be wondering how well you did. Click on the icon on the left to see the answers you should have gotten. (Only the answers are given, so if you don't match our results you need to figure out what you did wrong.)
You're now done with this lab. Next you may go to theÌýTable of Contents for theÌýMathematicaÌýBasics Labs, or go to theÌýTable of Contents for all of the Differential Equations Labs, or simply quit.