introduction to the p5 computing lab - university of dwm/courses/1p5_2011/1p5lec...intro to p5 mt...

71
Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray [email protected] www.robots.ox.ac.uk/dwm/Courses/1P5 Michaelmas 2011 1 / 39

Upload: nguyendieu

Post on 18-Mar-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Introduction to the P5 Computing Lab

Lab OrganizerProf David Murray

[email protected]/∼dwm/Courses/1P5

Michaelmas 2011

1 / 39

Page 2: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Lecture 1

The aim of the laboratory

Practical stuff about the labs

The Linux OS: your filestore

A quick word about Matlab

2 / 39

Page 3: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

I: Aims of the laboratory

3 / 39

Page 4: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Aims ...

To begin to equip you with computing competencies ...

that will be used throughout your four years at Oxford forproject work, and so on

that will be useful as an aide to learning when bashing outwork for tutorials

that are central to the professional engineer’s working life— nomatter which speciality you eventually pursue.

4 / 39

Page 5: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Importance of computing in modern engineeringcannot be over-stated

Pervasive in every aspect

synthesis of complex systems (modelling)

analysis of data from experiments

product design and development

real time control of equipment from washing machines tothe space shuttle

communications, web, video, audio

Some examples ...

5 / 39

Page 6: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Complex mechanical design: Millau viaduct

Cable-stayed, masted structureSection span 350 mOverall span 2.5 km

Tallest column 245 mMast height 90 m

Let’s build a set of Eiffel towers ...

perch a road deck across the topof each

stick 90 m masts on the top

6 / 39

Page 7: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

CFD: Weather forecasting/F1 Development

Navier-Stokes equations — no analytical solution

7 / 39

Page 8: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Medical Imaging

8 / 39

Page 9: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Robotics

9 / 39

Page 10: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Comms, Electronic Design: Smartphones

600 MHz ARM processor1GB RAM32GB storageOpenGL graphicsLinux OSUSB, BluetoothGPS, Camera, etc≡ PC circa 2000

10 / 39

Page 11: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Maths + Physics + Software

Being able to use a computer to solve engineering problems isa core skill

It requires mathematical analysis and physicalunderstanding of the problem at hand

but also software skills to write a program to satisfy somea-priori purpose ...

... compute heat transfer in a turbine blade ...... model blood flow in the heart ...

Both are a bit ambitious for your first day so you will start withsomething simpler

11 / 39

Page 12: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Simulate flight of a Saturn V Rocket

Vital StatisticsHeight 110mMax Diameter 10 mInitial Mass 2900 tonnesTotal Launch Thrust 34000 kNStage 1 Burn Time 150 sStage 1 Fuel Mass 2150 tonnes

12 / 39

Page 13: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

II: About the labs

13 / 39

Page 14: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Five × 5-hour sessions

Using the machines on Level 6

The first two lab sessions will introduce you to

the Linux operating system

Matlab — a powerful programming language andenvironment

In the later three lab sessions you

make your own design decisions

write Matlab to simulate rocket flight and controlled landing

14 / 39

Page 15: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

What is required from an academic perspective?

Read through notes the night before

Turn up with lab notes, logbook, cover sheet

Engage brain. Work steadily through the notes, try out thevarious examples AND explore for yourself

Do not worry about getting stuck. There is time to thinkhow to get unstuck, and demonstrators on hand to helpyou (but not to tell you the answer).

Complete the exercises in a timely fashion; make briefnotes in your logbook as you go.

Get assessed — present your results and code to ademonstrator

15 / 39

Page 16: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

The demonstrators’ favourite student

16 / 39

Page 17: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

What is required from a practical perspective?

Turn up on time (no later than 11.05 and 14.05).

Contact the lab organizer by email if you are unable tomake a session through some serious unavoidablecommitment.

Have fun. The labs are meant to be enjoyable ...

... for the demonstrators at least.

17 / 39

Page 18: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

What when? The 8 sets of exercises

Set Purpose Complete by end0 Basic Unix skills EOF Session 1I Basic Matlab Skills EOF Session 1II Extended Matlab Skills EOF Session 2III Simple Dynamics Simulation EOF Session 3IV Simulate Time Varying Dynamics EOF Session 3V Use of structures. Code design and form EOF Session 4VI Thinking in modules EOF Session 5VII Using simulator as a design tool EOF Session 5

18 / 39

Page 19: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Formal assessmentsThere are three assessments

1 At the end of Exercise Set I(and no later than 11.30am of your 2nd session)

2 At the end of Exercise Set II(and no later than 4.30pm of your 2nd session)

3 At the end of Exercise Set VII(and not later than 3.00pm of your 5th session)

These are not terrifying!

The demonstrators will wish to seeyour logbook, your code (commented and working),and may ask you a few on-the-spot questions.

19 / 39

Page 20: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

III: Unix and your filestore

20 / 39

Page 21: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

The only way to learn computing is to do computing

True, but this heads-up on using Unix commands to organiseyour filestore is needed because most of you are familiar withthe Windows style of iconic file manager

Instead you areurged to talk to the operating system by typing commandsinto a terminal windowdiscouraged from drag and drop

Why? Allows much more subtle control, is much faster, and willamaze your friends.

21 / 39

Page 22: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

The terminal window

After logging in, opening a“terminal window” allows you totalk directly to the operatingsystem using Unix commands.

We will worry here about Unixcommands for organizing yourfilestore

And for this you need to picturefile structures as trees(er, upside down trees)

22 / 39

Page 23: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Current working directory: pwdThe root directory is at the topof the diagram

Opening a terminal windowsets you “working” in yourhome directory

Find where you are workingusing%pwd ←↩/u11/abc

Actually probably says%pwd ←↩/home/ENG/u11/abc

At the moment, there are noother files or directories in it

u11

abc

23 / 39

Page 24: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Edit and save a file using gedit

Imagine using a text editor tocreate a file called list.txt%gedit list.txt ←↩

Type anything, then save.

Your filestore now changes ...

List your files using%ls ←↩list.txt

u11

abc

24 / 39

Page 25: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Edit and save a file using gedit

Imagine using a text editor tocreate a file called list.txt%gedit list.txt ←↩

Type anything, then save.

Your filestore now changes ...

List your files using%ls ←↩list.txt

list.txt

u11

abc

24 / 39

Page 26: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Edit and save a file using gedit

Imagine using a text editor tocreate a file called list.txt%gedit list.txt ←↩

Type anything, then save.

Your filestore now changes ...

List your files using%ls ←↩list.txt

list.txt

u11

abc

24 / 39

Page 27: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make directories: mkdir

Make two new directoriesunder your current directory%mkdir P5lab docs ←↩

Again list using%ls ←↩docs list.txt P5lab

list.txt

u11

abc

25 / 39

Page 28: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make directories: mkdir

Make two new directoriesunder your current directory%mkdir P5lab docs ←↩

Again list using%ls ←↩docs list.txt P5lab

list.txtdocsP5lab

u11

abc

25 / 39

Page 29: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make directories: mkdir

Make two new directoriesunder your current directory%mkdir P5lab docs ←↩

Again list using%ls ←↩docs list.txt P5lab

list.txtdocsP5lab

u11

abc

25 / 39

Page 30: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Change directory: cd

Change your working directorywith%cd P5lab ←↩

Check where you are “working”%pwd ←↩/u11/abc/P5lab

and what files are there%ls ←↩

You see nothing because thereare no files or directories underP5lab

list.txtdocsP5lab

u11

abc

26 / 39

Page 31: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Change directory: cd

Change your working directorywith%cd P5lab ←↩

Check where you are “working”%pwd ←↩/u11/abc/P5lab

and what files are there%ls ←↩

You see nothing because thereare no files or directories underP5lab

list.txtdocsP5lab

u11

abc

26 / 39

Page 32: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Change directory: cd

Change your working directorywith%cd P5lab ←↩

Check where you are “working”%pwd ←↩/u11/abc/P5lab

and what files are there%ls ←↩

You see nothing because thereare no files or directories underP5lab

list.txtdocsP5lab

u11

abc

26 / 39

Page 33: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Change directory: cd

Change your working directorywith%cd P5lab ←↩

Check where you are “working”%pwd ←↩/u11/abc/P5lab

and what files are there%ls ←↩

You see nothing because thereare no files or directories underP5lab

list.txtdocsP5lab

u11

abc

26 / 39

Page 34: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Change directory: cd

Change your working directorywith%cd P5lab ←↩

Check where you are “working”%pwd ←↩/u11/abc/P5lab

and what files are there%ls ←↩

You see nothing because thereare no files or directories underP5lab

list.txtdocsP5lab

u11

abc

26 / 39

Page 35: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txtdocsP5lab

u11

abc

27 / 39

Page 36: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

docsP5lab

u11

abc

27 / 39

Page 37: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

docsP5lab

u11

abc

27 / 39

Page 38: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

docsP5lab

u11

abc

27 / 39

Page 39: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

docsP5lab

u11

abc

27 / 39

Page 40: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

func.mprog.m

docsdocsP5lab

u11

abcabc

27 / 39

Page 41: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

func.mprog.m

docsdocsP5lab

u11

abcabc

27 / 39

Page 42: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

func.mprog.m

docsdocsP5lab

u11

abcabc

27 / 39

Page 43: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories

%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

func.mprog.m

docsP5lab

u11

abc

27 / 39

Page 44: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories

%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

func.mprog.m

docsP5lab

u11

abc

27 / 39

Page 45: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories

%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

func.mprog.m

docsP5lab

u11

abc

27 / 39

Page 46: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories

%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

27 / 39

Page 47: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Make more directories

%mkdir sess1 sess2 ←↩

%cd sess1 ←↩

%gedit prog.m func.m ←↩

How to cd into sess2?Go up then down%cd ../sess2 ←↩

How would we copy func.m intothis directory?%cp ../sess1/func.m .←↩

How to cd to “docs” from“sess2”?

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

27 / 39

Page 48: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Moving up and copying%cd ../../docs ←↩OR%cd ∼/docs ←↩

∼ is short for the path to yourhome directory∼ ≡ /u11/abc

Then edit another file%gedit a.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

28 / 39

Page 49: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Moving up and copying

%cd ../../docs ←↩OR%cd ∼/docs ←↩

∼ is short for the path to yourhome directory∼ ≡ /u11/abc

Then edit another file%gedit a.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

28 / 39

Page 50: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Moving up and copying

%cd ../../docs ←↩OR%cd ∼/docs ←↩

∼ is short for the path to yourhome directory∼ ≡ /u11/abc

Then edit another file%gedit a.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

28 / 39

Page 51: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Moving up and copying

%cd ../../docs ←↩OR%cd ∼/docs ←↩

∼ is short for the path to yourhome directory∼ ≡ /u11/abc

Then edit another file%gedit a.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

28 / 39

Page 52: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Moving up and copying

%cd ../../docs ←↩OR%cd ∼/docs ←↩

∼ is short for the path to yourhome directory∼ ≡ /u11/abc

Then edit another file%gedit a.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

a.txt

28 / 39

Page 53: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Typing files at the console: more

Change to your home directory%cd ∼ ←↩

Page by page listing%more list.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

a.txt

29 / 39

Page 54: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Typing files at the console: more

Change to your home directory%cd ∼ ←↩

Page by page listing%more list.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

a.txt

29 / 39

Page 55: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Typing files at the console: more

Change to your home directory%cd ∼ ←↩

Page by page listing%more list.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

ugrads

u10abc

a.txt

29 / 39

Page 56: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Typing files at the console: more

Change to your home directory%cd ∼ ←↩

Page by page listing%more list.txt ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

ugrads

u10abc

a.txt

29 / 39

Page 57: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

DeletingDelete a file once in the homedirectory%cd ∼ ←↩%rm list.txt ←↩

Delete a directory recursively%rm -r docs ←↩Watch out!There is no waste bin

What files would this list?%ls ←↩

list.txt

sess1 sess2

func.mfunc.mprog.m

docsP5lab

ugrads

u10abc

a.txt

30 / 39

Page 58: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Deleting

Delete a file once in the homedirectory%cd ∼ ←↩%rm list.txt ←↩

Delete a directory recursively%rm -r docs ←↩Watch out!There is no waste bin

What files would this list?%ls ←↩

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

a.txt

30 / 39

Page 59: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Deleting

Delete a file once in the homedirectory%cd ∼ ←↩%rm list.txt ←↩

Delete a directory recursively%rm -r docs ←↩Watch out!There is no waste bin

What files would this list?%ls ←↩

sess1 sess2

func.mfunc.mprog.m

docsP5lab

u11

abc

a.txt

30 / 39

Page 60: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Deleting

Delete a file once in the homedirectory%cd ∼ ←↩%rm list.txt ←↩

Delete a directory recursively%rm -r docs ←↩Watch out!There is no waste bin

What files would this list?%ls ←↩

sess1 sess2

func.mfunc.mprog.m

P5lab

u11

abc

30 / 39

Page 61: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Deleting

Delete a file once in the homedirectory%cd ∼ ←↩%rm list.txt ←↩

Delete a directory recursively%rm -r docs ←↩Watch out!There is no waste bin

What files would this list?%ls ←↩

sess1 sess2

func.mfunc.mprog.m

P5lab

u11

abc

30 / 39

Page 62: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Deleting

Delete a file once in the homedirectory%cd ∼ ←↩%rm list.txt ←↩

Delete a directory recursively%rm -r docs ←↩Watch out!There is no waste bin

What files would this list?%ls ←↩

sess1 sess2

func.mfunc.mprog.m

P5lab

u11

abc

30 / 39

Page 63: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

IV: Some quick remarks about Matlab

31 / 39

Page 64: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Why Matlab? I always use Java/C/C++/C#/Lisp/Z

Matlab is ideally suited for engineers for the following reasons.

It is very strong for numerical computing.Gives access to gold-standard numerical methods

It is a compact and powerful programming language withmany of the constructs of modern languages.

It provides fantastic ways to visualise data (2D/3D graphs,animation, surface meshing etc).

It allows interactive code development.

32 / 39

Page 65: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Why Matlab? Even more reasons ...

It is very widely used in industry and universitiesinternationally. It is not a toy language.

It runs on all major operating systems —your code is always operating system neutral.

It provides a conservative programming environment.Code written today is likely still to work in 10 years time.In other environments, code can “rot” in a remarkably shorttime.

It is a very intuitive language, with almost no overheadinvolved in getting going.

33 / 39

Page 66: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Matlab is built on vector and matrix operations

While Matlab handle scalars and strings as any language

Week = 1;Term = ’Michaelmas’;Temp = 21.5;

A key aspect is that it makes vectors and matrices easy torepresent

a = [ 3 -2 1];b = [ 2 -4 -3];c = [-1 2 2];

v = a + b + c;mag2 = sqrt( dot(v,v) );

34 / 39

Page 67: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Another example ...

To solve an example of Mx = b, 3 2 11 2 3−1 0 2

x1x2x3

=

1014

5

code in

M = [ 3 2 1; 1 2 3; -1 0 2] % 3 by 3 matrixb = [10; 14; 5] % 3 by 1 column vector

then

x = inv(M) * b;

35 / 39

Page 68: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Element operations are possible to

If you have a vector v and want a new vector w whoseelements are wi = v2

i , you can write for example

v = [ 1 2 3 4 5 6 7 8 ];w = v .* v; % dot times

This idea works on matrices too!

A = [1, 2; 3, 4]B = [5, 6; 7, 8]C = A * B % Mathematical multiplicationD = A .* B % Element by element!

A =

[1 23 4

]B =

[5 67 8

]A∗B =

[19 2243 50

]A.∗B =

[5 12

21 32

]

36 / 39

Page 69: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

And finally ..

37 / 39

Page 70: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

What to do at Session I

0 Bring notes, cover sheet, logbook, & yellow form1 Find a computer (not too hard ...)

2A If you’ve never logged in via the drawing officeLog in using your single-sign-on usernamebut with password ugrad2011Change password to your single-sign-on password%passwd ←↩and follow the instructions.

2B But if you haveLog in using your s-s-o usernameand s-s-o password.

3 Carry on

38 / 39

Page 71: Introduction to the P5 Computing Lab - University of dwm/Courses/1P5_2011/1P5lec...Intro to P5 MT 2011 Introduction to the P5 Computing Lab Lab Organizer Prof David Murray david.murray@eng.ox.ac.uk

Intro to P5 MT 2011

Learning outcomes ....

You willlearn key aspects of proceedural programming: variables,flow control, functions and abstraction.

acquire Matlab as a tool for engineering computation (andthe rest of this course)

be exposed to software design

have to use you code to analyse a complex system that isotherwise beyond your reach

be enthused (we hope!) about the possibilities moderncomputing offers the engineer.

39 / 39