Introductory Programming Fall 2005 Today: 1) workspace, variable, value 2) scripts 3) updating variables 4) rental cars Please read Chapter 2 for next time. Next Tuesday we will have our first evaluation, starting right at the beginning of class, so please come on time. 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. Scripts ------- Here is a solution to the problem we worked on last time: 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 gradually, practicing incremental development and debugging. 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. Car rentals ----------- Problem description from our friends in ICB1. How do we expect this system to behave over time? How can we simulate it using MATLAB?