Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
A. A Mathematical Introduction to Matrices
327
The sum C = A + B is determined as follows. Firstly the element c1,1 is
obtained by adding the corresponding elements in A and B, so that
a
c
b
d
+
=
a+
.
Now for the c1,2 entry (the top right element):
a
c
b
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
A. A Mathematical Introduction to Matrices
325
Of all the operations which can be performed on matrices one of the simplest
is that of transposition (or taking the transpose of a matrix); this operation is
usually denoted by a subscript T or a prime . If
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
326
A. A Mathematical Introduction to Matrices
The usual arithmetic operations of addition, subtraction and multiplication
also apply to matrices. However, there are now several additional rules (or
constraints) under which these operations can be perform
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
324
A. A Mathematical Introduction to Matrices
one row) then we refer to it as a row vector. A scalar is simply a matrix in which
both n and m are equal to one (that is, a onebyone matrix). Throughout this
text we will adopt the universal convection tha
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
A
A Mathematical Introduction to Matrices
Matrices are objects which have special properties and there are a number of
rules which must be adhered to in order to manipulate them in a consistent
(and correct) manner. A matrix can most readily be dened as a
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
322
9. Simulations and Random Numbers
for a variety of values of using the code:
9
cosa = 0.34;
sina = sqrt(1cosa2);
ii = 0;
for st = 0.5:0.05:0.5
6
x = st; y = st;
for its = 1:1000
ii = ii+1;
xn = cosa*xsina*y+x2*sina;
yn = sina*x+cosa*yx2*cosa;
x =
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
9.5 Tasks
321
Task 9.5 By experimenting with the value of mu in the above code identify a
value for which there is a real period 2 cycle and then show that the points occur
in pairs using the code map.m.
In order to nd roots of higher order it is obviousl
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
408
C. Solutions to Tasks
9
x = linspace(4,4);
N = length(x);
for j = 1:N
if x(j) >= 0 & x(j) <= 1
f(j) = x(j);
elseif x(j) >= 1 & x(j) < 2
f(j) = 2  x(j);
else
f(j) = 0;
end
end
8
6
7
C.4 Solutions for Tasks from Chapter 4
Solution 4.1 The solution to
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.4 Solutions for Tasks from Chapter 4
411
Solution 4.8 The function f (x) = cos 3x has three zeros in the range 0 to .
Using the full range, we encounter the left root /6 (in fact we should check
whether f (b + a)/2) is smaller than the tolerance, which
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
410
C. Solutions to Tasks
Considering b > 2 the modulus of this function is greater than one for the
root corresponding to the negative sign and less than one for the root with the
positive sign. For the other option we nd that
g (x) =
b
2
(bx + 1)
.
Wh
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.4 Solutions for Tasks from Chapter 4
409
(
1
b = input(Value of b );
x = 10:0.1:10;
f = x.2+b*x+1;
plot(x,f)
0
)
Notice that we have chosen the range [10, 10] but we could have used knowledge
of the structure of the function to make sure that both root
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.3 Solutions for Tasks from Chapter 3
407
4
3
2
1
0
1
2
3
4
3
2
1
0
1
2
3
and the choice of 1015 is in a sense arbitrary, but reects how close we come
to the singularities.
Solution 3.18 The rst line contains a spelling mistake: the command should
be lin
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.3 Solutions for Tasks from Chapter 3
9
sumln(1) = 1;
for n = 1:1000
sumln(n+1) = sumln(n)+(1)(n+1)/(n+1);
end
403
6
sum2(1) = 1/2;
for n = 1:1000
sum2(n+1) = sum2(n)+1/(n+1)*(n+2);
end
8
7
where we have used the terms in the summations evaluated at th
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.3 Solutions for Tasks from Chapter 3
9
function [val] = isdigit(charac)
lchar = charac(1);
if lchar>=0 & lchar <=9
val = 1;
else
val = 0;
end
8
We can now use the functions:
9
msg = Please enter a letter and a digit ;
405
6
7
6
str = input(msg,s);
while
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
402
C. Solutions to Tasks
cos(v)cosx
ans =
0
0
0
0
This means that the dierence between the MATLAB and the series answers
are less than eps.
Solution 3.6 We can use code which performs the summations separately for
dierent values of N or note that SN +1
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
404
C. Solutions to Tasks
Solution 3.13 We have
1
n = 1:50;
f = n.3n.2+40;
ii = find(f > 1000 & mod(n,3) = 0);
n(ii)
0
(
)
Solution 3.14 The key here is to start with the string of the rst ten letters,
namely abcdefghij. We ask the user to enter the rst
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.3 Solutions for Tasks from Chapter 3
401
5
2
s = 0;
for i = 1:100
s = s+1/i2;
end
disp([Required value is num2str(s)])
4
3
Notice that we have changed the command int2str to num2str: this is because
the answer is no longer an integer.
Solution 3.2 This
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.2 Solutions for Tasks from Chapter 2
9
w = ones(1,9);
399
6
w(1) = 1;
for j = 1:4
w(2*j) = 3;
w(2*j+1) = 2*j+1;
end
8
7
Solution 2.11
(a) Here the conversion factor will be worked out by remembering that there are
1760 yards in a mile, a yard is 36 inch
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.2 Solutions for Tasks from Chapter 2
397
8
f
g
f*g
f/g
7
6
5
4
3
2
1
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
We have added a legend which uses the line styles to show which lines we have
plotted. We could have used dierent style lines. We have used the ad
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.2 Solutions for Tasks from Chapter 2
395
Solution 2.3 The function for this purpose is:
function [out] = twox(x)
out = 2.x;
Note the use of the dot so that it can be called with a vector (or even matrix).
Try it with x=1:8.
Solution 2.4 We can do this c
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
396
C. Solutions to Tasks
#
function [outx,outy] = mapcode(inx,iny)
outx = mod(inx+iny,1);
outy = mod(inx+2*iny,1);
"
!
Solution 2.7 This requires the modication of the second line to read y =
x.3+3*x. The change in the limit requires the modication of th
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
394
C. Solutions to Tasks
16
14
12
10
8
6
4
2
0
2
2
1.5
1
0.5
0
0.5
1
1.5
2
Solution 1.11 The corrected code should be
9
x = 0:0.1:3;
f = x.3.*cos(x+1);
% x = 2
f(21)
% x = 3
f(end)
8
6
7
C.2 Solutions for Tasks from Chapter 2
Solution 2.1 This is hopeful
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.1 Solutions for Tasks from Chapter 1
393
9
6
clear all
x = linspace(0,1,200);
g = x.3+1;
h = x+2;
z = x.2;
y = cos(x*pi);
f = y.*z./(g.*h);
f(200)
8
7
The errors were: the second line should have been rst, else this cleared out the
contents of x. The de
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
398
C. Solutions to Tasks
denominator of the fraction, forcing it to be evaluated rst. In the display
line the rst square bracket is missing and the answer needs to be converted
to a string, which should be sum not s. On top of this we have failed to set
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
390
C. Solutions to Tasks
The values this returns are: 6.5900, 0.5000, 0.7854 (which is /4) and
0.5000.
Solution 1.2 To calculate the function y(x) = x sin x2 we use the code:
x = pi/3;
y = abs(x)*sin(x2);
and similarly for x = /6. Notice care is needed
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
C.1 Solutions for Tasks from Chapter 1
391
> x=[3 4 5]
x =
3
4
5
0
1
0
1
> rem(x,4)
ans =
3
> mod(x,4)
ans =
3
> rem(x,4)
ans =
3
0
1
> mod(x,4)
ans =
1
0
3
>
So for the second argument being positive we have that rem and mod are equivalent, whereas f
Physical Educ Activity Program, Physical Fitness Exercise To Music
764 225

Fall 2014
386
B. Glossary of Useful Terms
sqrt This nds the square root of a matrix element by element. If necessary
the answer may be returned as a complex number.
std Calculates the standard deviation of a vector.
str2mat As the name suggests, this takes a string