{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# partI - Part I Matlab and Solving Equations c Copyright...

This preview shows pages 1–4. Sign up to view the full content.

Part I Matlab and Solving Equations c circlecopyrt Copyright, Todd Young and Martin Mohlenkamp, Mathematics Department, Ohio University, 2007

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

View Full Document
Lecture 1 Vectors, Functions, and Plots in Matlab In this book > will indicate commands to be entered in the command window. You do not actually type the command prompt > . Entering vectors 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) Plotting Data Consider the following table, obtained from experiments on the viscosity of a liquid. 1 We can enter T (C ) 5 20 30 50 55 μ 0.08 0.015 0.009 0.006 0.0055 this data into Matlab with the following commands entered in the command window: > x = [ 5 20 30 50 55 ] 1 Adapted from Ayyup & McCuen 1996, p.174. 2
3 > 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 A major theme in this course is that often we are interested in a certain function y = f ( x ), but the only information we have about this function is a discrete set of data { ( x i , y i ) } . Plotting the data, as we did above, can be thought of envisioning the function using just the data. We will find later that we can also do other things with the function, like differentiating and integrating, just using the available data. Numerical methods, the topic of this course, means doing mathematics by computer. Since a computer can only store a finite amount of information, we will almost always be working with a finite, discrete set of values of the function (data), rather than a formula for the function. Built-in Functions If we wish to deal with formulas for functions, Matlab contains a number of built-in functions, including all the usual functions, such as sin( ) , exp( ) , etc.. The meaning of most of these is clear. The dependent variable (input) always goes in parentheses in Matlab . For instance: > sin(pi) should return the value of sin π , which is of course 0 and > exp(0) will return e 0 which is 1. More importantly, the built-in functions can operate not only on single numbers but on vectors. For example: > x = linspace(0,2*pi,40) > y = sin(x) > plot(x,y)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 26

partI - Part I Matlab and Solving Equations c Copyright...

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

View Full Document
Ask a homework question - tutors are online