Professional Documents
Culture Documents
Problem 1:
Write a function to calculate the sum, product and average of five numbers.
Note: Only one function with input of five numbers and 3 outputs of sum,
product and average.
MATLAB Code:
close all; clear all; clc;
a = input('Type the first number: ');
b = input('Type the second number: ');
c = input('Type the third number: ');
d = input('Type the fourth number: ');
e = input('Type the fifth number: ');
[Sum, Prod, Aver] = func(a,b,c,d,e);
fprintf('The sum, product and average of five input number is %4.2f,
%4.2f and %4.2f, respectively', Sum, Prod, Aver);
Problem 2:
MATLAB Codes:
clear all; close all; clc;
A = [-7 11; 4 9]
B = [4 -5; 12 -2]
C = [-3 -9; 7 8]
% Find A + B + C
a=A+B+C
% Find A - B + C
b=A-B+C
%Associative law: (A + B) + C = A + (B + C)
L=A+B
LHS = L + C
R=B+C
RHS = R + A
LHS - RHS
%Commutative law: A + B + C = B + C + A = A + C + B
D=A+B+C
E=B+C+A
F=A+C+B
D–E
D–F
E–F
Problem 3:
MATLAB Codes:
close all; clear all; clc;
A = [ 3 7 -4 12; -5 9 10 2; 6 13 8 11; 15 5 4 1]
max_column = max(A)
min_column = min(A)
max_row = max(A, [], 2)
min_row = min(A, [], 2)