Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Matlab “Matrix Laboratory”Matlab “Matrix Laboratory” Chapter 1 – matrices.

Similar presentations


Presentation on theme: "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Matlab “Matrix Laboratory”Matlab “Matrix Laboratory” Chapter 1 – matrices."— Presentation transcript:

1 March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Matlab “Matrix Laboratory”Matlab “Matrix Laboratory” Chapter 1 – matrices and algorithmsChapter 1 – matrices and algorithms Chapter 2 – syntaxChapter 2 – syntax Chapter 3 – types, plottingChapter 3 – types, plotting

2 March 2005 2R. Smith - University of St Thomas - Minnesota Matlab is ‘normal software’ It’s a lot more like Excel than CIt’s a lot more like Excel than C –You type in the computation and it ‘happens’ –No ‘compilation’ step –You can’t write operating systems with Matlab Chapter 1 of textChapter 1 of text –A lot about scales, measures, algorithms –Matrices often have 2 rows: a scale and a measurement –A 2D image matrix has elements representing pixels (dots) 3D image matrix has elements for level of primary colors3D image matrix has elements for level of primary colors –Algorithm: a set of directions for a computational task, described in terms of simpler operations

3 March 2005 3R. Smith - University of St Thomas - Minnesota Syntax things Variable names – much like CVariable names – much like C –Letters, digits, underscores Both ‘functional’ and ‘infix’ notationBoth ‘functional’ and ‘infix’ notation –Infix notation is the usual + - / *, more or less –Prefix noation is “function” notation Ex: plus(2,2) instead of 2+2Ex: plus(2,2) instead of 2+2 –Uparrow for exponentiation –Hypotenuse: sqrt(a^2 + b^2) Or: sqrt(plus(power(a,2),power(b,2)))Or: sqrt(plus(power(a,2),power(b,2))) Assignment statements, just like CAssignment statements, just like C –Fibonacci numbers: prev = 0; final = 1; new = prev + final;prev = 0; final = 1; new = prev + final; Prev = final; final = new; new = prev+final;Prev = final; final = new; new = prev+final;

4 March 2005 4R. Smith - University of St Thomas - Minnesota Chapter 3: Types Most basic things are floating point numbersMost basic things are floating point numbers –3 / 2 -> 1.5000, not 1 Text = strings, marked by single quotes (‘)Text = strings, marked by single quotes (‘) –Df = ‘dog food’; Integers show up in some special casesIntegers show up in some special cases –Images often have integers to give levels (but not always)

5 March 2005 5R. Smith - University of St Thomas - Minnesota Vectors, Collections Vector = sequence of numbersVector = sequence of numbers –Collection brackets: “[“ and “]” ExampleExample –time = [0 1 2 3.5 7]; –temp = [93.5 90.6 87.7 83.9 76.6]; –Including vs omitting the semicolon Calculations on the vectorsCalculations on the vectors –Time in seconds: time.* 60 –Fahrenheit conversion: 32 + temp.* 9./ 5 –Other examples: x + 1; x.^2; sqrt(x); log(x) –Combining 2 vectors: time + temp; time./ temp … Vector operations:Vector operations: –length, size, sum, prod, cumsum, cumprod

6 March 2005 6R. Smith - University of St Thomas - Minnesota Plotting plot(time, temp)plot(time, temp) plot(time, temp, ‘-o’)plot(time, temp, ‘-o’) –Shows data points

7 March 2005 7R. Smith - University of St Thomas - Minnesota Plotting built in functions Colon operatorColon operator –Creates a vector with preset values –Like ‘fill’ operations in Excel colon(start, incr, end)colon(start, incr, end) –Start = starting value –Incr = increment –End = ending value ExampleExample –Hunds = colon(0, 0.01, 4) –Tenths = colon(0, 0.1, 20) Try plotting: sin, cos, etc.Try plotting: sin, cos, etc.

8 March 2005 8R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by- sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Matlab “Matrix Laboratory”Matlab “Matrix Laboratory” Chapter 1 – matrices."

Similar presentations


Ads by Google