Upload
vuongkhuong
View
218
Download
0
Embed Size (px)
Citation preview
Usual apologies
Computing Lab started in Week 1 … Lectures in Week 3 (?)
The schedule gods rule the schedule
Lectures about computing
will not teach you how to program computers
Learn by doing in the Computing Practical Lab
But also: Lots of fun/free interactive tutorials online !
These Lectures
Complement (not duplicate) online course material
But a bit about the Practical Lab & getting started with MATLAB
Describe (language independent):
Fundamental aspects of computers and computing
Programming guidelines and best practices
Some warnings and pitfalls
Motivate: just in case you are not excited already !
MT 2016 Computing -- Gallas 2
Before we get started
MATLAB is
computing environment and 4th gen. programming language
“proprietary” (www.mathworks.com) i.e. not ‘open-source’ Oxford-wide license for research/study Use Computing Lab Macs OR
Download MATLAB on your laptop: http://www2.physics.ox.ac.uk/it-services/categories/matlab
https://register.it.ox.ac.uk/self/software/
MATLAB Primary purpose: numerical computing
Strong user base: engineering, science, economics, …
Some MATLAB functionality highlights: Matrix manipulations
Plotting of functions and data
Implementation of algorithms
Creation of user interfaces
Can be interfaced to other languages (C,C++,Java, Fortran, Python)
MT 2016 Computing -- Gallas 3
MATLAB: “MATrix LABoratory”
http://www-teaching.physics.ox.ac.uk/computing/
Students work independently (no partners)
Keep your own logbook; Write your own code, programs
Objectives, material, deadlines
See the Prelims Handbook and links therein.
I notes the Deadlines here (as in the Handbook):
Michaelmas:
CO01 (late in/after week 7)
Advise: finish/mark ASAP (or before week 5)
CO02 (late in Hilary)
Advise: finish/mark before week 8 (last week of the Lab)
Hilary:
Choose one of the CO6x exercises (doom after week 7)
Advise: finish/mark before final weeks 6,7 to avoid queues
MT 2016 Computing -- Gallas 4
Computing Lab General
Computing Lab is OPEN ! weekdays during working hours Booking is not strictly enforced (generally open spaces found)
“Demonstrators” in the lab: help and assess !! Prelims Demonstrators are in the lab (for marking & help):
Thursday and Friday: 10:00-13:00 and 14:00-17:00
Bulletin board (in the Lab): Show demonstrator schedule and their pictures
How to: Ask for help or for getting marked in lab Get a demonstrator’s attention
Don’t be surprised if you have to wait
Continue working as far as you can at your computer
Demonstrators should get to you ~ in sequence
Alternative to Lab computers: Work on your own laptop Follow instructions for installing MATLAB
In the Computing Lab Practical Course webpage
Demonstrators: can’t really help sorting your laptop issues
In First year Computing, you must use MATLAB In Second Year: you may choose other languages (on request)
MT 2016 Computing -- Gallas 5
Computing Lab Operations
See the notice board In the Computing Lab
Demonstrators are
Happy to help
Ready to mark
MT 2016 Computing -- Gallas 6
Our Demonstrators:
MT 2016 Computing -- Gallas 8
Computing introductions usually start with the evolution of logical signal processing hardware and storage … I just summarize here: • 1937: vacuum tubes • 1947 … 1955: transistors • 1958 … 1960: integrated circuit • 1970s: microprocessor
But to me: something more fundamental and useful in terms of computing software execution is the about time and clocks … so I start there …
2000 BC: Shadow clocks
300 BC - 1500:
Water Mechanical clock
1500: Spring powered clock
1656: Pendulum clock
(Huygens)
1930-1960: Quartz clock
1961 Atomic clock
MT 2016
Some Clock History
9 http://www.explainthatstuff.com/quartzclockwatch.html
Computing -- Gallas
2000 BC: Shadow clocks
300 BC - 1500:
Water Mechanical clock
1500: Spring powered clock
1656: Pendulum clock
(Huygens)
1930-1960: Quartz clock *
1961 Atomic clock
MT 2016 Computing -- Gallas
Modern Computers: based on clocks
10
Fundamentally:
A Computer is a clock
The CPU (Central Processing Unit)
logic is driven by a clock
With every CPU clock tick, the CPU is
able to execute one instruction
+ logic
+ memory
Computers everywhere (1)
MT 2016 Computing -- Gallas 11
hilarioushumorfromouterspace.tumblr.com
newportoregon.gov/dept/npd/atmsafety.asp
.. From the obvious …
www.thecolor.com/Coloring/Bus.aspx
The principle is similar to that used by noise-cancelling headphones only the microphones and speakers used in automotive exhaust systems must be more powerful and capable of withstanding the intense heat and corrosive environment of an automobile exhaust.
Active Exhaust Noise Cancellation
The microprocessor monitors the
engine operation and/or the
acoustic frequencies propagating
in the exhaust pipe and generates
sound that is out-of-phase with the
noise generated by the engine.
… to the not
so obvious…
MT 2016 Computing -- Gallas 12 http://www.cvel.clemson.edu/auto/systems/active_exhaust_noise_cancellation.html
Time measurement clock technology (+ machine logic, storage): dramatic shift !
For the last few (~4) thousand years We used the most precise mechanical devices
available to measure time
In the last 50 years: We are using cheap / precise / high frequency clocks discovered
in the process of improving time measurement [+ logic + storage] to drive ever more precise mechanical devices !
We are amassing human knowledge on an unprecedented scale
And over the last ~20 years This has also enabled more “information” than ever before to be
available at your fingertips !
what comes next is what we make of it
our ability to “compute” is key to develop the systems we envision
MT 2016 Computing -- Gallas 13
Profound transition !
Computing
elements (2)
CPU : Central Processing Unit
Clock: ticks at “Clock Speed” or cycles per second (Hz)
Synchronizes all compute operations
Typical rate MHz - GHz (GHz: 1,000,000,000 ticks/second)
Its rate factors into performance of the CPU
HIGHER: ~Faster, but runs hotter, consuming more power
LOWER: ~slower, less costly, less power [longer battery life]
Logic: programmable input to the processor
Format called “bytecode” (“machine code” is another form)
Compilation converts your program code into “bytecode”
At each clock tick: process one instruction or piece of data
Memory: Stores “State” of machine at each point in time
For example: values of program variables
MT 2016 Computing -- Gallas 14
Compute
input output Clock
+ Logic
+ Memory
Details about CPU/processor/memory internals:
See www Outside the scope of this course !
We are here to learn “programming”
MT 2016 Computing -- Gallas 15
Computing
elements (3)
processor input output
program
memory
Instructions
‘State’
“bytecode”
MT 2016 Computing -- Gallas 16
How Matlab looks (GUI)
Command Window:
type commands here
What you’ve
stored
What you’ve
done
Files
Snapshots
exit
Type this in the Command Window
Press the ENTER or RETURN key
Restart if needed
This should always clear up catastrophic confusion
clear
For slightly less drastic problems
clears your storage without having to exit MATLAB
help
Type this followed by a command or function
These are also available in the menus
MT 2016 Computing -- Gallas 17
Most important MATLAB commands STAY CALM
AND
TRY AGAIN
There is no magic:
Even if it appears to work like magic
Back to the clock:
Computers do one thing at a time/clock tick
Clock is fast on a human scale ! Only seems simultaneous
Coded instructions are executed sequentially
Your program executes “top down” (one line at a time)
the next line can only know what has happened before it
We don’t write “bytecode”: We use “higher level languages” HLL (level level of abstraction from machine language)
Examples: Fortran, … C, C++, python, MATLAB, …
HLL syntax is built on lower level constructs:
Gives us a “shorthand” that hide the lower level constructs
More natural for humans readable (but still precise) code !
Note the implications:
One line of HLL code != one instruction for the CPU But the advantages far outweigh the disadvantages
MT 2016 Computing -- Gallas 18
Getting started …
A(ny) computing language
You are talking to a machine You cannot hurt its feelings
You are learning a new language Nouns: variables, class objects, …
Imply a thing
Verbs: operators, functions, … Imply an action
Statements combine the above Order within statements: dictated by syntax rules
Order of statements: determines your program logic Computers execute commands sequentially (think: clock !)
Computers do exactly and only what you tell them to do Using syntax as they understand it
Important to understand precisely the syntax, order
Computing language is very precise EVERY character is important
MT 2016 Computing -- Gallas 19
I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.
~Author Unknown
Best Language: Depends on intended application But also what’s trending is of interest
developing skill sets of general, marketable interest
The Most Popular Programming Languages of 2015 http://spectrum.ieee.org/static/interactive-the-top-programming-languages-2015
MT 2016 Computing -- Gallas 20
Programming languages
Simple statements:
assignment: A = 5;
call: CLEARSCREEN();
return: return 5;
assertion: assert(x > 0);
goto: goto next; beware !
Compound statements:
block: begin prompt('Number?'); readline(myNum); A=A*myNum; end;
do-loop: do (this) block1; while (that is true)
for-loop: do (this) n-times
if-statement: if (this1) block1; else (this2) block2;
switch: switch (c) { case 'a': alert(); break; case 'q': quit(); break; }
while-loop: while NOT EOF DO begin READLN end
MT 2016 Computing -- Gallas 21
Statement Overview (Note: not language specific)
Statements are the
• sentences and
• paragraphs
of our new language
Starting point for any development:
Decide Input / Output …
then we think about what happens in between (Compute) What are the INPUT(s) ?
What are the OUTPUT(s) ?
MT 2016 Computing -- Gallas 22
Computing
elements (4):
Example ATM
Compute input output
INPUT:
ATM card
PIN number
Choose service
Prompt for more …
OUTPUT:
Display
Service dependent:
Cash ?
Balance ?
Receipt ?
ATM card … or NOT !
MT 2016 Computing -- Gallas 23
Computing
elements (5):
Example ATM
Compute input output
Next time:
We build the “Compute” element
forming statements and blocks
and putting it all together !
Revelation starts with your first line of code
Computing Practical Lab: a good place to start
Today, I talked about
Computing Lab Basics, MATLAB
Clock history … how cheap / precise / high frequency clocks make modern computing possible
Why the clock is fundamental:
driving logical progression and outcomes
Higher Level Languages and “Bytecode”
Overview of Statements:
These are the sentences of computing languages
Next time … turning Statements into programs
Variables and scope, operators, logical blocks, loops, …
Best practices: for writing code and making plots
MT 2016 Computing -- Gallas 24
Summary Day 1