Question Sheet 3 - Challenge Problem Example Answers

Section: Introduction

An easy pitfall to fall into when programming is to define a variable as two different values. One of the keys to avoiding this is structuring your notebook well. We can add extra sections to out notebook by selecting Format -> Style -> Section.

Section 1

1. Add a new section above this line. Title it ‘Section 1’

2. One thing you can do is label each constant with S1 (Section 1), at the beginning as shown below. Add in a section for ‘2’ and ‘3’.

S1mass=2(*kg*)

Section 2

S2mass=3(*kg*)

Section 3

S3mass=5(*kg*)

3. A student has tried to assign a value to ‘1mass’. Why does this not work?

1mass=2(*kg*)

If the number precedes the word, Mathematica treats what we have written as ‘1 multiplied by mass = 2’.

4. Evaluate the cells below:

m=4(*kg*)
v=1(*m/s*)

energy=mv^2/2

The student has made an error in the above code, why did it evaluate to give ((mv^2)/2)and not 2J?

energy=m v^2/2

In mathematica, if you don’t place a space between two letters, it treats them as a single symbol. Therefore, when there is no space between ‘m’ and ‘v’ it treats it as a single symbol ‘mv’.