Assignment #3
clear, clc date
ans = 19-Sep-2007
A = [3, 7, -4, 12; -5, 9, 10, 2; 6, 13, 8, 11; 15, 5, 4, 1] % given x = sort(A') C = x' % b. E = sum(A') % d.
A =
3 7 -4 12
-5 9 10 2
6 13 8 11
15 5 4 1
x =
-4 -5 6 1
3 2 8 4
7 9 11 5
12 10 13 15
C =
-4 3 7 12
-5 2 9 10
6 8 11 13
1 4 5 15
E =
18 16 38 25
A = [1, 4, 2; 2, 4, 100; 7, 9, 7; 3, pi, 42] % given B = log(A) % given B_sum_second_row = sum(B(2, :)) % b. x = B(:, 2).*A(:, 1) max(x) % d.
A =
1.0000 4.0000 2.0000
2.0000 4.0000 100.0000
7.0000 9.0000 7.0000
3.0000 3.1416 42.0000
B =
0 1.3863 0.6931
0.6931 1.3863 4.6052
1.9459 2.1972 1.9459
1.0986 1.1447 3.7377
B_sum_second_row =
6.6846
x =
1.3863
2.7726
15.3806
3.4342
ans =
15.3806
A = [-7, 16; 4, 9], B = [6, -5; 12, -2], ... C = [-3, -9; 6, 8] % Given information. Sum = A + B + C % a. Sum_and_Difference = A - B + C % b. x = (A + B) + C y = A + (B + C) y == x % c. Returns matrix of 1's if true.
A =
-7 16
4 9
B =
6 -5
12 -2
C =
-3 -9
6 8
Sum =
-4 2
22 15
Sum_and_Difference =
-16 12
-2 19
x =
-4 2
22 15
y =
-4 2
22 15
ans =
1 1
1 1
A = [64, 32; 24, -16], B = [16, -4; 6, -2] % Given information Array_Product = A.*B % a. Element_Exponentiation = B.^3 % c.
A =
64 32
24 -16
B =
16 -4
6 -2
Array_Product =
1024 -128
144 32
Element_Exponentiation =
4096 -64
216 -8
% For Five_Widget_Makers: row 1 contains the worker number, % row 2 contains their hourly wages($), % row 3 containes their number of hours worked (per week), % row 4 containes their output(widgets per week). Five_Widget_Makers = [1, 2, 3, 4, 5; 5, 5.50, 6.50, 6, 6.25; ... 40, 43, 37, 50, 45; 1000, 1100, 1000, 1200, 1100] weekly_Earnings = Five_Widget_Makers(2, :).*Five_Widget_Makers(3, :) % a. (in $) Total_Salary = sum(weekly_Earnings') % b. Total_Widgets = sum(Five_Widget_Makers(4, :)') % c. Average_cost = Total_Salary/Total_Widgets % d. ($/widget) % e. (hours/widget) Hour_Widgets = sum(Five_Widget_Makers(3, :)')/sum(Five_Widget_Makers(4, :)') % for part f: The first array product gives each workers sallary per week, % deviding this by the number of widgets each worker makes per week % gives the efficiency of each worker in $/widget. f = (Five_Widget_Makers(2, :).*Five_Widget_Makers(3, :))./ ... Five_Widget_Makers(4, :) % Least efficiant worker, where Lest_efficiant is the worker number. [Efficiancy, Lest_efficiant] = min(f) % Most efficiant worker, where Most_efficiant is the worker number. [Efficiancy, Most_efficiant] = max(f)
Five_Widget_Makers =
1.0e+003 *
0.0010 0.0020 0.0030 0.0040 0.0050
0.0050 0.0055 0.0065 0.0060 0.0063
0.0400 0.0430 0.0370 0.0500 0.0450
1.0000 1.1000 1.0000 1.2000 1.1000
weekly_Earnings =
200.0000 236.5000 240.5000 300.0000 281.2500
Total_Salary =
1.2583e+003
Total_Widgets =
5400
Average_cost =
0.2330
Hour_Widgets =
0.0398
f =
0.2000 0.2150 0.2405 0.2500 0.2557
Efficiancy =
0.2000
Lest_efficiant =
1
Efficiancy =
0.2557
Most_efficiant =
5
% For Material_Price: column 1 is the material number, % column 2 is the price corresponding to each material ($/ton) Material_Price = [1, 300; 2, 550; 3, 400; 4, 250; 5, 500] % For Quantity_Purchased(tons): column 1, 2, and 3 is the ammount of % material purchased in the month of May, June, and July respectively. Quantity_Purchased = [5, 4, 6; 3, 2, 4; 6, 5, 3; 3, 5, 4; 2, 4, 3] l = Material_Price(:, 2).*Quantity_Purchased(:, 1) m = Material_Price(:, 2).*Quantity_Purchased(:, 2) n = Material_Price(:, 2).*Quantity_Purchased(:, 3) v = [l,m,n] % a. % b. May = sum(l) % Total spent in May June = sum(m) % Total spent in June July = sum(n) % Total spent in July % c. Mat1 = sum(v(1, :)) % Total spent on Material 1 Mat2 = sum(v(2, :)) % Total spent on Material 2 Mat3 = sum(v(3, :)) % Total spent on Material 3 Mat4 = sum(v(4, :)) % Total spent on Material 4 Mat5 = sum(v(5, :)) % Total spent on Material 5 Total_Spent = sum([May,June,July]) % d.
Material_Price =
1 300
2 550
3 400
4 250
5 500
Quantity_Purchased =
5 4 6
3 2 4
6 5 3
3 5 4
2 4 3
l =
1500
1650
2400
750
1000
m =
1200
1100
2000
1250
2000
n =
1800
2200
1200
1000
1500
v =
1500 1200 1800
1650 1100 2200
2400 2000 1200
750 1250 1000
1000 2000 1500
May =
7300
June =
7550
July =
7700
Mat1 =
4500
Mat2 =
4950
Mat3 =
5600
Mat4 =
3000
Mat5 =
4500
Total_Spent =
22550