Consider the surface S given by squareroot x2 y2 22 z2 1
Solution
In Matlab, the basic objects are matrices, i.e. arrays of numbers. Vectors can be thought of as special matrices. A row vector is recorded as a 1 × n matrix and a column vector is recorded as a m × 1 matrix. To enter a row vector in Matlab, type the following at the prompt ( > ) in the command window: > v = [0 1 2 3] and press enter. Matlab will print out the row vector. To enter a column vector type > u = [9; 10; 11; 12; 13] You can access an entry in a vector with > u(2) and change the value of that entry with > u(2)=47 You can extract a slice out of a vector with > u(2:4) You can change a row vector into a column vector, and vice versa easily in Matlab using > w = v’ (This is called transposing the vector and we call ’ the transpose operator.) There are also useful shortcuts to make vectors such as > x = -1:.1:1 and > y = linspace(0,1,11) Basic Formatting To make Matlab put fewer blank lines in its output, enter > format compact To make Matlab display more digits, enter > format long Note that this does not change the number of digits Matlab is using in its calculations; it only changes what is printed. Plotting Data Consider the data in Table 1.1.1 We can enter this data into Matlab with the following commands entered in the command window: 1Adapted from Ayyup &McCuen 1996, p.174. 2 3 T (C ) 5 20 30 50 55 µ 0.08 0.015 0.009 0.006 0.0055 Table 1.1: Viscosity of a liquid as a function of temperature. > x = [ 5 20 30 50 55 ] > y = [ 0.08 0.015 0.009 0.006 0.0055] Entering the name of the variable retrieves its current values. For instance > x > y We can plot data in the form of vectors using the plot command: > plot(x,y) This will produce a graph with the data points connected by lines. If you would prefer that the data points be represented by symbols you can do so. For instance > plot(x,y,’*’) > plot(x,y,’o’) > plot(x,y,’.’) Data as a Representation of a Function
