Exercises week 2
Table of Contents
Exercise 2.3 ....................................................................................................................................... 1
Task A .............................................................................................................................................. 1
Task B .............................................................................................................................................. 2
Exercise 2.4 ....................................................................................................................................... 3
Task 1 ............................................................................................................................................... 3
Task 2 ............................................................................................................................................... 3
Task 3 ............................................................................................................................................... 4
Task 4 ............................................................................................................................................... 4
Exercise 2.6 ....................................................................................................................................... 5
Task A1 ............................................................................................................................................. 5
Task A2 ............................................................................................................................................. 5
Task A3 ............................................................................................................................................. 5
Task B1 & B2 ..................................................................................................................................... 6
Task B3 ............................................................................................................................................. 6
Task C1 & C2 ..................................................................................................................................... 6
Task C3 ............................................................................................................................................. 6
Task D .............................................................................................................................................. 6
Exercise 2.9 ....................................................................................................................................... 7
Task 1 & 2 ......................................................................................................................................... 7
Task 3 ............................................................................................................................................... 9
Task 4 ............................................................................................................................................... 9
Task 5 ............................................................................................................................................... 9
Exercise 2.3
Task A
% Values for leg A
A = [3,5,1,3,2];
% Values for leg B
B = [1,3,2,7,2];
% Preallocate a 5x5 matrix for the results
C = zeros(5,5);
% Compute the combinations for the hypothenuse using Pythagoras' theorem
for i = 1:length(A);
l = 1:length(B);
C(i,l)=sqrt(A(i).^2+B(l).^2);
end
% Display the resulting matrix containing all hypotenuse lengths
disp('The length of the hypothenuse is')
disp(C)
The length of the hypothenuse is
3.1623 4.2426 3.6056 7.6158 3.6056
5.0990 5.8310 5.3852 8.6023 5.3852
1
Table of Contents
Exercise 2.3 ....................................................................................................................................... 1
Task A .............................................................................................................................................. 1
Task B .............................................................................................................................................. 2
Exercise 2.4 ....................................................................................................................................... 3
Task 1 ............................................................................................................................................... 3
Task 2 ............................................................................................................................................... 3
Task 3 ............................................................................................................................................... 4
Task 4 ............................................................................................................................................... 4
Exercise 2.6 ....................................................................................................................................... 5
Task A1 ............................................................................................................................................. 5
Task A2 ............................................................................................................................................. 5
Task A3 ............................................................................................................................................. 5
Task B1 & B2 ..................................................................................................................................... 6
Task B3 ............................................................................................................................................. 6
Task C1 & C2 ..................................................................................................................................... 6
Task C3 ............................................................................................................................................. 6
Task D .............................................................................................................................................. 6
Exercise 2.9 ....................................................................................................................................... 7
Task 1 & 2 ......................................................................................................................................... 7
Task 3 ............................................................................................................................................... 9
Task 4 ............................................................................................................................................... 9
Task 5 ............................................................................................................................................... 9
Exercise 2.3
Task A
% Values for leg A
A = [3,5,1,3,2];
% Values for leg B
B = [1,3,2,7,2];
% Preallocate a 5x5 matrix for the results
C = zeros(5,5);
% Compute the combinations for the hypothenuse using Pythagoras' theorem
for i = 1:length(A);
l = 1:length(B);
C(i,l)=sqrt(A(i).^2+B(l).^2);
end
% Display the resulting matrix containing all hypotenuse lengths
disp('The length of the hypothenuse is')
disp(C)
The length of the hypothenuse is
3.1623 4.2426 3.6056 7.6158 3.6056
5.0990 5.8310 5.3852 8.6023 5.3852
1