PSY8219 : Week 2. Homework 1 Due Today. Homework 2 Due September 12. Readings for Today Attaway Chapters 2, 7, and 8
|
|
- Shanon Montgomery
- 5 years ago
- Views:
Transcription
1 PSY8219 : Week 2 Homework 1 Due Today (homework solutions will be posted on the web site after class the day the assignment is due or two+ days after if anyone is late turning it in) Homework 2 Due September 12 Readings for Today Attaway Chapters 2, 7, and 8 Readings for Next Week Attaway Chapters 3, 4, and 5
2
3 Scripts in Matlab
4 Best Practices Use folders/directories, subfolders/subdirectories Make a copy of a working program before you make new edits to it. Keep copies of experiment programs and analysis programs with any data you collect in an experiment.
5 Running a Script Green Arrow Save and Run Debugging setting breakpoints in code
6 Defining and Executing Sections %% a comment and a start of a section sections should be self-contained units of code single-click / left click to select a section two-finger click / right click to select Evaluate Current Section or Evaluate Current Selection* * on a MacBook trackpad, there is a known two-finger click bug - try using control-click instead
7 Homework Assignments Turn in.m file(s) on Brightspace; if there are multiple files, please turn in as a single ZIP file Use comments to indicate which part of a question you are answering If I ask a question that requires a short answer, you can usually answer it in a comment within the script For a longer answer you might need to submit a pdf file or a word file
8 Homework Assignments include all files needed to run your code when you submit your solutions, even files that I have supplied if you have more than 1 or 2 files, please submit them as a ZIP file clearly inform me which file I should run to test your program
9 Homework Assignments Unless required by the assignment to do otherwise, make sure your lines end with a ; to suppress output - in the class.m files I sometimes leave the ; off so that output is generated in the Command Window please use %% to separate logical sections of your code both as a matter of style, and so I can run subsections of your code when grading note other Best Practices that I will be looking for
10
11 QUIZ Quiz.xlm MathWorks version of Jupyter notebooks
12
13 Characters and Strings
14 Character Types >> x = 'A' >> whos x >> x = 'ABC' >> whos x
15 String Types >> x = "A" >> whos x >> x = "ABC" >> whos x There are lots of things you can do with characters
16 Character Arrays vs. Strings >> "abc" + "1234" >> 'abc' + '1234' >> 'abc' + '123'
17 ASCII Code
18 Character Arrays vs. Strings >> "abc" + "1234" >> 'abc' + '1234' >> 'abc' + '123' >> 'abc' - '123' >> "abc" - "123"
19 >> strcmp(a,c) Character / String Operations strcmp is case sensitivity >> strcmpi(a,c) strcmpi is not
20 >> a = 'abc' >> b = 'abc ' >> strcmp(a,b) Character / String Operations string comparison is not intelligent - we re used to search engines like google that take care of misspellings and extra spaces gracefully
21
22 Data Structures
23 Data Structures one key to successful programming is using the right kind of data structure and using it the right way for the right task
24 Data Structures in Matlab Arrays, Vector, Matrices Structures Cell Arrays Tables Categorical Arrays Matlab does not so easily support more sophisticated data structures (queues, trees, hash tables, etc.), which is why some people use Python or C++
25
26 Arrays
27 Why use a data structure? Imagine we have 10 subjects and each subject answers 10 true/false questions. 100 data points. We could create 100 variables, s1q1, s2q2, s2q1, s2q2, s10q9, s10q10. Why do we use a data structure instead?
28 Why use a data structure? Imagine we have 10 subjects and each subject answers 10 true/false questions. 100 data points. We could create 100 variables, s1q1, s2q2, s2q1, s2q2, s10q9, s10q10. Why do we use a data structure instead? - access data more easily and more efficiently - access data dynamically - all the data is in the same place
29 Arrays Arrays are the most common data structure used in just about every language. creating a one-dimensional array in Matlab >> a = [ ] referencing an element >> a(2) changing the value of an element >> a(2) = 10
30 Arrays remove an element from a one-dimensional array >> a(2) = [ ] adding an element to an array >> a(5) = 5 but note this >> a(10) = 10 regular arrays, by definition are contiguous there are advanced data structures called sparse matrices too:
31 Arrays >> a = [1 2 3] >> a(10) = 1 One nice thing about Matlab is that it lets you dynamically add new elements to an array. Other languages force you to say how big an array is at the outset (e.g., C++) and you have to resize it explicitly to add more elements. If you go past the boundaries of the array, the program crashes. but this can also make it harder to debug a program
32 Two-dimensional Arrays >> a = [1 2 3 ; 4 5 6] >> size(a) 2 rows 3 columns Now the meaning of ; changes. Within [ ] it creates a new row in an array.
33 Two-dimensional Arrays >> b = [1 2 ; 3 4 ; 5 6] How many columns and rows will this have?
34 Two-dimensional Arrays >> b = [1 2 ; 3 4 ; 5 6] How many columns and rows will this have? >> size(b) Note: It is entirely up to you to keep straight what the rows and columns MEAN. Rows could be subjects. Columns could be subjects. It s up to you.* * other data structures impose more "structure"
35 Two-dimensional Arrays >> a = [1 2 3 ; 4 5 6] What will happen here? >> a(4,1) Why?
36 Here? >> a(4.1, 1.2) Why? Two-dimensional Arrays
37 Here? >> a(4.1, 1.2) Why? Two-dimensional Arrays What if you referenced an array like this >> a(i,j) You need to make sure i and j are whole numbers.
38
39 >> x = 3; >> F(x) = x^2; A beautiful misconception
40 >> x = 3; >> F(x) = x^2; A beautiful misconception >> F(3) >> F(4) >> x = 3.1; >> F(x) = x^2;
41
42 >> x = 1 >> size(x) We re already been using arrays 1 row 1 column there are no true "scalars" in Matlab (unlike other languages)
43 What does [ ] actually do? It s a concatenation operator. concatenate = link together in a chain [ ] = >> x = 1 >> y = [x x x]
44 What does [ ] actually do? What do you think this will do? >> x = 1 >> y = [x x x] >> z = [y y]
45 What does [ ] actually do? What do you think this will do? >> x = 1 >> y = [x x x] >> z = [y y] [ ] =
46 How about this? >> x = [2 ; 3] >> y = [4 ; 5] >> z = [6 ; 7] >> [x y z] What does [ ] actually do?
47 How about this? >> x = [2 ; 3] >> y = [4 ; 5] >> z = [6 ; 7] >> [x y z] What does [ ] actually do? [ ] =
48 This? >> x = [1 2 3] >> y = [4 5] >> z = [6 7 8] >> [x y z] What does [ ] actually do?
49 This? >> x = [1 2 3] >> y = [4 5] >> z = [6 7 8] >> [x y z] What does [ ] actually do? [ ] =
50 What does [ ] actually do? >> w = [1 1 ; 1 1] >> x = [2 2 ; 2 2] >> y = [3 3 ; 3 3] >> z = [4 4 ; 4 4] This? >> [w x y z]
51 What does [ ] actually do? >> w = [1 1 ; 1 1] >> x = [2 2 ; 2 2] >> y = [3 3 ; 3 3] >> z = [4 4 ; 4 4] This? >> [w ; x ; y ; z]
52 What does [ ] actually do? >> w = [1 1 ; 1 1] >> x = [2 2 ; 2 2] >> y = [3 3 ; 3 3] >> z = [4 4 ; 4 4] This? >> [w x ; y z]
53 What does [ ] actually do? >> w = [1 1 ; 1 1] >> x = [2 2 ; 2 2] >> y = [3 3 ; 3 3] >> z = [4 4 ; 4 4] This? >> [w x y ; z]
54 This? >> x = [2 ; 3] >> y = [4 5] >> [x y] What does [ ] actually do?
55 What does [ ] actually do? This? >> x = [2 3 ; 4 5] >> y = [6 ; 7] >> [x y]
56 >> a = 'apple' >> size(a) character arrays >> b = 'banana' >> size(b) What do you think this does? >> [a b]
57 >> a = 'apple' >> size(a) character arrays >> b = 'banana' >> size(b) These? >> [a ' ' b] >> a(4)
58 vs. strings >> a = "apple" >> size(a) >> b = "banana" >> size(b) These? >> [a b] >> a(4)
59
60 and versus and two differences (1) >> A B C calculates A, B, C to figure out logical expression >> A B C If A is false, it does not evaluate B and C short-circuit behavior
61 and versus and two differences (1) >> A B C calculates A, B, C to figure out logical expression >> A B C If A is true, it does not evaluate B and C short-circuit behavior
62 and versus and two differences (2) >> [1 0 1] [0 1 1] what does this result in? >> [1 0 1] [0 1 1] what does this result in?
63 and versus and two differences (2) >> [1 0 1] [0 1 1] what does this result in? >> [1 0 1] [0 1 1] what does this result in?
64
65 How are arrays stored in memory? Create a variable >> x = 2 O/S Matlab Data Memory
66 How are arrays stored in memory? Create a variable >> x = 2 O/S Matlab Data Memory
67 How are arrays stored in memory? Create a variable >> x = 2 free filled
68 How are arrays stored in memory? Create a variable >> x = 2 x length 1
69 How are arrays stored in memory? Create a variable >> x = [2 3 4] x length 1
70 How are arrays stored in memory? Create a variable >> x = [2 3 4] x length 3
71 How are arrays stored in memory? Create a variable >> x(4) = 5 x length 3
72 How are arrays stored in memory? Create a variable >> x(4) = 5 x length 4
73 Preallocating arrays Creating and moving large arrays every time a new index is added can take a lot of time. Preallocate >> x = zeros(1,100) or >> x = ones(1,100) or >> x = zeros(5,20)
74 How are two-dimension arrays stored? >> x = [1 2 3; 4 5 6]
75 How are two-dimension arrays stored? >> x = [1 2 3; 4 5 6] x total length 6
76 How are two-dimension arrays stored? >> x = [1 2 3; 4 5 6] how is a 2D array stored? x total length 6 Column Major Order
77 How are two-dimension arrays stored? >> x = [1 2 3; 4 5 6] What will these spit out? >> x(1,1) >> x(1,2) >> x(1,3) These? >> x(1) >> x(2) >> x(3)
78 How are two-dimension arrays stored? >> x = [1 2 3; 4 5 6] What will these spit out? >> x(1,1) >> x(1,2) >> x(1,3) These? >> x(1) >> x(2) >> x(3) can be a dangerous way to reference a multidimensional array if you are not very careful can be a difficult "bug" to detect as well
79 size vs. length of an array >> clear all >> x = [ ] >> size(x) >> length(x) >> x = [1 2 ; 3 4 ; 5 6] >> size(x) >> length(x)
80 Extracting part of an array >> a = [ ; ; ; ; ]; How do we extract row 2? >> [a(2,1) a(2,2) a(2,3) a(2,4) a(2,5)]
81 Extracting part of an array >> a = [ ; ; ; ; ]; How do we extract row 2? >> [a(2,1) a(2,2) a(2,3) a(2,4) a(2,5)] Here s an easier way: >> a(2,[ ])
82 Using the colon : operator >> 1:5 creates a sequence within an array
83 Using the colon : operator >> 1:5 creates a sequence within an array Try these. >> a >> a(2, 1:5) >> a(1:5, 2)
84 Using the colon : operator >> 1:5 creates a sequence within an array Try these. >> a >> a(2, 1:5) >> a(1:5, 2) What will this give you? >> a(1:2, 1:2)
85 Using the colon : operator : by itself within an array >> a(2, :) >> a(:, 2) >> a(:, :)
86 Using the colon : operator Create a 10x10 array containing the integers between 0 and 99.
87 Using the colon : operator Create a 10x10 array containing the integers between 0 and 99. >> a = [0:9 ; 10:19; 20:29; 30:39; 40:49; 50:59; 60:69; 70:79; 80:89; 90:99];
88 Using the colon : operator Create a 10x10 array containing the integers between 0 and 99. >> a = [0:9 ; 10:19; 20:29; 30:39; 40:49; 50:59; 60:69; 70:79; 80:89; 90:99]; >> a = 0:99
89 Using the colon : operator Create a 10x10 array containing the integers between 0 and 99. >> a = [0:9 ; 10:19; 20:29; 30:39; 40:49; 50:59; 60:69; 70:79; 80:89; 90:99]; >> a = 0:99 >> a = reshape([0:99],10,10);
90 transpose (') swapping rows and columns >> x = [ ] >> x >> x' >> y = [1 2 ; 3 4 ; 5 6] >> y' (Note: Technically, if you just want to transpose rows and columns and keep the numbers exactly the same, you should use.' instead of ', but it only makes a difference if you have complex numbers.)
91 Multidimensional Arrays By default, all arrays in Matlab are 2-dimensional. You can create arrays with more than 2 dimensions.
92 Multidimensional Arrays e.g., imagine a within-subjects design rows are subjects columns are levels along IV 1 depth are levels along IV 2 each entry (x,y,z) within the array is the score for subject x, along level y of IV 1 and level z of IV 2
93 Creating a multidimensional array No way to create one directly using the [ ] operator. Remember, [ ] simply concatenates. While it looks like [ ] creates a two-dimensional array from onedimensional elements (e.g., [2 3 ; 4 5]), recall that even a number like 2 is technically a twodimensional array (1 row, 1 column) already. So, while [ ] can concatenate three-dimensional arrays, it cannot create them from scratch.
94 Creating a multidimensional array Preallocating >> x = zeros(20,10,5) You need to remember what the dimensions mean. And this would be impossible to understand if you saw it in someone s Matlab script.
95 Creating a multidimensional array This is better style >> Nsubj = 8; >> NIV1 = 5; >> NIV2 = 3; >> data = zeros(nsubj, NIV1, NIV2);
96 The only number (2, 125, 25.1) you should EVER see in a computer program is one that is an intrinsic part of a calculation or a formula. e.g., Best Practices f = (1/(sig*sqrt(2*pi))) * exp(-((x-mu).^2)/(2*sig.^2)) for i=1:size(data,1) end
97 Best Practices You NEVER EVER want to see 64 in a loop if you have 64 trials, or 3 in a loop if you have 3 blocks, or 2.1 in a formula if that s some scaling factor you picked to adjust image contrast. Make those variables with meaningful names and comment them. Even if this is a "one-off" analysis program, you might need to go back to it in 6 months or more after a couple rounds of reviews through a journal.
98 Best Practices In all homework assignments, I will expect that you use good programming style.
99 Referencing a multidimensional array Back to our data example
100 Referencing a multidimensional array How would you pull out the data for subject 3?
101 Referencing a multidimensional array How would you pull out the data for subject 3? >> x = data(3,:,:) >> size(x)
102 Referencing a multidimensional array How would you pull out the data for subject 3? >> x = data(3,:,:) >> size(x) You might want to reduce this to two dimensions. >> x = squeeze(data(3,:,:))
103 Referencing a multidimensional array Matlab is mind-numbingly arbitrary sometimes. Try this now >> x = data(:,:,1) >> size(x)
104 Removing data? Can you remove subject three?
105 Removing data? Can you remove subject three? >> data(3,:,:) = [ ]
106 Removing data? Can you remove subject three? >> data(3,:,:) = [ ] Can you remove level 2 of IV 1?
107 Removing data? Can you remove subject three? >> data(3,:,:) = [ ] Can you remove level 2 of IV 1? >> data(:,2,:) = [ ]
108 Removing data? Can you remove subject three? >> data(3,:,:) = [ ] Can you remove level 2 of IV 1? >> data(:,2,:) = [ ] Now what if you wanted to remove subject four?
109 Removing data? Can you remove subject three? >> data(3,:,:) = [ ] Can you remove level 2 of IV 1? >> data(:,2,:) = [ ] Now what if you wanted to remove subject four? Is this right? >> data(4,:,:) = []
110 Removing data? Can you remove subject three? >> data(3,:,:) = [ ] Can you remove level 2 of IV 1? >> data(:,2,:) = [ ] Now what if you wanted to remove subject four? Is this right? >> data(4,:,:) = [] Which row has subject 4 s data now?
111 Removing data? Can you remove subject three? >> data(3,:,:) = [ ] Can you remove level 2 of IV 1? >> data(:,2,:) = [ ] Now what if you wanted to remove subject four? Is this right? >> data(4,:,:) = [] Which row has subject 4 s data now? >> data(3,:,:) = []
112 Removing data? Suppose you think that the data for subject 1 is suspect, but only for level 1 on IV1 and level 3 on IV2. Can you remove that one data point?
113 Removing data? Suppose you think that the data for subject 1 is suspect, but only for level 1 on IV1 and level 3 on IV2. Can you remove that one data point? >> data(1,1,3) = [ ] Will this work?
114 Removing data? Suppose you think that the data for subject 1 is suspect, but only for level 1 on IV1 and level 3 on IV2. Can you remove that one data point? >> data(1,1,3) = [ ] Will this work? No. But people sometimes do this. >> data(1,1,3) = NaN
115
116 Best Practices A common (and nasty) problem people run into is that they don t realize they are reusing a variable, especially an array that s already been set up. What s especially troubling is that they try to restart Matlab and the problem goes away, so they think it was just a Matlab hiccup. Why does it go away when you restart Matlab?
117 Best Practices A common (and nasty) problem people run into is that they don t realize they are reusing a variable, especially an array that s already been set up. What s especially troubling is that they try to restart Matlab and the problem goes away, so they think it was just a Matlab hiccup. Why does it go away when you restart Matlab? The Workspace is clear.
118 Another example How would we create a multidimensional array to hold the data for a mixed design where there could be unequal numbers of subjects in the betweensubjects levels? One B/S variable with 3 levels 10 subjects in level 1 12 subjects in level 2 8 subjects in level 3 One W/S variable with 2 levels One W/S variable with 5 levels
119 >> NBet = 3 >> NWith1 = 2 >> NWith2 = 5 >> NMaxSubj = 12 Another example >> Nsubj = zeros(1,nbet) >> Nsubj(1) = 10 >> Nsubj(2) = 12 >> Nsubj(3) = 8 >> data = different from how you might code data in Excel or SPSS zeros(nbet,nmaxsubj,nwith1,nwith2)
120
121 Simple I/O in Matlab For Homework Assignment (read these notes, the book, and online help) save, load, input, fprintf
122 Simple I/O in Matlab We ll talk about more complex I/O later Files or User Input
123 Simple I/O in Matlab Save data in Matlab (.mat) format: >> save filename.mat >> save('filename.mat') saves all variables in the current workspace in file named filename.mat >> save filename.mat X a b >> save('filename.mat', 'X', 'a', 'b') saves variables X, a, and b in filename.mat
124 Simple I/O in Matlab Load data in Matlab (.mat) format: >> load filename.mat >> load('filename.mat') loads everything within filename.mat into workspace You can also load specific variables >> load filename.mat X >> load('filename.mat', 'X') Only loads variable X
125 Simple I/O in Matlab User input >> age = input('enter age : '); >> name = input('enter name : ', 's');
126 Simple I/O in Matlab Screen output >> X We ve already used this. Often we want it formatted. fprintf() command (borrowed from C)
127 fprintf() >> ans = 42 >> fprintf(['answer to the Ultimate Question' 'of Life, the Universe, and Everything' 'is %d\n'], ans) First, what am I doing with the [ ] and why?
128 fprintf() >> ans = 42 >> fprintf(['answer to the Ultimate Question' 'of Life, the Universe, and Everything' 'is %d\n'], ans) %d inserts an integer at that location in the string %f inserts a floating point number %c inserts a single character %s inserts a string
129 fprintf() >> ans = 42 >> fprintf(['answer to the Ultimate Question' 'of Life, the Universe, and Everything' 'is %d\n'], ans) \n new line \t tab put a quote in the string \\ put a \ in the string
130 fprintf() What will this print? >> ans = 10 >> str = 'hello' >> fprintf('say \'%s\' and give me $%d\n', str, ans)
131 What will this print? >> fprintf('pi = \n', pi) fprintf()
132 fprintf() What will this print? >> fprintf('pi = %f\n', pi)
133 fprintf() What will this print? >> fprintf('pi = %9.9f\n', pi) >> fprintf('pi = %12.9f\n', pi) >> fprintf('pi = %15.9f\n', pi) >> fprintf('pi = %15.1f\n', pi)
134 fprintf() What will this print? >> fprintf('pi = %9.9f\n', pi) >> fprintf('pi = %12.9f\n', pi) >> fprintf('pi = %15.9f\n', pi) >> fprintf('pi = %15.1f\n', pi) >> ans = 1000*pi >> fprintf('pi = %4.4f\n', pi)
135 fprintf() What will this print? >> ans = >> fprintf('ans = %d\n', ans) >> fprintf('ans = %10d\n', ans)
136 fprintf() What will this print? >> ans = >> fprintf('ans = %d\n', ans) >> fprintf('ans = %10d\n', ans) Please use fprintf() statements where appropriate in your homework assignments
137
138 Mathematical Operations on Arrays Basic Linear Algebra
139 Mathematical Operations on Arrays >> clear all >> data = [1 2 ; 3 4] add a number to a particular element in an array >> data(1,2) = data(1,2) + 10
140 Mathematical Operations on Arrays >> clear all >> data = [1 2 ; 3 4] add or subtract a number to/from EVERY element >> data = data + 10 >> data = data 10
141 Mathematical Operations on Arrays >> clear all >> data = [1 2 ; 3 4] multiple or divide by the same number for every element in the array >> data = data * 10 >> data = data / 10
142 Mathematical Operations on Arrays >> clear all >> data = [1 2 ; 3 4] >> x = repmat(10, 2, 2) >> x = repmat(10, size(data)) what does repmat do?
143 Mathematical Operations on Arrays >> clear all >> data = [1 2 ; 3 4] >> x = repmat(10, 2, 2) >> x = repmat(10, size(data)) >> data + 10 >> data + x
144 Mathematical Operations on Arrays >> clear all >> data = [1 2 ; 3 4] When you add or subtract two arrays, the corresponding elements are added or subtracted. >> data2 = [8 7 ; 6 5] >> data + data2 >> data data2
145 Mathematical Operations on Arrays >> clear all >> data = [1 2 ; 3 4] What about these? >> x = repmat(10, 2, 2) >> data * 10 >> data * x >> data / 10 >> data / x
146 Arrays vs. Matrices Arrays are data structures with rows and columns used to organize and use data. Matrices are mathematical entities used in linear algebra. Unfortunately, in Matlab, arrays and matrices are defined in exactly the same way. While they are distinct computationally and mathematically, Matlab treats them as the very same type. Watch out.
147 Mathematical Operations on Arrays >> clear all >> data = [1 2 ; 3 4] What about these? >> x = repmat(10, 2, 2) >> data * 10 >> data.* x >> data / 10 >> data./ x Element-by-element
148 Array vs. Matrix multiplication and division Best Practices Get in the habit, within Matlab, of always using.* or./ when you multiply or divide, even if you do not need it (unless you really intend matrix operations)
149 Some more operations on arrays >> clear all >> data = [1 2 ; 3 4] What does this do? >> data.^ 2 Versus this? >> data ^ 2 Best Practices Also always use.^
150 Some more operations on arrays >> log10(data) >> exp(data) >> sin(data)
151 Some more operations on arrays >> mean(data) What s it doing? How could you find out? >> help mean >> doc mean
152 Some more operations on arrays >> mean(data) What s it doing? How could you find out? >> help mean >> doc mean >> mean(data,1) >> mean(data,2)
153 Evaluating Mathematical Formulas in Matlab One thing that Matlab does really well is calculate (and plot) lots of values for some function
154 Evaluating Mathematical Formulas in Matlab One thing that Matlab does really well is calculate (and plot) lots of values for some function f (x) = What is this? 1 2πσ $ (x µ) 2 exp 2 % 2σ 2 ' ) (
155 Evaluating Mathematical Formulas in Matlab One thing that Matlab does really well is calculate (and plot) lots of values for some function f (x) = What is this? 1 2πσ $ (x µ) 2 exp 2 % 2σ 2 ' ) ( probability density function for a normal distribution
156 Evaluating Mathematical Formulas in Matlab How would we code this in Matlab? f (x) = 1 2πσ $ (x µ) 2 exp 2 % 2σ 2 ' ) (
157 Evaluating Mathematical Formulas in Matlab How would we code this in Matlab? sig2 = 1 mu = 0 x = 1 f (x) = 1 2πσ $ (x µ) 2 exp 2 % 2σ 2 % variance % mean % a particular value f = (1/sqrt(2*pi*sig2)) * exp(-((x-mu)^2)/(2*sig2)) ' ) (
158 Evaluating Mathematical Formulas in Matlab How would we code this in Matlab? sig2 = 1 mu = 0 x = 1 f (x) = 1 2πσ $ (x µ) 2 exp 2 % 2σ 2 % variance % mean % a particular value f = (1/sqrt(2*pi*sig2)) * exp(-((x-mu)^2)/(2*sig2)) This calculates only one value at a time. ' ) (
159 Evaluating Mathematical Formulas in Matlab How would we code this in Matlab? sig2 = 1 mu = 0 x = -4:.01:4 % variance % mean % a particular value f = (1/sqrt(2*pi*sig2)) * exp(-((x-mu)^2)/(2*sig2)) plot(x,f) f (x) = 1 2πσ $ (x µ) 2 exp 2 % 2σ 2 What is this doing? ' ) (
160 Evaluating Mathematical Formulas in Matlab How would we code this in Matlab? sig2 = 1 mu = 0 x = -4:.01:4 % variance % mean % a particular value f = (1/sqrt(2*pi*sig2)) * exp(-((x-mu)^2)/(2*sig2)) plot(x,f) f (x) = 1 2πσ $ (x µ) 2 exp 2 % 2σ 2 What's wrong with this? ' ) (
161 Evaluating Mathematical Formulas in Matlab How would we code this in Matlab? sig2 = 1 mu = 0 x = -4:.01:4 % variance % mean % a particular value f = (1/sqrt(2*pi*sig2)).* exp(-((x-mu).^2)/(2*sig2)) plot(x,f) f (x) = 1 2πσ $ (x µ) 2 exp 2 % 2σ 2 ' ) (
162
163 Vectors, Matrices, and Linear Algebra
164 Vectors, Matrices, and Linear Algebra Arrays are merely containers that hold numeric data in an organized way. Vectors (1-dimensional) and Matrix (2-dimensional) are mathematical entities with mathematical operators that act on them. In Matlab, a 1-dimensional vector and 1-dimensional array, and a 2-dimensional matrix and a 2- dimensional array are defined exactly the same way, but they need to be thought of differently.
165 Vectors
166 Vectors Vectors have a magnitude and direction. Terminology can be a bit confusing in that a vector is one-dimensional in one sense >> a = [1 2] >> b = [3 2 1] >> c = [ ]
167 Vectors Vectors have a magnitude and direction. But we ll also illustrate plotting a vector in a multidimensional space >> a = [1 2] % vector 2D space >> b = [3 2 1] % vector 3D space >> c = [ ] % vector 4D space
168 Vectors >> a = [1 2] % vector 2D space >> b = [3 2] >> a + b y x
169 Vectors >> a + b y x
170 Vectors >> a + b y x
171 Vectors >> a = [1 2] >> b = 2*a y x
172 Vectors >> a = [1 2] >> b = 2*a y x
173 Vectors >> a = [1 2] >> b = 2*a y x
174 Vectors >> norm(b) % vector length (norm) Euclidian norm is found using the Pythagorean Theorem (also called 2-norm or an L 2 norm) y norm(b) x
175 Vectors angle between two vectors >> a = [1 3] >> b = [2 1] y θ x
176 Vectors angle between two vectors Implement in Matlab? cos(θ) = a b a b dot product norm y θ x
177 Vectors >> theta = radtodeg(acos( dot(a,b) / (norm(a)*norm(b)))) a b = n i=1 a i b i y cos(θ) = a b a b θ x
178
179 Matrices
180 Solving systems of linear algebra x + 2y = 2 x + y = 3 How would you view these equations in Matlab?
181 Solving systems of linear algebra How would you view these equations in Matlab? x1 = -5:5; x2 = -5:5; y1 = -0.5*x1 + 1 y2 = -x2 + 3 plot(x1,y1,x2,y2) x + 2y = 2 x + y = 3 What s the solution to the system of equations?
182 Solving systems of linear algebra x + 2y = 2 x + y = 3 Rewrite in matrix notation:! " $! % " x y $! = 2 % " 3 $ %
183 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ %
184 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
185 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
186 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
187 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
188 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
189 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
190 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
191 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
192 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
193 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
194 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
195 Multiplying Matrices! " a 11 a 12! a 1n a 21 a 22! a 2n " " " a m1 a m2! a mn $ %! " b 11 b 12! b 1p b 21 b 22! b 2p " " " b n1 b n2! b np $ % =! " c 11 c 12! c 1p c 21 c 22! c 2p " " " c m1 c m2! c mp mxn matrix nxp matrix mxp matrix $ % n k =1 c i j = a i k b kj
196 Solving systems of linear algebra x + 2y = 2 x + y = 3 Rewrite in matrix notation:! " $! % " x y $! = 2 % " 3 $ % 2x2 2x1
197 Solving systems of linear algebra x + 2y = 2 x + y = 3 Rewrite in matrix notation:! " $! % " x y $! = 2 % " 3 $ %! " x + 2 y x + y $! = 2 % " 3 $ %
198 Solving systems of linear algebra x + 2x = x + x = Rewrite :! " $! % " x 1 x 2 $! = 2 % " 3 $ % A x = b matrix vector vector
199 Mathematical Operations on Matrices A + B = B + A c(a+b) = ca + cb Convince yourself in Matlab >> A = [2 1 ; 2 3] >> B = [1 2 ; 0 1] >> c = 2 >> (A + B) (B + A) >> c.*(a+b) (c.*a + c.*b)
200 Mathematical Operations on Matrices How about this? Try it in Matlab. AB =? BA
ARRAY VARIABLES (ROW VECTORS)
11 ARRAY VARIABLES (ROW VECTORS) % Variables in addition to being singular valued can be set up as AN ARRAY of numbers. If we have an array variable as a row of numbers we call it a ROW VECTOR. You can
More informationELEMENTARY MATLAB PROGRAMMING
1 ELEMENTARY MATLAB PROGRAMMING (Version R2013a used here so some differences may be encountered) COPYRIGHT Irving K. Robbins 1992, 1998, 2014, 2015 All rights reserved INTRODUCTION % It is assumed the
More informationCME 192: Introduction to Matlab
CME 192: Introduction to Matlab Matlab Basics Brett Naul January 15, 2015 Recap Using the command window interactively Variables: Assignment, Identifier rules, Workspace, command who and whos Setting the
More informationAppendix A. Introduction to MATLAB. A.1 What Is MATLAB?
Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system
More informationMATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab
MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the
More informationVariable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.
MATLAB Introduction Accessing Matlab... Matlab Interface... The Basics... 2 Variable Definition and Statement Suppression... 2 Keyboard Shortcuts... More Common Functions... 4 Vectors and Matrices... 4
More informationLinear algebra deals with matrixes: two-dimensional arrays of values. Here s a matrix: [ x + 5y + 7z 9x + 3y + 11z
Basic Linear Algebra Linear algebra deals with matrixes: two-dimensional arrays of values. Here s a matrix: [ 1 5 ] 7 9 3 11 Often matrices are used to describe in a simpler way a series of linear equations.
More informationLab 1 Intro to MATLAB and FreeMat
Lab 1 Intro to MATLAB and FreeMat Objectives concepts 1. Variables, vectors, and arrays 2. Plotting data 3. Script files skills 1. Use MATLAB to solve homework problems 2. Plot lab data and mathematical
More informationVariables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:
Contents VARIABLES... 1 Storing Numerical Data... 2 Limits on Numerical Data... 6 Storing Character Strings... 8 Logical Variables... 9 MATLAB S BUILT-IN VARIABLES AND FUNCTIONS... 9 GETTING HELP IN MATLAB...
More informationAn Interesting Way to Combine Numbers
An Interesting Way to Combine Numbers Joshua Zucker and Tom Davis October 12, 2016 Abstract This exercise can be used for middle school students and older. The original problem seems almost impossibly
More informationMATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks
MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student
More informationMATLAB Project: Getting Started with MATLAB
Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB built-in functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos,
More informationC++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5
C++ Data Types Contents 1 Simple C++ Data Types 2 2 Quick Note About Representations 3 3 Numeric Types 4 3.1 Integers (whole numbers)............................................ 4 3.2 Decimal Numbers.................................................
More informationConstraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial
1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the
More informationDr Richard Greenaway
SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 3 Creating, Organising & Processing Data Dr Richard Greenaway 3 Creating, Organising & Processing Data In this Workshop the matrix type is introduced
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationIf Statements, For Loops, Functions
Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements
More informationFinding, Starting and Using Matlab
Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col
More information1 Introduction to Matlab
1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,
More informationLecture 2: Variables, Vectors and Matrices in MATLAB
Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables
More information(Refer Slide Time 6:48)
Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 8 Karnaugh Map Minimization using Maxterms We have been taking about
More informationDecisions, Decisions. Testing, testing C H A P T E R 7
C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little
More informationGLY Geostatistics Fall Lecture 2 Introduction to the Basics of MATLAB. Command Window & Environment
GLY 6932 - Geostatistics Fall 2011 Lecture 2 Introduction to the Basics of MATLAB MATLAB is a contraction of Matrix Laboratory, and as you'll soon see, matrices are fundamental to everything in the MATLAB
More informationIn math, the rate of change is called the slope and is often described by the ratio rise
Chapter 3 Equations of Lines Sec. Slope The idea of slope is used quite often in our lives, however outside of school, it goes by different names. People involved in home construction might talk about
More informationDynamics and Vibrations Mupad tutorial
Dynamics and Vibrations Mupad tutorial School of Engineering Brown University ENGN40 will be using Matlab Live Scripts instead of Mupad. You can find information about Live Scripts in the ENGN40 MATLAB
More informationMATLAB: The Basics. Dmitry Adamskiy 9 November 2011
MATLAB: The Basics Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 9 November 2011 1 Starting Up MATLAB Windows users: Start up MATLAB by double clicking on the MATLAB icon. Unix/Linux users: Start up by typing
More informationMATLAB Project: Getting Started with MATLAB
Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos, sin,
More informationSECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing
SECTION 1: INTRODUCTION ENGR 112 Introduction to Engineering Computing 2 Course Overview What is Programming? 3 Programming The implementation of algorithms in a particular computer programming language
More informationMathematical Operations with Arrays and Matrices
Mathematical Operations with Arrays and Matrices Array Operators (element-by-element) (important) + Addition A+B adds B and A - Subtraction A-B subtracts B from A.* Element-wise multiplication.^ Element-wise
More informationAn Introduction to MATLAB
An Introduction to MATLAB Day 1 Simon Mitchell Simon.Mitchell@ucla.edu High level language Programing language and development environment Built-in development tools Numerical manipulation Plotting of
More informationMATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)
Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal
More informationMcTutorial: A MATLAB Tutorial
McGill University School of Computer Science Sable Research Group McTutorial: A MATLAB Tutorial Lei Lopez Last updated: August 2014 w w w. s a b l e. m c g i l l. c a Contents 1 MATLAB BASICS 3 1.1 MATLAB
More informationObjectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016
Physical Sciences 12a Lab 0 Spring 2016 Objectives This lab is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started in this class. It is meant to
More informationCITS2401 Computer Analysis & Visualisation
FACULTY OF ENGINEERING, COMPUTING AND MATHEMATICS CITS2401 Computer Analysis & Visualisation SCHOOL OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING Topic 3 Introduction to Matlab Material from MATLAB for
More informationLecturer: Keyvan Dehmamy
MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications
More informationLecture 3: Linear Classification
Lecture 3: Linear Classification Roger Grosse 1 Introduction Last week, we saw an example of a learning task called regression. There, the goal was to predict a scalar-valued target from a set of features.
More informationChapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1
Chapter 2 (Part 2) MATLAB Basics dr.dcd.h CS 101 /SJC 5th Edition 1 Display Format In the command window, integers are always displayed as integers Characters are always displayed as strings Other values
More informationWriting MATLAB Programs
Outlines September 14, 2004 Outlines Part I: Review of Previous Lecture Part II: Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Control Structures If/Then/Else For Loops
More informationA Guide to Using Some Basic MATLAB Functions
A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available
More informationUNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING
UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2012 Lab 3 Matrix Math Introduction Reading In this lab you will write a
More informationMATLAB TUTORIAL WORKSHEET
MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent
More informationQUIZ: What is the output of this MATLAB code? >> A = [2,4,10,13;16,3,7,18; 8,4,9,25;3,12,15,17]; >> length(a) >> size(a) >> B = A(2:3, 1:3) >> B(5)
QUIZ: What is the output of this MATLAB code? >> A = [2,4,10,13;16,3,7,18; 8,4,9,25;3,12,15,17]; >> length(a) >> size(a) >> B = A(2:3, 1:3) >> B(5) QUIZ Ch.3 Introduction to MATLAB programming 3.1 Algorithms
More informationVector Calculus: Understanding the Cross Product
University of Babylon College of Engineering Mechanical Engineering Dept. Subject : Mathematics III Class : 2 nd year - first semester Date: / 10 / 2016 2016 \ 2017 Vector Calculus: Understanding the Cross
More informationGetting To Know Matlab
Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better
More informationIntroduction. Matlab for Psychologists. Overview. Coding v. button clicking. Hello, nice to meet you. Variables
Introduction Matlab for Psychologists Matlab is a language Simple rules for grammar Learn by using them There are many different ways to do each task Don t start from scratch - build on what other people
More informationObjectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014
PS 12a Laboratory 1 Spring 2014 Objectives This session is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started. Throughout the tutorial, the instructors
More informationIntroduction to MATLAB for Engineers, Third Edition
PowerPoint to accompany Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 2 Numeric, Cell, and Structure Arrays Copyright 2010. The McGraw-Hill Companies, Inc. This work is
More informationChapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.
Chapter 8 out of 7 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal 8 Matrices Definitions and Basic Operations Matrix algebra is also known
More informationLecture 2 Introduction to MATLAB. Dr.Tony Cahill
Lecture 2 Introduction to MATLAB Dr.Tony Cahill The MATLAB Environment The Desktop Environment Command Window (Interactive commands) Command History Window Edit/Debug Window Workspace Browser Figure Windows
More informationAMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA
AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA MATLAB (short for MATrix LABoratory) is a very useful piece of software for numerical
More informationTo start using Matlab, you only need be concerned with the command window for now.
Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,
More informationMATLAB Tutorial III Variables, Files, Advanced Plotting
MATLAB Tutorial III Variables, Files, Advanced Plotting A. Dealing with Variables (Arrays and Matrices) Here's a short tutorial on working with variables, taken from the book, Getting Started in Matlab.
More informationProgramming Exercise 3: Multi-class Classification and Neural Networks
Programming Exercise 3: Multi-class Classification and Neural Networks Machine Learning Introduction In this exercise, you will implement one-vs-all logistic regression and neural networks to recognize
More informationIntroduction to MATLAB
Introduction to MATLAB The Desktop When you start MATLAB, the desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. The following
More informationHow to learn MATLAB? Some predefined variables
ECE-S352 Lab 1 MATLAB Tutorial How to learn MATLAB? 1. MATLAB comes with good tutorial and detailed documents. a) Select MATLAB help from the MATLAB Help menu to open the help window. Follow MATLAB s Getting
More informationFreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx
1 of 9 FreeMat Tutorial FreeMat is a general purpose matrix calculator. It allows you to enter matrices and then perform operations on them in the same way you would write the operations on paper. This
More informationELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)
Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies
More informationArray Creation ENGR 1181 MATLAB 2
Array Creation ENGR 1181 MATLAB 2 Array Creation In The Real World Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data are critical to
More informationPhysics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.
Physics 326G Winter 2008 Class 2 In this class you will learn how to define and work with arrays or vectors. Matlab is designed to work with arrays. An array is a list of numbers (or other things) arranged
More informationProgramming Exercise 1: Linear Regression
Programming Exercise 1: Linear Regression Machine Learning Introduction In this exercise, you will implement linear regression and get to see it work on data. Before starting on this programming exercise,
More informationCourse Layout. Go to https://www.license.boun.edu.tr, follow instr. Accessible within campus (only for the first download)
Course Layout Lectures 1: Variables, Scripts and Operations 2: Visualization and Programming 3: Solving Equations, Fitting 4: Images, Animations, Advanced Methods 5: Optional: Symbolic Math, Simulink Course
More informationArray Accessing and Strings ENGR 1181 MATLAB 3
Array Accessing and Strings ENGR 1181 MATLAB 3 Array Accessing In The Real World Recall from the previously class that seismic data is important in structural design for civil engineers. Accessing data
More informationLab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013
Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.
More informationProject 2: How Parentheses and the Order of Operations Impose Structure on Expressions
MAT 51 Wladis Project 2: How Parentheses and the Order of Operations Impose Structure on Expressions Parentheses show us how things should be grouped together. The sole purpose of parentheses in algebraic
More informationIntroduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis
Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise
More informationThe value of f(t) at t = 0 is the first element of the vector and is obtained by
MATLAB Tutorial This tutorial will give an overview of MATLAB commands and functions that you will need in ECE 366. 1. Getting Started: Your first job is to make a directory to save your work in. Unix
More informationLesson 2b Functions and Function Operations
As we continue to work with more complex functions it is important that we are comfortable with Function Notation, opertions on Functions and opertions involving more than one function. In this lesson,
More informationQuestion. Insight Through
Intro Math Problem Solving October 10 Question about Accuracy Rewrite Square Root Script as a Function Functions in MATLAB Road Trip, Restaurant Examples Writing Functions that Use Lists Functions with
More informationAllocating Storage for 1-Dimensional Arrays
Allocating Storage for 1-Dimensional Arrays Recall that if we know beforehand what size we want an array to be, then we allocate storage in the declaration statement, e.g., real, dimension (100 ) :: temperatures
More informationVector: A series of scalars contained in a column or row. Dimensions: How many rows and columns a vector or matrix has.
ASSIGNMENT 0 Introduction to Linear Algebra (Basics of vectors and matrices) Due 3:30 PM, Tuesday, October 10 th. Assignments should be submitted via e-mail to: matlabfun.ucsd@gmail.com You can also submit
More informationFall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017)
MATH-GA 2010.001/CSCI-GA 2420.001, Georg Stadler (NYU Courant) Fall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017) Objectives. This class is for you and you should try to get the most out of
More informationFinite Math - J-term Homework. Section Inverse of a Square Matrix
Section.5-77, 78, 79, 80 Finite Math - J-term 017 Lecture Notes - 1/19/017 Homework Section.6-9, 1, 1, 15, 17, 18, 1, 6, 9, 3, 37, 39, 1,, 5, 6, 55 Section 5.1-9, 11, 1, 13, 1, 17, 9, 30 Section.5 - Inverse
More informationAn introduction to plotting data
An introduction to plotting data Eric D. Black California Institute of Technology February 25, 2014 1 Introduction Plotting data is one of the essential skills every scientist must have. We use it on a
More informationMATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1
MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED Christian Daude 1 Introduction MATLAB is a software package designed to handle a broad range of mathematical needs one may encounter when doing scientific
More informationHow To Test Your Code A CS 1371 Homework Guide
Introduction After you have completed each drill problem, you should make it a habit to test your code. There are good ways of testing your code and there are bad ways of testing your code. This guide
More informationBasics of Computational Geometry
Basics of Computational Geometry Nadeem Mohsin October 12, 2013 1 Contents This handout covers the basic concepts of computational geometry. Rather than exhaustively covering all the algorithms, it deals
More informationRelational and Logical Statements
Relational and Logical Statements Relational Operators in MATLAB A operator B A and B can be: Variables or constants or expressions to compute Scalars or arrays Numeric or string Operators: > (greater
More informationTable of Laplace Transforms
Table of Laplace Transforms 1 1 2 3 4, p > -1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Heaviside Function 27 28. Dirac Delta Function 29 30. 31 32. 1 33 34. 35 36. 37 Laplace Transforms
More informationStat 579: Objects in R Vectors
Stat 579: Objects in R Vectors Ranjan Maitra 2220 Snedecor Hall Department of Statistics Iowa State University. Phone: 515-294-7757 maitra@iastate.edu, 1/23 Logical Vectors I R allows manipulation of logical
More informationClustering Images. John Burkardt (ARC/ICAM) Virginia Tech... Math/CS 4414:
John (ARC/ICAM) Virginia Tech... Math/CS 4414: http://people.sc.fsu.edu/ jburkardt/presentations/ clustering images.pdf... ARC: Advanced Research Computing ICAM: Interdisciplinary Center for Applied Mathematics
More informationExcel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller
Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing
More informationA Tour of Matlab for Math 496, Section 6
A Tour of Matlab for Math 496, Section 6 Thomas Shores Department of Mathematics University of Nebraska Spring 2006 What is Matlab? Matlab is 1. An interactive system for numerical computation. 2. A programmable
More informationThe Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Chapter 1 An Introduction to MATLAB Course Information (from Course
More informationMATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras
MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras Module No. #01 Lecture No. #1.1 Introduction to MATLAB programming
More informationIntroduction to Matlab
Introduction to Matlab Andreas C. Kapourani (Credit: Steve Renals & Iain Murray) 9 January 08 Introduction MATLAB is a programming language that grew out of the need to process matrices. It is used extensively
More informationOUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.
1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN
More informationFall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB
Fall 2014 MAT 375 Numerical Methods Introduction to Programming using MATLAB Some useful links 1 The MOST useful link: www.google.com 2 MathWorks Webcite: www.mathworks.com/help/matlab/ 3 Wikibooks on
More informationEOSC 352 MATLAB Review
EOSC 352 MATLAB Review To use MATLAB, you can either (1) type commands in the window (i.e., at the command line ) or (2) type in the name of a file you have made, whose name ends in.m and which contains
More informationDefinition: A data structure is a way of organizing data in a computer so that it can be used efficiently.
The Science of Computing I Lesson 4: Introduction to Data Structures Living with Cyber Pillar: Data Structures The need for data structures The algorithms we design to solve problems rarely do so without
More informationEN 001-4: Introduction to Computational Design. Matrices & vectors. Why do we care about vectors? What is a matrix and a vector?
EN 001-: Introduction to Computational Design Fall 2017 Tufts University Instructor: Soha Hassoun soha@cs.tufts.edu Matrices & vectors Matlab is short for MATrix LABoratory. In Matlab, pretty much everything
More informationECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu
ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu 0. What is MATLAB? 1 MATLAB stands for matrix laboratory and is one of the most popular software for numerical computation. MATLAB s basic
More informationCS1114: Matlab Introduction
CS1114: Matlab Introduction 1 Introduction The purpose of this introduction is to provide you a brief introduction to the features of Matlab that will be most relevant to your work in this course. Even
More informationVARIABLES Storing numbers:
VARIABLES Storing numbers: You may create and use variables in Matlab to store data. There are a few rules on naming variables though: (1) Variables must begin with a letter and can be followed with any
More informationPython for Analytics. Python Fundamentals RSI Chapters 1 and 2
Python for Analytics Python Fundamentals RSI Chapters 1 and 2 Learning Objectives Theory: You should be able to explain... General programming terms like source code, interpreter, compiler, object code,
More information(Refer Slide Time 3:31)
Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 5 Logic Simplification In the last lecture we talked about logic functions
More informationLab 7 1 Due Thu., 6 Apr. 2017
Lab 7 1 Due Thu., 6 Apr. 2017 CMPSC 112 Introduction to Computer Science II (Spring 2017) Prof. John Wenskovitch http://cs.allegheny.edu/~jwenskovitch/teaching/cmpsc112 Lab 7 - Using Stacks to Create a
More informationComputer Vision. Matlab
Computer Vision Matlab A good choice for vision program development because Easy to do very rapid prototyping Quick to learn, and good documentation A good library of image processing functions Excellent
More informationMatlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia
Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia The goal for this tutorial is to make sure that you understand a few key concepts related to programming, and that you know the basics
More informationVectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018)
Vectors and Matrices Chapter 2 Linguaggio Programmazione Matlab-Simulink (2017/2018) Matrices A matrix is used to store a set of values of the same type; every value is stored in an element MATLAB stands
More informationSummer 2009 REU: Introduction to Matlab
Summer 2009 REU: Introduction to Matlab Moysey Brio & Paul Dostert June 29, 2009 1 / 19 Using Matlab for the First Time Click on Matlab icon (Windows) or type >> matlab & in the terminal in Linux. Many
More information