-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lab1_zounes.m
330 lines (186 loc) · 4.4 KB
/
Lab1_zounes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
% Name: Eric Zounes
% Date: 09/26/2012
% Lab1: MATLAB Tutorial
% Task A
% 1.
tut1 = [1,2,3,4,5; 6,7,8,9,10; 11,12,13,14,15]
tut2 = [1,3,5,7,9; 11,13,15,17,19; 2,3,5,7,11]
% Output:
% tut1 =
% 1 2 3 4 5
% 6 7 8 9 10
% 11 12 13 14 15
% tut2 =
% 1 3 5 7 9
% 11 13 15 17 19
% 2 3 5 7 11
% 2.
size(tut1)
size(tut2)
% Output: (both)
% ans =
% 3 5
% Task B
% 1.
diag(ones(1,5))
% Output:
% ans =
% 1 0 0 0 0
% 0 1 0 0 0
% 0 0 1 0 0
% 0 0 0 1 0
% 0 0 0 0 1
% 2.
evens = [6:3:24]
% Output:
% evens =
% 6 8 10 12 14 16 18 20 22 24
% Task C
fdj = [1 2 3;5 4 3; 6 5 8]
% 1.
% Output:
% fdj =
% 1 2 3
% 5 4 3
% 6 5 8
fdj+3
% Output:
% ans =
% 4 5 6
% 8 7 6
% 9 8 11
fdj-6
% Output:
% ans =
% -5 -4 -3
% -1 -2 -3
% 0 -1 2
fdj/2
% Output:
% ans =
% 0.5000 1.0000 1.5000
% 2.5000 2.0000 1.5000
% 3.0000 2.5000 4.0000
% 2.
abc = 1:10;
% Output:
% abc =
% 1 2 3 4 5 6 7 8 9 10
% This command creates a vector of integers from 1 to 10 with a default step of 1.
def = 5:14;
% Output:
% def =
% 5 6 7 8 9 10 11 12 13 14
% This command crates a vector of integers from 1 to 10 with a default step of 1.
ghi = 3*abc + def
% Output:
% ghi =
%
% 8 12 16 20 24 28 32 36 40 44
% This command does component-wise multiplication on abc then performs addition on the resultant vector with def.
% 3.
abc = [1 2 3 4; 5 6 7 8];
def = [4 3 2 1;8 7 6 5];
abc + def
% Output:
% ans =
%
% 5 5 5 5
% 13 13 13 13
%
% The output contains the same value for each row because each component of abc and def increment and decrement respectively.
% 4.
tut1 .* tut2
tut2 .* tut1
tut1 ./ tut2
tut2 ./ tut1
tut1 .^ 2
tut1 .* tut2
% Output:
%
% ans =
% 1 6 15 28 45
% 66 91 120 153 190
% 22 36 65 98 165
tut2 .* tut1
% Output:
%
%ans =
% 1 6 15 28 45
% 66 91 120 153 190
% 22 36 65 98 165
tut1 ./ tut2
% Output:
%
%ans =
% 1.0000 0.6667 0.6000 0.5714 0.5556
% 0.5455 0.5385 0.5333 0.5294 0.5263
% 5.5000 4.0000 2.6000 2.0000 1.3636
tut2 ./ tut1
% Output:
% ans =
% 1.0000 1.5000 1.6667 1.7500 1.8000
% 1.8333 1.8571 1.8750 1.8889 1.9000
% 0.1818 0.2500 0.3846 0.5000 0.7333
tut1 .^ 2
% Output:
%ans =
% 1 4 9 16 25
% 36 49 64 81 100
% 121 144 169 196 225
% Task D
% 1.
% tut1 * tut2
% Output: ERROR
% The matrices tut1 and tut2 cannot be multiplied because the dimensions of their rows/columns are not equal.
% tut2 * tut1
% Output: ERROR
% The matrices tut2 and tut1 cannot be multiplied because the dimensions of their rows/coumns are not equal.
tut1 * tut2'
% Output:
% ans =
% 95 245 106
% 220 620 246
% 345 995 386
% tut1 can be multiplied by the transpose of tut2 because their dimensions are equal.
tut2' * tut1
% Output:
% ans =
% 89 103 117 131 145
% 114 133 152 171 190
% 150 175 200 225 250
% 186 217 248 279 310
% 244 283 322 361 400
tut1 ^ 2
% Output: ERROR
% tut1 cannot be multiplied because it isn't square.
(tut2' * tut1)^2
% Output:
% ans =
% 96959 112803 128647 144491 160335
% 126274 146908 167542 188176 208810
% 166150 193300 220450 247600 274750
% 206026 239692 273358 307024 340690
% 267024 310658 354292 397926 441560
% The first multiplication results in a square matrix which allows it to be squared.
% 2.
foo = [1,2,3,4,5,6,7,8,9,10]
foo*ones(1,10)'
% Output: 55
% ans = 55
% 3.
[1:100]*ones(1,100)'
% Output:
% ans = 5050
% 4.
bar = [2:2:1001]
bar*ones(1,size(bar,2))'
% Output:
% ans = 250500
% Task E
% 1.
% The output of the graph shows greater resolution on the slope of the function.
% 2.
% The output is the unit circle.
% 3.
% Task F