Lec5 MatlabProgramming

Lec5 MatlabProgramming - Opinion Polls Physics 257 Lecture...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Physics 257 Lecture 5: More fun with Matlab Prof. Matt Dobbs Physics Department, McGill U. Prof. M. Dobbs, Physics 257 October 17. 2007 3 Opinion Polls ± Question from a student- how do we interpret: z The poll surveyed 1,002 Quebecers from Oct. 10 to Oct. 22. It is considered accurate to within 4.3 percentage points, 19 times out of 20. ± Let’s re-write one of our physics results in the same language: z We measure the period of a pendulum T= 5.1 ± 0.1 seconds z The errors are random and we think the central limit theorem applies, such that they are distributed Gaussian. ± This physics result predicts a period of ____ seconds. It is considered accurate within ____ seconds, _____ times out of 100. Matlab programming Prof. M. Dobbs, Physics 257 October 17. 2007 5 How a computer stores numbers ± The only numbers a computer can store are 1 and 0. z 1 bit boolean number: 0/1 = False/True ± But it can build integers out of binary numbers: z Base 2 (binary), 8 (octal), 10(decimal), 16(hexidecimal) z With 16 bits it can count from 0 to 2 16 -1 = 65535. ¾ 16 bit unsigned integer 0 Æ 65535 z Using 1 bit as the sign (+ or -), it can represent negative numbers too. ¾ 16 bit signed integer -32767 Æ 32768 ¾ 32 bit signed integer (“long”) -2 147 483 647 Æ 2 147 483 648 ± It can build regular text as well by using 8 bits per character (a “byte”), representing 256 unique symbols. We assigned each letter (or other key) in the alphabet to one of these numbers. z The most common coding of this style is called ASCII. ± Floating point numbers can also be built out of binary: z digital devices can’t store them. Built up from integers. z analog devices can store them, with noise.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Prof. M. Dobbs, Physics 257 October 17. 2007 6 Goals for Scientific Programming ± The program should solve the problem z Correctly (the answer should be correct!) z Efficiently (without wasting time/space) ¾ The top two are obvious! z Readably / user-friendly (other people should be able to read it) ¾ With modern computers, we almost always choose to trade speed for readability. z Modularly – so that it is easy to understand. ¾ For this we use functions or subroutines. Prof. M. Dobbs, Physics 257 October 17. 2007 7 Script Files ± Matlab program files have .m extensions. ± We can put any number of commands in a .m file. z
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Lec5 MatlabProgramming - Opinion Polls Physics 257 Lecture...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online