Scientific Computing Skills 5. Lecture 01.

Scientific Computing Skills 5. Lecture 01.

>>Welcome to Chem 5. I’m your instructor Doug Tobias. Looking forward to working
hard with you all quarter long and hopefully having lots of
fun learning useful things. So, the first thing that
I should tell you is that if you turn around you
will see that the lectures for Chem 5 are being filmed. And this is part of a
big project on campus which is called Open Courseware. And we’re trying to get all of our required undergraduate
chemistry courses archived, both for UCI students
as well as Planet Earth. And that’s an exciting project. And I’ve agreed to
participate in this. One thing I should tell you is
that if you feel at all strange about having the backs of
your heads appear on film or, perhaps more embarrassingly,
if you happen to be doing something other
than Chem 5 related things like looking at your
Facebook, it may actually show up on the film, you might
want to sit on the other side of the classroom so that you’re
not in the eye of the lens. Okay? All right, so what I
like to do before I get started with the course is to figure
out what’s the composition of our class so I can figure
out who I can make jokes about. So first of all,
is there anybody in the room who’s not
a chemistry major? Raise your hand. Okay. Is there anybody in the room who’s a
chemistry/biology double major? Ah, can’t make jokes
about bio majors then. What about engineers? Any double majors
with engineering? Okay, good. We can pick on the engineers. All right, so we’re going
to get right to work today. You might be thinking
that’s a little strange because this is discussion. Well, in this course,
there’s no distinction between the discussion
and the lecture. The only distinction is is that the discussion
is 50 minutes long and the lecture is
an hour and 20, okay? Now, you might be thinking
well that’s kind of unfortunate because I actually
like to discuss. Well, the good news
is that you’re free to discuss both during the
discussions and lectures, okay? So this is going
to be hopefully, a somewhat interactive course. All right? So, feel free to
discuss anytime you want. All right, so now what I’m
going to do is I’m going to very quickly go
over the syllabus just to make sure a few
things are clear. I expect that you
all have read it as I instructed you
to do last week. All right, so first of
all, here’s our homepage. And there’s not much of
interest on the homepage except for this really cool picture. And you’ll actually learn how
to make really cool pictures like that this quarter. And it’s not very difficult. The only thing to notice
maybe is the announcements. So every time I update the
Website, unless I forget like I did today, I’ll say
when I updated it, okay? So today I posted the homework
assignment, but I forgot to update the announcements. Anyway, we’ll talk
about that later. Okay, now, so if you see that
there’s been a new announcement since last time you were here
and you might want to check at least once a week, you can
go and see what I had to say. So here’s the announcement that you’ve already seen
welcoming you to the class and telling you to go
read the syllabus, okay? So let’s have a quick
look at the syllabus. So first of all, this is going
to be really confusing for me, but hopefully not for you. I’m actually teaching
two sections of Chem 5 concurrently,
all right? And the schedules
are really weird. So from time to time I’m
going to get really confused. But, the one thing I can tell
you is that this is Section B. And your TA is named
Vera Prytkova and she’s sitting
right over there. And she’s going to
be a very good friend of yours this quarter. She’s going to be
helping you a lot and especially with
your homework. So you should be nice to her. And if you are, then
she’ll treat you well. Okay, another thing
is, we’re not going to hold regular office hours. We’re going to be seeing a
lot of each other in here. There will be lots of
opportunities for us to talk to one another, answer
your questions. But that doesn’t
mean that we are against seeing you
in our offices. So, if you have anything
you want to talk about outside the
classroom, please feel free to make an appointment either
with Vera or myself, okay? Don’t feel intimidated. Another thing is about emailing. There’s probably not a
whole lot of reasons to need to be emailing us,
especially because we’re going to see each other so
much in the class. If you do so, just
keep in mind that a lot of what we’re doing
is fairly technical and sometimes it’s hard to discuss technical
things over email. And so you know, be patient
and we’ll try to figure out how to best address your
concerns via email. But, like I say, most of
the time we should be able to take care of anything
you want to know here in the lecture. Now, if you do want to send
emails, there’s a couple of ground rules so that we can
distinguish your very important emails from all the lousy
stuff that comes our way. And that is that you should send
your email from a UCI account and be sure to include your full
name and your student ID number at the bottom of your email. That will help us a lot. Okay. What else? So by now you probably
know when we meet. So we have the two
lectures — wait a minute. We’re actually Section A.
What are you doing here? Sorry, Vera’s not your TA. Your TA is not here today. Her name is Krista. See, I’m already confused
about the sections. All right. Well, in any case,
you can hang out Vera. This is your class. And like I said, very
importantly, you’re expected to come to both lecture
and discussion and one of the two labs. You don’t have to go to both. And the labs are very
important because that’s where you’re going to get
your homework done, okay? So the whole purpose of the
labs is for you to do homework and get help from your TA. And most of the time you’ll get
your homework done in the lab, so you won’t actually have to take it home with
you, all right? Now, if you don’t finish in
the lab, and that will be rare, then you’ll have opportunities
either to come here or to some other computer
lab that has the software that we’re going to be
using, which I’ll talk about in just a second,
all right? Now, strictly speaking, you
don’t have to go to the lab to which you’re assigned. You could go to the
other one, but we would like to encourage you as much
as possible to go to your lab because otherwise if there’s
a lot more students in one lab versus the other, it will
be harder to give help to the larger section. Right now they’re fairly
equally balanced, okay? So, but from time to time,
you may not be able to make it to one and you can
go to the other. Okay. Now, course materials. So, in this class
there’s no book. The book is the notes, which
we’ll get to in a minute. And those were prepared
specifically by me for this class, okay? They’re free. And the one thing that you might
consider is to purchase a copy of the software that
we’re going to use. This course we’re
almost exclusively going to be using a software
package called Mathematica. How many have heard of or
used Mathematica before? Okay, a few. All right. So that’s what we’re
going to do. And we’re going to
start from zero assuming that you don’t know anything. And we’ll work our way up to solving really
cool chemistry problems. And the goal of this class — well one of the goals of
this class is to prepare you to be able to use
Mathematica to do things like physical chemistry
homework, to do things like analysis and
representation of datasets from your lab classes and your
research and to introduce you to a very, very powerful
software package that is sufficiently
impressive that if you list it on your resume, which you
will have the right to do if you pass this class, then that may actually be
a good feather in your cap when you’re looking for a job. Okay? It’s definitely
well recognized as a very, very powerful software package. All right. Now, we don’t have a book, but
some people like to have books. And so there are many, many
books written about Mathematica. There are not really any
good ones on chemistry, but if you want just general
introductions to the software, I listed three here
that I’ve looked at that seem somewhat useful,
especially at the beginning. So you may want to
have a look at those. All right. The grades. So, this class is
a hands-on class. We’re teaching you the
techniques and we want you to show that you can use
those techniques, all right? And most of the way that
you’re going to show that is by doing your homework,
all right? And homework’s extremely
important, so it’s representing 50
percent of your grade. All right? We’re going to have a mid-term around the middle
of the quarter. That’ll be about 20 percent. And then we’ll have a final
exam during finals week, and that’ll be 30
percent, all right? Now, I want to say a few
things about the grades. So first of all, this is a
class for chemistry majors. We love our majors. We want them to learn. And in this class, I don’t
want you to be intimidated by worrying about
your grade, all right? If you do your work by
yourself, and that’s the key, and don’t cheat by
going to somebody who took the class some
years ago and get their work, and if you can show a
reasonable proficiency — and reasonable is a very
liberal definition — then you’ll get a good
grade in this class. And by good grade I mean
an A or B. It’s really hard in this class if you actually do
the work to get a lousy grade. You’ll have to try
really, really hard. The best way to get
a lousy grade is to not do the work yourself
and not turn it all in. That may cost you. But otherwise, you’re
guaranteed to get a good grade and you shouldn’t worry about
it, even if you’re struggling, because some of you will. I know this from experience. Okay? All right. Now, when you’re
doing the homework, you will certainly benefit
greatly from a lot of advice and consultation with the TA
in the lab sections, okay? And that’s fine. You also may discuss with your
classmates certain aspects of the problems. But in the end, you
should do your own work. That’s the main rule
of this course. You’ve got to do your own work. Okay? All right. Now, here are the exams. So you know when they are. And basically, the exams
are going to be the same as the homework assignments
except you won’t get help from the TA or me, except
maybe to clarify the question. So this is really to see if you
can take what you’ve learned by doing homework and do it
again but without help, okay? So not really super difficult. And one thing about all
of the work in this class, with the exception of
copying off classmates, and/or using work
from previous years, everything is available
to you at any time. If you want, you can
wheel in a rack of books to use during your
homework and exams. You can use anything
that you can find on the Internet except work
related to this course. It’s all available. And in fact, you can use, and I
expect you to use and advise you to use, your homework
assignments and the notes from this class because I will
never ask you to do something that I did not teach
you how to do. All right? So the notes in particular will
be very, very useful to you. All right? Okay, so you can read what I
have to say about cheating. I expect that you won’t do it. And you can also read, if for
some reason you need to deal with enrollment, I can’t do
anything with enrollment. You have to talk
to the nice people over in the chemistry office
who you probably know very well. Okay, now, a couple of
other little things. And then we’ll get to work. Woops. Let’s see. So when I post homework
assignments, they’ll be on the homework page. And so for example, here’s one. It’s going to be a PDF file. It’s going to have
some problems on it. They look long and
intimidating, but they’re not. It’s mostly because I
want to explain to you in gory detail what
you’re supposed to do. We’ll talk about the
homework tomorrow. Your labs are on
Wednesday, so I’m going to tell you basically how
to do your homework tomorrow at the end of lecture. If you want, you can look at it. And if you know how to do it,
you can already get started. Now, everything that
you do, every assignment in this course including
the exams is electronic. And it’s going to be
turned in electronically. All right, I haven’t set it
up yet, but there’s going to be a drop box
available to you. It’s going to say
something like homework 1. And you’re going to turn in
your assignments in drop boxes for every assignment
including exams, okay? And I assume that you
know how to do that. If you don’t, there’s
some instructions here that you can follow. In our class most of your
assignments are going to be what’s called
Mathematica notebooks. So, all you have to do is
name your file something like HW1, say, dot MB. That’s the extension for
Mathematica Notebook. Your name will automatically be
put on it when you turn it in. So you don’t need
to put your name. Just keep it simple. Homework 1, mid-term, final. That’s all you have to do. Okay? All right. One last little thing. Here on the links page are
some important things, okay? So first of all, this is
basically your textbook and the auxiliary
files that go with it. All right? I’ve organized the material
into what I call lessons. They’re somewhat arbitrary to
the way they’re divided up. And we’ll most likely make
it through all of them. Okay? So I assume you’ve
read the introduction, which just gives you a
brief overview to the class. And today we’ll start
on Lesson 1. Okay. Now, are there
any questions about what I just told you about
how the class is going to work? Okay. All right. So, I already kind of
alluded to it, but I just want to say a couple more
things very briefly about what we’re
going to do here. So first of all, you
guys are really lucky. You’re really lucky
because you are living on the very highly evolved tail
of what’s called Moore’s Law. Has anybody ever
heard of Moore’s Law? No? Okay, well Gordon
Moore, who founded Intel, the company that made
the processors that are in most PC’s nowadays. Back in the mid-60’s,
when I was a baby and way before you
guys were born, he said every two years
the computing capacity of integrated circuits, so the CPUs in your
computers, will double. And the price will
remain roughly constant. Moore’s Law has been very, very closely followed
for about 35 years. And there’s lots of talk
about it coming to an end. But in any case, what this means
is is that there’s been a huge, huge improvement in
computer capabilities. And so now, you know,
computers run your cars. You have your little Smart
phones, you have your laptops. Computers are everywhere. And importantly for us,
they’re in the chemistry lab. When I was an undergrad,
I used to have to make graphs on graph paper. Have you ever seen graph paper? Yeah? And we used to use
slide rules, not calculators. And then toward the end of my
undergrad we used calculators. And even programmable
calculators so we could calculate
something like a mean in about 20 minutes
from, you know, 50 data points or something. Okay? Now, everything’s
computerized. It’s very easy to use. And you are living in the age where that is available
to you, all right? Now, one of the —
well, there are many, many amazing software
packages that have been written over this period since I was
an undergrad that are very, very powerful at
doing a lot of things that are relevant to chemistry. One of those is Mathematica. And hopefully in this course
you’ll get a taste for some of the things that you
can do in them, okay? And the main objective of this
course is to make you familiar with the program so
that you can use it to do useful things later. All right? And what you’re going to be able to do is you can use
it as a calculator. You can use it to read in,
manipulate, plot, fit data, do statistics, output data. You can use it to solve
systems of equations that would be very difficult
if not impossible by hand that are very relevant to
complicated chemical kinetics and chemical equilibrium
problems. And you can use it to do
calculus that’s relevant to many aspects of
physical chemistry, especially quantum mechanics,
statistical mechanics, okay? So you’re going to learn
how to do all those things. Now, you might be thinking, man,
I’m just now taking calculus. Or I haven’t had the math. Well, that’s quite possible. And so, because I’m aware
of the fact that you’re in different places in
your chemistry major degree completion, I’m going
to try to provide for you the appropriate
mathematical or chemical background for
the stuff that we’re going to be doing because the
whole objective here is to teach you how to solve
chemistry-related problems or do chemistry-related data
manipulations using this software package. And at times that’s going
to mean I’m going to have to teach you things
that you don’t know. And it’s going to be quickly. And you’re probably going
to feel like you’re lost. And I’ll just tell you — give you a preview that
this is not a math class. It’s not even really strictly
speaking a chemistry class. This is a computer skills class. So if you don’t get the math or if you don’t get the physical
chemistry that we’re going to talk about, don’t worry about
it because I’m going to explain that stuff, and ultimately
all you have to do is translate
it into the software. And it may sound
intimidating at the moment, but I know from experience
that most of you will find that it’s actually
not so bad, okay? And if it is bad, let us know. Because it’s not
supposed to be bad. All right? Okay. So now let’s go
ahead and get started. So every time, when you come
into the class at the beginning of class, log into your
computer and go ahead and fire up Mathematica. So I’m going to show
you how to do that now. If you haven’t already figured
it out, what we’re going to do is go into this
folder called Apps. Double click on Wolfram
Mathematica 8. And I’m going to — you don’t
have to do this, but I’m going to make my font 1 1/2 times
so that those of you who are in the back can see it. And now, you get
this blank screen. And this is what’s called a
Mathematica Notebook, okay? And you may notice up in the
upper left there’s a little horizontal cursor that’s
blinking, waiting for you to tell the program
to do something. Now, there are many
different modes in which you can
enter information. And we’ll talk about
some of those later, some of the other ones. The default mode is what
I would call command mode, which means you can execute
commands related to, you know, mathematical operations
or whatever, reading and data, et cetera, et cetera. Okay? So we’re going to start with very simple
arithmetic operations. Okay? So the first
thing I’m going to do is I’m going
to type 2 plus 2. And then what you do is
you find the enter key, which is the return
key — woops, sorry. And with a shift, shift enter, you enter this command,
all right? So when I type 2 plus
2, nothing happens. But as soon as I
hit shift enter, that means execute this command. All right? Now, what you see is
that you got a result, 4. That’s the result of
adding 2 plus 2, okay? All right, so that’s your first
— well, maybe not all of you, but for most of you, your
first Mathematica command. Now, I want to say a couple
of things about the format, which you will get used
to as times goes on. Okay, so first of all, every
time you’re in input mode and typing in a command,
you have this thing that says in bracket number. And that number is keeping track
of how many commands you have within a given section, okay? And it keeps track
of them in order of how they’re executed
regardless of where they are
on the screen, okay? And the output corresponding to that command also
gets the number 1, okay? So that’s our first command. Input was 2 plus
2, output was 4. One other thing to notice, over on the right hand side
there are some brackets. And these brackets sort of let you know how your
commands are organized within the notebook, okay? And they’re useful — it’s useful to be able to
keep track of those sometimes. For what we’re going to do
now, you can ignore them. But I just want to
explain to you. So first of all, within a
continuous sequence of commands, there will be one
bracket on the outside that contains all
of those, okay? And every time there’s an input
there will be a little bracket inside that has a little
triangle thing on the top. And every time there’s an
output it’ll be the same. It’ll have a little
line below the triangle. Okay? So these are things
that as time goes on and we start doing more
complicated things, you may want to make use of the fact that
you can manipulate those. So, and we’ll see
that as time goes on. But for now we won’t
worry about it too much. Okay, now, if I want,
I can edit. So suppose I said, well I didn’t
really want to add 2 plus 2, I actually wanted
to add 2 plus 3. So I can go up here and put
my cursor there, backspace, and then if I hit
shift enter again, notice it updates the result. And now you may also notice that
it has replaced 1’s with 2’s because it’s keeping track of all the commands I’m
making in this session. All right. Now, if I want, I can
keep adding commands to this same what we cell. So this exterior bracket here
is denoting a single cell, okay? So, for example, I can do
a multiplication 2 times 3. So multiplication can be done
with the asterisk, all right? So if I do that, shift enter,
I get the result, 6, all right? And notice it’s now 3. And there’s another way that
you can do multiplications, all right? Another way is if
you say 2 space 3. Notice, when I put the
space in and type 3, Mathematica interprets
that as a multiplication. It puts in the times
sign, all right? And that’s something to be
aware of because sometimes when you’re typing in things,
if you have a spurious space that you didn’t notice you
accidentally put in, you may or may not want that
to be interpreted as a multiplication, okay? So it’s good to be
aware of that. So if I enter that, of
course, I get the same result. Now, if I want, I can
break out of this cell. So notice — oops, sorry. These are all individual
commands. If I want, I can
start a new sequence. It doesn’t really
affect things much. You know, I can go down a little
bit and — or I can go up. I’m sorry, I can go up here
in the middle somewhere and add additional commands. So for example, suppose
I want to raise 2 to the power of 3, all right? So 2 to the power of
3, use this carat. All right? So this carat means
2 to the 3rd. All right? So you enter that and
you get 8, as expected. Now notice, even though
I went back and put this in between a couple of commands,
it’s still keeping track of the total number,
and this is 5. This is something that’s useful
to keep in mind because later on as we do more and
more complicated things, we may end up screwing
things up by moving around within the notebook. But don’t worry about
that for now. We’ll see how that works later. Okay. Now, what if you
want to do division? So I’ll come down
here at the bottom. And now I’m going to
do 6 divided by 3. So division is with
the forward slash. Okay? So if I do 6 divided
by 3, I get 2, all right? Now let’s try a different
division. 16 divided by 6. I got 8/3. This shows a very important
point about Mathematica, okay? This is an exact
result, all right? Mathematica in general will
return an exact result whenever it can. Okay? And we’ll see
shortly how you can turn that into an approximate or a
numerical result if you want. All right? One way to do that is to put
an inexact number in somewhere. So here we have two integers,
so this is the exact fraction, 16 divided by 6 reduced
as far as possible. If I want a decimal
representation I just can make one of my numbers a decimal. So if I say 16 point
divided by 6, now this is in principle
an inexact number. And so when I enter that
command, I get 2 and 2/3 or 2.6667, to one, two, three,
four, five decimal places. Now, by default, Mathematica
will return five decimal places. Okay? And we’ll see how to
change that soon enough. Okay? All right. Now, so far all we’ve done is
single arithmetic operations. What if we want to chain
a bunch of them together? All right? So let’s try one. We’ll do 2 times 3
plus 4, all right? So what do you thing
we should get?>>10.>>Should we get first 2
times 3 and then plus 4? Or should we get
2 times 3 plus 4? In general, what happens is
that the operations are executed from left to right and
there is a precedent, okay? And the precedent is
exponentiation before multiplication and division
before addition and subtraction. All right? So if you have a
complicated expression, and you want it organized
in a particular way, you should use parentheses
to group the operations that you want to be
done together, okay? And this is very important and
it’s one of the major sources of mistakes or getting something
that you didn’t’ want to get. It has to do with this
order of operations and not putting parentheses in
the right places, all right? So my advice to you, and
I’ll keep saying this again and again, is to just use
lots and lots of parentheses. Okay? So let’s try this one. We get 10. And that’s the expected result of having first 2 times
3 and then plus 4. Now, what if I wanted to do
2 times quantity 3 plus 4? Well, then I put
in the parentheses. So I’d say 3 plus 4. And what this does is it
forces 3 plus 4 to be executed and then multiplied by 2. So we should get 14, and we do. Okay? Here’s another example. 3 divided by 2 to
the power of 6, okay? Now, what we expect
to happen is 2 to the 6th is going
to be executed. And then 3 is going to be
divided by that, all right? So what should we get? 2 to the 6th is 64. So we should get
3 divided by 64. And we do. Okay? But what if instead
we actually wanted 3/2 to the power of 6? Well, in that case, we
should use parentheses to make sure we get the
3/2 and then power 6. In that case, we get a
quite different result, 729 divided by 64. And notice in both
cases, as advertised, Mathematica returns
the exact result. All right? Okay. Now, we’re going
to be making a lot of use of so-called commonly
used numbers like e. The base
of the natural log. We may also use — we will
also use from time to time, not very often, i,
the imaginary number. So I’m going to show you how
we actually can access those using Mathematica. Also pi. So let’s start with pi. So if I want pi, I can type
capital P and then lower case I. And if I enter, notice that Mathematica says,
yes, I know about pi. And that’s the exact
representation of pi. It’s the symbol pi, okay? All right? And notice what happens if I do
use a lower case by accident. I get a word pi that
doesn’t mean anything. Okay? So that’s something
to keep in mind, that predefined numbers, and
later we’ll see functions and variables in Mathematica
start with capital letters. Okay. Now another one, e.
If I want the number e, I type capital E, all right? If I enter that, notice that I
get the letter e. So it looks like the letter e, but there’s
something special about this one that I want you to
notice immediately, and that is that it’s got
this little slash on it, okay? And that’s to be distinguished
from the true letter e, which you can get by
typing a lower case. Lower case, you get just
e. This is the letter e, which doesn’t mean anything
special to Mathematica. This is the number e that
has this little slash on it that is the actual number. So for example, we can see what
that is by saying report to me e to the power of 1 point. And those of you
who are familiar with the numerical value of
e know that in fact it is about 2.72, all right? If I did that with
little e, I get nonsense. It just spits it back
the way I wrote it. Okay? All right, another one
is i. So if I type capital I, that’s the imaginary number. And notice, as in the case
of e, it’s got a little bit of that double vision
thing going on. And I can check to see that
it’s the imaginary number i by squaring it. So i squared, and
notice I get minus 1. Okay? All right. All right, so those are some
commonly used predefined numbers in Mathematica. Now, I’m going to
introduce you to a few of the predefined
user functions. There are literally thousands
and thousands of functions, and as time goes on
we’ll probably learn about a hundred or so. But I want to introduce you
to a few simple arithmetic or mathematical functions that
we will use commonly, okay? So one of them is
absolute value. Absolute value is capital ABS. And so if I put in for example
minus 5 and enter, I get 5. Now notice, I used
square brackets when indicating the
argument to a function, okay? There’s lots of different kinds
of brackets in Mathematica. This is another source of
many headaches and errors, but I’ll try to help you to
avoid those as time goes on. But whenever you’re
indicating the argument to the function you
use square brackets. Okay? So if I want
to do a square root, the command is SQRT
with a capital. And then I can put in an
argument with brackets. So for example square root of 2. And I get the square root of 2. Once again, you see,
it didn’t give me 1.414 or whatever dot, dot, dot. It gave me literally
the square root of 2. That’s the exact representation. If I want the numerical,
one way I could get that is to say square root of 2 point. Then I get 1.41421, okay? And notice, if I
put in lower case, it just spits it back at me. And that normally means
something’s wrong. All right? So that’s not square
root, obviously. Okay. Now, what if
you want logarithms? Well, logarithms are LOG. and if you just say LOG, so
for example I say LOG of e, you get the natural
log, all right? So just plain old LOG is
understood as the natural log. So if I take the natural
log of e, what should I get? 1. And sure enough, I get 1. Well, we often like to
use other logs, right? So for example, we use
log 10 a lot in chemistry, pH being a common example. So if I want log base
10, there’s a couple of ways I can do that. One is to say LOG 10. That’s a special command
to give me the log base 10. And so for example, if I put
in 100, what should I get?>>2.>>I get 2. All right? Another way to do logs
of arbitrary bases, okay? So we’ll do log 10, but you can
use this to do log of any base, is to actually use the
regular old log command, except now include
two arguments. The first is the base. So this is going
to give me log 10. And the second is the
actual argument, 100. So this is equivalent
to the previous command. And we get 2, all right? So we will see quite frequently
there are multiple ways to get the same answer,
all right? Now suppose we want log base 2? Well, there’s no command
log 2, so what we have to do there is we
have to say LOG 2 and then give the argument. So for example, if I put
in 8, what should I get?>>3.>>3, because 8 is 2 to the 3rd. Okay? All right. What else do we have? How about trig functions? Sine is capital Sin. So if I say Sin of
Pi, what should I get?>>0.>>0. What about cosine? Cosine of Pi. Minus 1. How about inverse
cosine, or arccosine? Well, the way you do that is you
say capital Arc, capital Cos. So if I put in minus
1, what should I get? Pi. And I do. Okay? All right.>>Question.>>Yeah.>>If you want to put like
degrees, like cosine of 60, it should be .5 but
it [inaudible].>>Because the default
units for angles in Mathematica is going
to be radians, okay? And we will see soon
how to convert. But I don’t want to
go there just yet. It’s very easy to convert. But we’ll see that later, okay? But just keep in mind, by
default, I think it’s this way with most calculators,
certainly on computer programs, the units of the
angles are radians. Okay. Now I want to introduce
you to another function that I alluded to earlier, and that is the numerical
representation function, okay? So there’s a function
called N. Okay, so first let’s just remind
ourselves, so if I just type Pi, I get the exact representation. Now, what if I want a
numerical representation of pi? I can say capital
N bracket Pi, okay? So what that does is it converts
my exact number, the symbol pi, into a numerical representation. And as in previous
examples, the default is to give you five decimal places. Okay? So N brackets just
means give me a number, a decimal number, of
whatever’s in the brackets. Okay? Now, what if I
want more accuracy? Well, what I do is I
say okay, N bracket. I say what I want to get the
decimal representation of. And then I say how many
decimal points do I want? So how many — anybody
in here — so some nerds like to show off
how many digits of pi they know. Anybody in here think they
know a lot of digits of pi? How many do you know? [ Inaudible Audience Response ] Yeah, I know about six or so,
so I think I’m pretty good. Well, Mathematica is very smart. Let’s try 100. There you go. There’s pi to 100
decimal places. Piece of cake. All right? So you can get as
many as you want. So the whole point, though,
is it just says convert this to a numerical representation with 100 decimal
places, all right? So I can do, for example,
N bracket, and I can embed within that a function,
square root of 2. And I can say give me
eight decimal places. So there you have it, one,
two, three, four, five, six, seven, eight, okay? All right. Now, there’s another way to use
this N. And the way I’m going to show you how to do this is
useful for other functions. So this is going to
be your introduction to a particular format. So suppose I do some calculation
and I don’t want to type N and put the thing in brackets. But I still want a
numerical representation. Sometimes it’s convenient
to be able to do it sort of after the fact, all right? So here I do square
root of 2, all right? So there’s my square root of 2. Now, if I want a numerical
representation, I could say — I could go up here and say,
oh, I have to type N bracket and put a bracket
on the other side. Well, another way I can
do the same thing is to use this notation:
slash slash N. So look what happens
when I do that. It gives me now the
numerical representation. So this is what’s
called a post-fix. We’ll see other examples later. And it’s convenient
sometimes because you don’t — maybe sometimes you have
a really beautiful thing and you don’t want to make it
look ugly by putting N brackets around it, but you still want
the numerical representation. You could just do this at
the very end, all right? What this literally means
is it means take the result of whatever’s on the left side
of the two slashes and feed it into N. It’s called post-fix. And you can do this
with other functions. So you could say take
the result of this and put something else here
if you want, all right? So we’ll see more
examples of that later. All right. So we have just a
couple of minutes left. So I want to show
you one more thing. All right? And this is something
that can be useful, but it also can be the source
of headaches, all right? So I’m going to show it to you,
and I will occasionally use it. And I encourage you if you think
it’s useful to use it also. But just be aware that you
can get into some trouble. Okay. So what this is is this is
a shortcut to be able to refer to the result of a
previous cell, okay? So for example, the last command that I executed here
was this one, all right? And it’s number 37. Now, if I want to
refer to this number, I can do that with percent. Okay? So let’s see
how that works. I type percent times 10. Okay? So what this means
is it means take the result of the last, the very, very
last command that I entered, which is this one,
and multiply it by 10. So what should I get? 14.1421 whatever, okay? So there it is. Now, if I want, I can do
other things with this, okay? So what do you think will happen
if I say percent times 10 again? Am I going to get
the same number? No. Because now the last
command is this one. So I’m going to get
10 times that, okay? All right, now, what
if I say, oh, I didn’t want to
multiply it by 10. I wanted to multiply it by 100. Can I get to this one? Yes. I can get to that one
by doing the double percent. So double percent means
go back two commands. So 39, 38, all right? And now I can multiply
that one times — well just make it different
by saying 1000, all right? And now I get 1000 times
this one, not this one. Okay? So this can be useful to avoid typing a
bunch of stuff in. But it also, you
have to keep in mind that it refers to
the last command. So for example, if I go
up here, and I say oh, I want to do 10 times this. And I say, okay,
percent times 10. Am I going to get 14? No. I’m going to get
10 times this number, because that was
the last command. And there you have it. Okay? So you have to be
careful if you’re jumping around and you’re using
this percent thing. Okay? Now, other things I can do
is I can say square root of 2. And then I can use the percent
as an argument to a function. So for example I say,
okay, N bracket percent, so I don’t actually have to go and type N square
root of 2, okay? So you can use it
as an argument also. It just means take
whatever was the result of the last command
and use it here. It’s very general. Okay? So, that’s all for today. So next time we’re
going to learn how to plot, make simple plots. And then I’ll tell you
how to do your homework. All right? So next time is tomorrow at 2. Okay? Have a nice day.

3 thoughts to “Scientific Computing Skills 5. Lecture 01.”

  1. I'm interested in making very tiny symbolic computing engine system with ability to work on very tiny computers (microcontroller-based systems), or generating some C(++) code able to cross-compile to this tiny systems and compute my tiny tasks numerically. By the other words, I'm searching info on basics of symbolic methods and it's realisation at very basic level. Can anybody can advice me what free online books or video lectures shoud I found for the first time ?

Leave a Reply

Your email address will not be published. Required fields are marked *