Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATLAB FUNDAMENTALS: MATRIX/ARRAY FUNCTIONS THE COLON MATRIX/ARRAY MANIPULATION INPUT/OUTPUT HP 100 – MATLAB Wednesday, 9/3/2014 www.clarkson.edu/class/honorsmatlab.

Similar presentations


Presentation on theme: "MATLAB FUNDAMENTALS: MATRIX/ARRAY FUNCTIONS THE COLON MATRIX/ARRAY MANIPULATION INPUT/OUTPUT HP 100 – MATLAB Wednesday, 9/3/2014 www.clarkson.edu/class/honorsmatlab."— Presentation transcript:

1 MATLAB FUNDAMENTALS: MATRIX/ARRAY FUNCTIONS THE COLON MATRIX/ARRAY MANIPULATION INPUT/OUTPUT HP 100 – MATLAB Wednesday, 9/3/2014 www.clarkson.edu/class/honorsmatlab

2 Before We Begin:  Any Questions? Comments? Concerns?  Feel free to contact Joe or Jim We can set up small group tutoring or one-on-one You can email us with any questions or concerns We are here for you! Even if it isn't about MATLAB

3 Quote/Video of the Week  “English is ambiguous. If someone said, ‘The horse flies like the devil,’ they could either be advising me on a horse race, or merely commenting on the rising tide of Satanism among some insects.” - Professor Felland Foundations of Mathematics https://www.youtube.com/watch?v=I15bDqhkxwE

4 Matrix/Array Functions  A = [1 1 1; 1 1 1]  B = [0 0; 0 0; 0 0]  C = [1 1; 1 1] A = 1 1 1 1 1 1 B = 0 0 0 0 C = 1 1 1 1

5 Matrix/Array Functions  A = ones(2,3)  B = zeros(3,2)  C = ones(2) A = 1 1 1 1 1 1 B = 0 0 0 0 C = 1 1 1 1

6 Matrix/Array Functions  Built in Commands/Functions: See Tables 3.5,6,7  max: Maximum Value  min: Minimum Value  mean: Mean Value  median: Median Value  sum: Sum of Vector  prod: Product of Vector

7 Matrix/Array Functions  Sorting FunctionsTable 3.8  sort  sortrows  Size FunctionsTable 3.9  size Dimensions of Array  length Largest Dimension

8 Special Values / Misc.  The following have special meanings:  pi - The constant 3.141592 …  i,j - Imaginary Number  Inf - Infinty, or overflow  NaN - Not a number, Undefined (0/0)  clock - [year month day hour minute seconds]  date

9 The Colon Operator  Used for:  Creating Vectors  Referencing arrays  Future applications [loops]

10 Creating Vectors  A = [2 4 6 8 10 12]  B = [2:2:12]  C = [4:6:30] A = 2 4 6 8 10 12 2 4 6 8 10 12 B = 2 4 6 8 10 12 2 4 6 8 10 12 C = 4 10 16 22 28 4 10 16 22 28

11 The Colon Operator  Let:  A(2,3) =  A(1, :) =  A(:, 3) =  A(:, 1:2:4) = A = 2 9 -3 10 2 9 -3 10 -4 13 1 6 -4 13 1 6

12 The Colon Operator  Built-in function – end  A(:,end)= [13; 6; 8]  A(end,end) = 8  diag(A) = [4; 2; 8] A = 4 7 13 4 7 13 5 2 6 5 2 6 1 9 8 1 9 8

13 Matrix/Array Manipulation  You can define new arrays or matrices in terms of other arrays or matrices.  This can be tricky, but always try to say it out loud and visualize what is happening.

14 I/O – Input / Output  Definition:  Hardcoding:Setting variables equal to particular numbers in the code. Example: Calculate the square root of a number. number = 100; sqrt_of_number = sqrt(number); The code snippet always calculates the square root of 100, unless you manually change the code. What if we want to do it for the number the user chooses (whomever is using your program/code)?

15 I/O – Input / Output  Methods:  Ask the user for input through the command window.  Load data from files.  Function inputs (We will get to this in a few weeks.)  Input Command:  number = input('Please Specify a Number: ');

16 I/O – Input / Output  Loading data from files:  Many different ways, depending on what type of file it is. We do this in the future. Use the load command.

17 I/O – Input / Output  Calculations, Manipulation, Calculations…  We Still need to display our Results  Methods:  Display in the command window Good for quick solutions, small amount of data. Commands: dispfprintf  Write the results to a file. Great for processing and saving lots of information. A bit harder to do, can be highly customized. Commands: fprintfsave

18 I/O – Input / Output  Command: disp  Example: x = 5; disp(x); disp(['The value of x is ' num2str(x) ‘. Cool Ehh?’]); Tells MATLAB to combine everything inside together into an array, in this case, a character array Things inside of single quotation marks are strings, or just simply text (stored as plain text) Converts a number to a string.

19 I/O – Input / Output  Command: fprintf  This can be used to either print out to the command window or write to a file.  This is saved for your own reading/learning.  It’s another way to display, also. It allows for more formatting and pretty outputs

20 Example Code Time  The Golf Ball Example  Please take note of lots of little things that are done, they add to the readability and to the end results being pretty  Problem Description: Calculate the X-Position and Y-Position of a golf ball hit with an initial speed and angle. Assume constant acceleration from gravity and no drag. Also find the maximum height and display the results.

21 Homework  Please review/read:  Chapter 3, Chapter 4  It is very important to review the tables indicated and go through the example problems.  Please do:  3.4, 4.1, 4.6

22 Before you go…  Do Problem 4.1 in the book


Download ppt "MATLAB FUNDAMENTALS: MATRIX/ARRAY FUNCTIONS THE COLON MATRIX/ARRAY MANIPULATION INPUT/OUTPUT HP 100 – MATLAB Wednesday, 9/3/2014 www.clarkson.edu/class/honorsmatlab."

Similar presentations


Ads by Google