{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# HW2S - result = 0.5000 1.0000 1.0000 16.0000 2.4 2.5(a...

This preview shows pages 1–4. Sign up to view the full content.

Fall 2011, Dr. Frank Shih 2.1 (a) Giving anyone of them is correct: [3:4:67] or [3:4:68] or [3:4:69] or [3:4:70] (b) Giving anyone of them is correct: [-32:7:31] or [-32:7:32] or [-32:7:33] or [-32:7:34] or [-32:7:35] or [-32:7:36] or [-32:7:37] (c) 17 12 7 2 -3 (d) Empty matrix: 1-by-0 (e) 4 5 6 7 8 9 2.2 (a) b = 1 1 0 3 1 (b) c = 0 0 0 0 0 0 0 6 (c) d = 1 2 0 0 0 8 (d) size(A) ans = 3 3 (e) size(A) ans = 3 3 2 2.3 (a) >> result = a + b result = 1 4 -1 6 (b) >> result = a * d result = 2 1 -1 4 (c) >> result = a .* d result = 2 0 0 4 (d) >> result = a * c result = 5 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Fall 2011, Dr. Frank Shih (e) Illegal: This is element by element array multiplication, and the two arrays have different sizes. (f) >> result = a \ b result = -0.4444 1.1111 -0.1111 0.7778 (g) >> result = a .\ b result = -0.5000 3.0000 0 0.5000 (h) >> result = a .^ b result =

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: result = 0.5000 1.0000 1.0000 16.0000 2.4 2.5 (a) clear clc A1 = [2,4,8] B1 = [3,9,27] odds=1:2:(2*length(A1)); evens= 2:2:(2*length(A1)); C1(odds)=A1+B1; C1(evens)=A1-B1 (b) The script file “hw2.m” is Fall 2011, Dr. Frank Shih clear clc A1 = input( 'Enter A1 ' ); B1 = input( 'Enter B1 ' ); odds=1:2:(2*length(A1)); evens= 2:2:(2*length(A1)); C1(odds)=A1+B1; C1(evens)=A1-B1 In command window, type >>hw2 Enter A1 [-2, -4, -8, -10, -12] Enter B1 [3, 9, 27, 21, 23] C1 = 1 -5 5 -13 19 -35 11 -31 11 -35 Bonus clear clc close all x = linspace(-5, 5, 60); y1 = 3*x; y2 = (3*x).^ 2; y3 = (3*x).^ 3; y4 = (3*x).^ 4; plot(x,y1,x,y2,x, y3, x, y4) xlabel( 'x Value' ) ylabel( 'y Value' ) title( 'Powers of x' ) legend( 'y1' , 'y2' , 'y3' , 'y4' ) Fall 2011, Dr. Frank Shih -5-4-3-2-1 1 2 3 4 5-1 1 2 3 4 5 6 x 10 4 x Value y Value Powers of x y1 y2 y3 y4...
View Full Document

{[ snackBarMessage ]}