Lecture2 - CS1050-004 CS1050-004 Day 2, (Don’t giveup ye...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: CS1050-004 CS1050-004 Day 2, (Don’t giveup ye I aretrying to ge t, t (Don’t be r) tte be Review Tuesday’s Stuff Review Tuesday’s Stuff (And some stuff I forgot) • Command Window – – – – – – – • Command History Window Place to input commands Displays output from Calculations Navigate with arrows keys Shows all commands given to MATLAB Does not clear with clc, or clear commands. Double clicking Drag and Drop (Version 7) Review Continued Review Continued • Work Space Window – Keeps track of defined variables – Double click to open the array editor – Can check size, bytes, name, value and class – Alternate method in the Command Window: whos Review it some more, dude Review it some more, dude • Current Directory – The place where MATLAB accesses files or saves information onto your computer – This is the best place to put files you will be loading into MATLAB – Opens automatically when you request a graph – More on these later. • Graphic Window Are We there yet? Are We there yet? • Edit Window • Start Button – Didn’t Cover this, should have though – Will cover this first this today! – Not in Version 6 This is taking forever!! This is taking forever!! • Variables – – – Must start with a letter Case sensitive After 1st letter, can use letters, digits, and underscore (_) – First 63 characters must be unique – Cannot be MATLAB keyword – Built­in functions • Isvarname • Namelengthmax • Iskeyword • which The last one, I promise The last one, I promise • Matrices – Scalar Operations • a = 1+2 – White Space – – – – – – “=“ mean what? • Array Operations List values with or without commas New row with a semicolon B=1:5 same as B=[1:5] linespace(1,10,3) .* and ./ and .^ Yeah!!!! New Stuff Yeah!!!! New Stuff Solutions to Solutions Problems 1,2 and 3 and Problem 2.1 Problem 2.1 a. b. c. d. e. f. 3vars no, can’t begin with a number global no, global is a key word help help is a built­in function, you could, but I wouldn’t My_var yes sin sin is a built­in function, again, you could, but why. How would MATLAB tell you this was a variable, rather than a function? X+Y no, why???? Answers to 2.1 Answers to 2.1 g. h. i. j k _input no, must start with a letter input input is a built­in function, I don’t write em, I just pass em on tax­rate no, why? example1.1 no, and please don’t put periods in file names either example1_1 yes, yes, yes we found another one!! Problem 2.2 Problem 2.2 • • • • • • • 1 + ¾ = 1.75 5*6*4/2 = 60 5/2*6*4 = 60 5^2*3 = 75 5^(2*3) = 15625 1 + 3 + 5 / 5 + 3 +1 = 9 (1 + 3 + 5)/(5 +3 +1) = 1 Problem 2.2 Continued Problem 2.2 Continued • • • 5^2 (5+3)/(5*6) sqrt(4 + 6^3) or (4 + 6^3)^(1/2) or (4 + 6^3)^(.5) 9*(6/12)+7*5^(3+2) or (9*(6/12))+(7*5^(3+2)) • Problem 2.3 Problem 2.3 a. r = 5; area_circle = pi*r^2 r = 10; surface_area_sphere = 4/3*pi*r^2 r = 2; vol_sphere = 4*pi*r^3 b. c. New Stuff New Stuff • Extracting values from a Matrix – A value from inside a matrix is specified with the matrix name, and then the value location in side parentheses • A(1,2) – Create a smaller vector by extracting it from a larger vector • A = [1 2 3 4; 5 6 7 8; 3 4 5 6]; • B=A(1,:) – how to make a vector of just one column from A? Are we having fun yet? Are we having fun yet? • Transpose – The transpose operator basically changes rows to columns or vice versa • D’ – Can be used to create tables • table = [D’,R’] Scientific Notation Scientific Notation • Large and small numbers expressed in scientific notation, with a value as a number between 1 and 10 (the mantissa), multiplied by a power of 10 (the exponent). An e is placed between the mantissa and exponent, without any white spaces MATLAB will interpret this as two different numbers – 6.2e24 not 6.2 e24 Display Format Display Format • Integers printed as integers • Decimal fraction default to 4 decimal digits • To get 14 decimal digits, use: • • • • A=5.10000000000000 To return to 4 decimal digits – format short – format long – A=5.1000 – A=5 • Changing the display format does not change the accuracy of your calculations Large and small numbers automatically displayed in SN More in the Textbook. See Table 2.3 for commands and examples Saving Our Work Saving Our Work • save myspace • load myspace – This will save the variables in the workspace window in the current directory as a .mat file – myspace is user defined – This will restore a workspace – I will demonstrate these commands • save myspace variable_list Script M­files Script M­files • MATLAB M­file Editor/ Debugger – Text editor built into MATLAB – You can use a different text editor, just make sure you save the files as ASCII format. Such editors are: • Notepad • WordPerfect • Word M­files, part II M­files, part II • Same naming rules as variables, what are they? • Two type of M­files – Script • list of MATLAB commands saved in a file, .m extension • Executed by Save and Run Icon, Debug pull down menu – – – Type the file name run myscript run(‘myscript’) then Run, or by hitting F5. Can from the command window by: M­files are our friend M­files are our friend • Comments, lots and lots of comments – % This is how to comment Th­th­th­that’s all folks Th­th­th­that’s all folks ...
View Full Document

Ask a homework question - tutors are online