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 as 4*sample.

  • 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 and 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.


Mathematica App IconYou 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.


Mathematica App IconWelcome 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.