Physics with Mathematica

https://phys.cst.temple.edu/~napolj/PHYS3001/indexF19.html

Instructor: Jim Napolitano
Grader: Ahmed Fouad

(Go to the website, read the “Course Information” link.)

Twelve classes each with an exercise

Exercise can be done by end of class, but you have until 8am tomorrow

Grade is mostly (80%) based on your top 10 exercise grades

Remainder of your grade is a “homework problem” of your choosing

This course should be an “easy A” if you just do the work!

Today’s class: Just some real basic stuff

Remove["Global`*"]

1+1

a=1

a=2;
b=2.5;

a^b

Sqrt[2]^5

N[%]

Pi

N[Pi]

Sin[Pi/2]

Factor[x^n-y^n]

Factor[x^n-y^n/.n->3]

Getting used to the syntax of Mathematica

What did you notice?

The command you enter is executed after “shift return”; Just “return” continues the command onto the next line.

If the line ends in a semicolon, the answer is not printed out.

If Mathematica knows that a variable is defined, it is shown in black. Otherwise, it is blue.

Built-in functions for Mathematica always start with a capital letter. Remember this!!

Arguments of functions are square brackets.

Where to find more information

See the “Documentation Center” in the program, or http://reference.wolfram.com/mathematica/guide/Mathematica.html

Try playing with free-form input, similar to http://www.wolframalpha.com/

Review the “More on Mathematica” links on the course web page

Using “ReplaceAll” with the shortcut “/.”

Remove["Global`*"]

There is a command ReplaceAll, but everyone uses the shortcut.

a/.a->5

aVal=a^2/.a->2.3

Notice that “a” is never changed in these manipulations

a

I find this handy for putting numbers into expressions

expr=a x^2+b y;
expr1=expr/.{a->1,b->2}
expr2=expr/.{a->2,b->-5}

expr

“Lists” and “Simplify”

Remove["Global`*"]

Lists are everywhere in Mathematica. They can contain anything.

list={a,b,expr,5};
list^2

listRoot=Sqrt[list^2]

“Simplify” is useful, but don’t get hung up on it.

Simplify[listRoot]

Simplify[listRoot,Assumptions->{a>0,b>0}]

A simple example before you do your exercise

Remove["Global`*"]

Motion under constant acceleration

y=y0+v0 t+a t^2/2;

Plot the height as a function of time for two different initial velocities

yPlot=y/.{y0->0,a->-9.8};
yPlot1=yPlot/.v0->20;
yPlot2=yPlot/.v0->40;

Plot[{yPlot1,yPlot2},{t,0,8}]