Introductory Programming Fall 2006 For today you should have: 1) printed the handouts from last time 2) read Chapter 1 For next time you should: 1) finish Homework 1 (nothing to turn in, but you can post answers to Question 1.2 on the wiki http://allendowney.com/wiki/index.php?title=IntroProgramming Or just start from http://allendowney.com/wiki And follow links. We will have the first evaluation on Friday, starting right at the beginning of class, so please come on time. Vocabulary ---------- Words we have seen so far: expression, operand, operator statement, assignment function call (or invocation) variable, value, workspace From the reading: Four kinds of errors, syntax, run time, logical, approximation. Practice -------- Evaluate F10 and F100 using the formula in Homework 1. F10 should be 89 F100 should be 5.7315e+20 The Workspace ------------- A workspace is a set of variables and their values. The who command prints the name of the variables in the current workspace. An assignment statement: 1) adds a new variable to the name space, if necessary 2) evaluates the expression on the right-hand side 3) assigns the resulting value to the named variable A "workspace diagram" shows the variables in a workspace and their values. Draw a diagram showing the variables in your current workspace and their values. Scripts ------- What does the following sequence of statements do? s5 = sqrt(5) t1 = (1 + s5) / 2 t2 = (1 - s5) / 2 diff = t1^(n+1) - t2^(n+1) Fn = diff / s5 1) Under the file menu, select New -> M-file A new window should appear. 2) Type the first line above into the new window. 3) Save the file with the name fib1.m 4) Go back to the Matlab interpreter and type fib1 It should execute the statements in your script and print the result. 5) Add lines to the file one at a time and run the script again. 6) This script assumes that n is already defined! 7) You can suppress the output of a statement by putting a semi-colon at the end.