Professional Documents
Culture Documents
Question #1
In[ ]:= n = Input["Any integer"];
a = 2n-1
Out[ ]= 107
In[ ]:= Print["Number of primes less than of equal to ", n, " is ", PrimePi[n]]
Number of primes less than of equal to 54 is 16
In[ ]:= Print["The next prime larger than ", n, " is ", NextPrime[n]]
The next prime larger than 54 is 59
nC 4= 316 251
Question #2
(Do loop)
In[ ]:= n = Input["Number of terms"];
elem = 0.0;
sum = 0.0;
1
Doelem = elem + ; sum = sum + elem, {i, 1, n}
2i+1
Print["Sum of the first ", n, " terms of the sequence= ", sum]
Sum of the first 20 terms of the sequence= 22.3374
(For loop)
In[ ]:= n = Input["Number of terms"];
elem = 0.0;
sum = 0.0;
1
Fori = 1, i ≤ n, i ++, elem = elem + ; sum = sum + elem
2i+1
Print["Sum of the first ", n, " terms of the sequence= ", sum]
Sum of the first 20 terms of the sequence= 22.3374
Question #3
(Using symbol)
In[ ]:= nom = 1.0;
denom = 2.0;
∞ nom = nom * (i + 1)
i=2
denom = denom * (2 * i)
Which indicates that the series is divergent, hence it’s not possible to specify the sum of the series up to
infinity. We can try to sum up the series to finite terms in following way.
In[ ]:= n = Input[] + 1;
Print["Sum of the series upto ", n, " terms"]
nom = 1.0;
denom = 2.0;
n nom = nom * (i + 1)
i=2
denom = denom * (2 * i)
Out[ ]= 0.993652
MTH-150 (Exercise Sheets).nb 5
(Using command)
In[ ]:= n = Input[] + 1;
Print["Sum of the series upto ", n, " terms"]
nom = 1.0;
denom = 2.0;
nom = nom * (i + 1)
Sum , {i, 2, n}
denom = denom * (2 * i)
Sum of the series upto 10 terms
Out[ ]= 0.993652
(Using loops)
In[ ]:= n = Input[] + 1;
nom = 1.0;
denom = 2.0;
sum = 0.0;
nom
Donom = nom * (i + 1); denom = denom * (2 * i); sum = sum + , {i, 2, n}
denom
Print["Sum of the series upto ", n, " terms= ", sum]
Sum of the series upto 10 terms= 0.993652
Question #4
(Sum)
In[ ]:= n = Input["Number of terms(Enter odd integer≥15)"];
elem = 0.0;
sum = 0.0;
i
Doelem = elem + ; sum = sum + elem, {i, 1, n}
2*i-1
Print["Sum of the first ", n, " terms of the sequence= ", sum]
Sum of the first 25 terms of the sequence= 675.172
(Product)
In[ ]:= n = Input["Number of terms(Enter odd integer≥15)"];
elem = 0.0;
product = 1.0;
i
Doelem = elem + ; product = product * elem, {i, 1, n}
2*i-1
Print["Product of the first ", n, " terms of the sequence= ", product]
Product of the first 19 terms of the sequence= 1.11764 × 10 21
Question #5
In[ ]:= sum = 0.0;
elem = 0.0;
1
Fori = 1, i ≤ 20, i ++, elem = elem + ; sum = sum + elem
i
Print["Sum of the sequence= ", sum]
Sum of the sequence= 55.5525
Question #6
In[ ]:= list1 = RandomInteger[{- 10, 10}, 10]
Out[ ]= {4, 1, - 6, - 7, - 6, - 2, 7, 6, - 4, - 7}
Question #7
In[ ]:= intlist = Range[49, 1, - 1]
Out[ ]= {49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26,
25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
8 MTH-150 (Exercise Sheets).nb
Question #8
In[ ]:= n = Input["Any two digits integer"];
list1 = Range[1, n, 1]
Out[ ]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}
Question #9
In[ ]:= FIB21 = {};
Do[AppendTo[FIB21, Fibonacci[i]], {i, 1, 21}]
Print[FIB21]
{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10 946}
Question #10
In[ ]:= FIB30 = {};
Do[AppendTo[FIB30, Fibonacci[i]], {i, 1, 30}]
Print[FIB30]
{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181,
6765, 10 946, 17 711, 28 657, 46 368, 75 025, 121 393, 196 418, 317 811, 514 229, 832 040}
Question #11
In[ ]:= f0 = 1;
f1 = 1;
f[n_] := f[n - 1] + f[n - 2]
Question #12
In[ ]:= f1 = 3;
f2 = 5;
fibs = {};
AppendTo[fibs, f1 ];
AppendTo[fibs, f2 ];
For[i = 3, i ≤ 10, i ++, fi = fi-1 + fi-2 ; AppendTo[fibs, fi ]]
Print["Fibonacci sequence: ", fibs]
Fibonacci sequence: {3, 5, 8, 13, 21, 34, 55, 89, 144, 233}
Question #13
In[ ]:= list = Range[500];
primes = {};
Do[If[PrimeQ[list〚i〛] True, AppendTo[primes, list〚i〛]], {i, 1, Length[list]}]
Print["Prime numbers less than 500: ", primes]
Prime numbers less than 500:
{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,
89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179,
181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277,
281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389,
397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499}
Question #14
In[ ]:= n = 100;
n
A = Range ;
10
n
Print"First positive numbers: ", A
10
n
First positive numbers: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
10
In[ ]:= Grid[{{"A", "B", "C", "D"}, {A, B, c, d}}, Frame All]
A B C D
Out[ ]= {1, 2, 3, 4, 5, {2, 3, 5, 7, 11, {1, 1, 2, 3, 5, {6, 28, 496}
6, 7, 8, 9, 10} 13, 17, 19, 23, 29} 8, 13, 21, 34, 55}
12 MTH-150 (Exercise Sheets).nb
Question #15
In[ ]:= deg = Table[i, {i, 0, 60, 5}];
π
rad = Tablei * , {i, 0, 60, 5};
180
body = Table[{deg〚i〛, rad〚i〛}, {i, 1, Length[deg]}];
TableFormbody, TableHeadings None, "Degree(°)", "Radian( c )"
Out[ ]//TableForm=
Degree(°) Radian(c )
0 0
π
5
36
π
10
18
π
15
12
π
20
9
5π
25
36
π
30
6
7π
35
36
2π
40
9
π
45
4
5π
50
18
11 π
55
36
π
60
3
Question #16
In[ ]:= list = {13, 28, 51, 119};
prime = {};
Do[If[PrimeQ[list〚i〛] True, AppendTo[prime, list〚i〛]], {i, 1, Length[list]}];
Print["Prime numbers from the list: ", prime]
Prime numbers from the list: {13}
Calculus
Question #1
In[ ]:= f[x_] := (x - 1) (x - 2) (x - 3)
In[ ]:= Print["f(-4)=", f[- 4], ", f(4)=", f[4], ", g(0)=",
g[0], ", g(2)=", g[2], ", g(-2)=", g[- 2], ", g(-8)=", g[- 8]]
f(-4)=-210, f(4)=6, g(0)=0, g(2)=4, g(-2)=-3, g(-8)=-8
Out[ ]=
X
-10 -5 5 10
-5
-10
In[ ]:= Plot[g[x], {x, - 20, 20}, PlotRange {{- 10, 10}, {- 10, 10}},
PlotStyle {RGBColor[Green], Thickness[Small]},
Axes True, AxesLabel {X, Y}, GridLines Automatic]
Y
10
Out[ ]=
X
-10 -5 5 10
-5
-10
14 MTH-150 (Exercise Sheets).nb
Out[ ]=
X
-10 -5 5 10
-5
-10
Here the domain and range of f(x) is , whereas, the domain of g(x) is and the range is [-8,+∞). Also,
f(x) is a polynomial functions and thus differentiable over its entire domain.
In[ ]:= Dt[f[x], x] // Simplify
Out[ ]= 11 - 12 x + 3 x2
f (x)
Out[ ]= f ′ (x)
-4 -2 2 4
f ′′ (x)
-5
-10
(Increasing)
In[ ]:= Reduce[f '[x] > 0, x]
1 1
Out[ ]= x< 6 - 3 || x > 6 + 3
3 3
MTH-150 (Exercise Sheets).nb 15
(Decreasing)
In[ ]:= Reduce[f '[x] < 0, x]
1 1
Out[ ]= 6 - 3 < x < 6 + 3
3 3
(Concave up)
In[ ]:= Reduce[f ''[x] > 0, x]
Out[ ]= x>2
(Concave down)
In[ ]:= Reduce[f ''[x] < 0, x]
Out[ ]= x<2
(Critical points)
In[ ]:= Solve[f '[x] 0, x]
1 1
Out[ ]= x 6 - 3 , x 6 + 3
3 3
(Inflection points)
In[ ]:= Solve[f ''[x] 0, x]
Out[ ]= {{x 2}}
As f’’(x) switches signs at x=2, f(x) has has it’s only inflection point at x=2. Now, f(x) has no absolute
extremum, but we can find the relative extrema using commands.
In[ ]:= FindMinimum[f[x], {x, 2.5}]
Out[ ]= {- 0.3849, {x 2.57735}}
1 1 1 1
In[ ]:= ListPlot 6 - 3 , f 6 - 3 , 6 + 3 , f 6 + 3 , {2, f[2]},
3 3 3 3
{2.577, f[2.577]}, {1.423, f[1.423]}, PlotStyle {Red, PointSize[Large]}
0.4
0.2
Out[ ]=
1.6 1.8 2.0 2.2 2.4 2.6
-0.2
-0.4
f (x)
Out[ ]= f ′ (x)
-4 -2 2 4
f ′′ (x)
-5
-10
Question #2
In[ ]:= Plot 5-x + x - 5 + 1.0, {x, - 10, 10}, PlotRange Full
1.0
0.5
Out[ ]=
-10 -5 5 10
-0.5
-1.0
1
In[ ]:= Plot , {x, - 10, 10}
Abs9 - x2
0.5
0.4
0.3
Out[ ]=
0.2
0.1
-10 -5 5 10
20
15
Out[ ]=
10
-10 -5 5 10
4
Out[ ]=
-4 -2 2 4
MTH-150 (Exercise Sheets).nb 19
Out[ ]=
4
-6 -4 -2 2 4 6
Out[ ]=
-4 -2 2 4
-2
20 MTH-150 (Exercise Sheets).nb
2.0
1.5
Out[ ]= 1.0
0.5
Question #3
In[ ]:= f[x_] := Cos[x]
2.5
2.0
f (x)
Out[ ]=
1.5 g(x)
1.0
0.5
X
-6 -4 -2 2 4 6
Out[ ]= {x - 2.35619}
Out[ ]= {x 3.92699}
MTH-150 (Exercise Sheets).nb 21
In[ ]:= ListPlot[{{- 5.498, f[- 5.498]}, {- 2.356, f[- 2.356]}, {3.927, f[3.927]}},
PlotStyle PointSize[Large]]
2.0
1.5
Out[ ]= 1.0
0.5
-4 -2 2 4
2.5
2.0
f (x)
Out[ ]=
1.5 g(x)
1.0
0.5
X
-6 -4 -2 2 4 6
Question #4
In[ ]:= f[x_] := x Sin[2 x]
Out[ ]=
-4 -2 2 4
-5
2
Out[ ]=
-4 -2 2 4
-2
-4
-6
2
Out[ ]=
-4 -2 2 4
-2
-4
-6
MTH-150 (Exercise Sheets).nb 23
Question #5
In[ ]:= DtLog[x y] Sin x2 y + 2 y , x
2 y - 2 + x2 y + x2 y Cos 2 y + x2 y
′
Out[ ]= y -
x - 2 2 + x2 y + 2 y Cos 2 y + x2 y + x2 y Cos 2 y + x2 y
Question #6
Abs[x - 4]
In[ ]:= f[x_] :=
x-4
In[ ]:= Plot[f[x], {x, - 10, 10}, PlotRange {{- 10, 10}, {- 10, 10}},
PlotStyle {Black, Thin}, GridLines {Range[- 10, 10, 1], None}]
10
Out[ ]=
-10 -5 5 10
-5
-10
We know that a function f(x) is continuous at x=c if f(c) is defined, limxc f (x ) exists and limxc f (x )=f(c).
24 MTH-150 (Exercise Sheets).nb
As f(4) is undefined, f(x) is not continuous at x=4. also from the graph we can see a jump discontinuity at
x=4.
Question #7
x2 - 9
In[ ]:= f[x_] := Piecewise , x ≠ 3, {k, 3}
x+3
x2 - 9
k = Limit , x - 3
x+3
Out[ ]= -6
-10 -5 5 10
Out[ ]=
-5
-10
Which indicates that f(x) behaves like a polynomial function with k=-6.
Question #8
In[ ]:= f[x_] := Piecewisea 9 - x , x < 0, {Sin[b x] + 1, 0 ≤ x ≤ 3}, x - 2 , x > 3
1
Out[ ]= a
3
So if we take a=1/3 and b=0, the function will be continuous over it’s entire domain.
MTH-150 (Exercise Sheets).nb 25
1
In[ ]:= a= ;
3
b = 0;
Text[f[x]]
9- x
x<0
3
1 0≤x≤3
Out[ ]=
-2 + x x>3
0 True
In[ ]:= Plot[f[x], {x, - 10, 10}, PlotRange {{- 10, 10}, {- 10, 10}}]
10
Out[ ]=
-10 -5 5 10
-5
-10
Question #9
2 * Sin[x]
In[ ]:= f[x_] := Piecewise , x < 0, {a, 0}, {b * Cos[x], x > 0}
x
2 * Sin[x]
In[ ]:= a = Limit , x 0
x
Out[ ]= 2
Question #10
In[ ]:= f[x_] := Piecewise3 x2 , x ≤ 1, {a x + b, x > 1}
Question #11
3x+2
In[ ]:= Integrate , x
x2 + 4 x + 2
Out[ ]= 3 2 + 4 x + x2 + 4 Log- 2 - x + 2 + 4 x + x2
Question #12
In[ ]:= f[x_] := Piecewisex2 + 1, - 5 ≤ x < 0, x2 , 0 ≤ x < 2, x2 - 1, 2 ≤ x < 5
25
20
15
Out[ ]=
10
-10 -5 5 10
We know that a function f(x) is continuous at x=c if f(c) is defined, limxc f (x ) exists and limxc f (x )=f(c).
In[ ]:= f[0]
Out[ ]= 0
In[ ]:= If[RHL1 LHL1, Print["limx0 f(x)= ", RHL1], Print["Limit doesn't exist"]]
Limit doesn't exist
Question #13
-1
In[ ]:= Solve2 + Abs[x - 1] x + 7, x
5
Out[ ]= {{x - 5}, {x 5}}
-1
In[ ]:= Plot2 + Abs[x - 1], x + 7, {x, - 5, 5}, Filling {1 {2}}
5
8
Out[ ]= 5
-4 -2 2 4
-1
In[ ]:= Integrate x + 7 - (2 + Abs[x - 1]), {x, - 5, 5}(*Area between the curves*)
5
Out[ ]= 24
Question #14
In[ ]:= f[x_] := x
3
In[ ]:= h[x_] := Piecewise x - 2 , x ≥ 0, {0, True}
In[ ]:= Plot[{f[x], g[x], h[x]}, {x, - 10, 10}, PlotRange {{- 10, 10}, {- 10, 10}},
PlotLegends "Expressions", AxesLabel {X, Y}]
Y
10
f (x)
Out[ ]=
X
g(x)
-10 -5 5 10
h(x)
-5
-10
As g(x)and h(x)are mirror images of each other with respect to the line y=x, which is a property that
inverse functions exhibit; thus g(x)and h(x)are inverse functions.
Question #15
In[ ]:= f[x_] := Sin[x];
g[x_] := Cos[x];
a = 0;
π
b= ;
2
f[b] - f[a] f '[c]
Solve && a ≤ c ≤ b, c
g[b] - g[a] g '[c]
π
Out[ ]= c
4
1.0
0.8
0.6
Out[ ]=
0.4
0.2
Out[ ]=
30 MTH-150 (Exercise Sheets).nb
0.8
0.6
Out[ ]=
0.4
0.2
We have, x=cos(t)and y=sin (t).Therefore, x 2 + y 2 =1 and in this case y = 1 - x 2 is the Cartesian equation
of the curve.
1
In[ ]:= h ' (*Slope of the tangent line at q(c)*)
2
Out[ ]= -1
1 1
In[ ]:= Solve -1 * + r, r(*y-intercept of the tangent line*)
2 2
Out[ ]= r 2
2
Out[ ]=
-4 -2 2 4
-2
-4
1.0
0.8
0.6
Out[ ]=
0.4
0.2
Question #16
In[ ]:= f[x_] := x3 - 4 x + 1
32 MTH-150 (Exercise Sheets).nb
In[ ]:= a = - 4;
b = 4;
f[b] - f[a]
Solvef '[w] , w
b-a
4 4
Out[ ]= w - , w
3 3
40
20
Out[ ]=
-4 -2 2 4
-20
-40
4 4 4
In[ ]:= k1[x_] := f- + f '- * x+
3 3 3
4 4 4
k2[x_] := f + f ' * x-
3 3 3
In[ ]:= Plot[{f[x], k1[x], k2[x]}, {x, - 10, 10}, PlotLegends "Expressions"]
300
200
100
f (x)
Out[ ]= k1(x)
-10 -5 5 10
-100
k2(x)
-200
-300
MTH-150 (Exercise Sheets).nb 33
300
200
100
f (x)
Out[ ]= k1(x)
-10 -5 5 10
-100
k2(x)
-200
-300
This graph shows that over the interval [-4,4], there are two points where the slope of the tangent line is
the same as the slope of the secant line from -4 to 4; which is exactly what MVT stands for when inter-
preted graphically.
Question #17
Rolle’s Theorem: If f(x)is differentiable over the interval [a,b] and continuous at x=a and x=b, given that
f(a)=f(b)=0, there’s at least one point c in the interval such that f’(c)=0.
x
In[ ]:= f[x_] := - x
2
a = 0;
b = 4;
If[f[a] f[b] 0, Print["f(x) satisfies the pre-requisite"],
Print["f(x) doesn't satisfy the pre-requisite"]]
f(x) satisfies the pre-requisite
1.0
0.5
Out[ ]=
-10 -5 5 10
-0.5
Question #18
Intermediate Value Theorem: If f(x) is continuous on [a,b] and k is any number between f(a) & f(b),
then there’s at least one point c in the interval such that f(c)=k.
Out[ ]= 9
Out[ ]= c - 1 || c 2
Question #19
In[ ]:= f[x_] := -x * Sin[x]
a = 0;
b = π;
f[a]
f[b]
Out[ ]= 0
Out[ ]= 0
MTH-150 (Exercise Sheets).nb 35
0.8
0.6
0.4
0.2
Out[ ]=
-10 -5 5 10
-0.2
-0.4
As f(x) is continuous on [0,π] and f(0)=f(π)=0, Rolle’s Theorem applies in this case. Now from the graph
we can see for the point x=0.7854, the slope of the tangent line is zero; and that’s exactly what the
geometrical interpretation of Rolle’s Theorem implies.
Question #20
In[ ]:= f[x_] := x - x2
When the particle is at it’s highest distance from the ground, f’(x)=0
In[ ]:= Solve[f '[x] 0, x]
1
Out[ ]= x
2
Question #21
Rolle’s Theorem: If f(x)is differentiable over the interval [a,b] and continuous at x=a and x=b, given that
f(a)=f(b)=0, there’s at least one point c in the interval such that f’(c)=0.
In[ ]:= a = - 3;
b = 2;
If[f[a] f[b] 0, Print["f(x) satisfies the pre-requisite"],
Print["f(x) doesn't satisfy the pre-requisite"]]
So f(x) will satisfy the hypothesis of Rolle’s Theorem over the interval [-3,2]
In[ ]:= Plot[{f[x], f '[x]}, {x, - 5, 5},
PlotRange {{- 5, 5}, {- 50, 50}}, PlotLegends "Expressions"]
40
20
f (x)
Out[ ]=
-4 -2 2 4 f ′ (x)
-20
-40
(Direct method)
In[ ]:= Reduce[f '[x] 0, x] // N
Out[ ]= x - 3.23494 || x - 0.755051 || x 1.73999
Linear Algebra
Question #1
In[ ]:= A = {{2, - 1, 3}, {0, 4, 5}, {- 2, 1, 4}};
B = {{8, - 3, - 5}, {0, 1, 2}, {4, - 7, 6}};
c = {{0, - 2, 3}, {1, 7, 4}, {3, 5, 9}};
MTH-150 (Exercise Sheets).nb 37
In[ ]:= If[(B + c).A B.A + c.A, Print["Statement is true"], Print["Statement is false"]]
Statement is true
Question #2
In[ ]:= A = IdentityMatrix[3];
Table[A〚i, j〛 = Input[], {i, 1, 3}, {j, 1, 3}];
A // MatrixForm
Out[ ]//MatrixForm=
-3 5 -5
2 -1 6
0 -7 2
In[ ]:= CF = Table(- 1)i+j AM〚i, j〛, {i, 1, 3}, {j, 1, 3}
Out[ ]= {{40, - 4, - 14}, {25, - 6, - 21}, {25, 8, - 7}}
Question #3
In[ ]:= n = Input["Dimensions of the matrix"];
A = IdentityMatrix[n];
Table[A〚i, j〛 = Input[], {i, 1, n}, {j, 1, n}];
A // MatrixForm
Out[ ]//MatrixForm=
3 1 -5 -7
6 10 3 8
1 0 0 -6
-9 3 11 - 20
In[ ]:= IfDet[A] ≠ 0, Print"A-1 = ", Inverse[A] // MatrixForm, Print"A-1 Doesn't Exist"
606 156 395 318
- -
3955 3955 791 3955
706 249 267 253
-
3955 3955 791 3955
A-1 = 872 107 276 66
- -
3955 3955 791 3955
101 26 66 53
- - -
3955 3955 791 3955
Question #4
In[ ]:= n = Input["Dimensions of the matrix"];
A = IdentityMatrix[n];
Table[A〚i, j〛 = Input[], {i, 1, n}, {j, 1, n}];
A // MatrixForm
Out[ ]//MatrixForm=
-5 -3 1
-9 -3 8
- 10 5 - 1
Question #5
In[ ]:= A = {{3, 4, 1, 2, 3}, {5, 7, 1, 3, 4}, {4, 5, 2, 1, 5}, {7, 8, 1, 6, 5}, {3, 7, 5, 4, 6}};
B = {{1}, {1}, {1}, {1}, {1}};
We know that the nullspace of A is formed of such vectors v for which A.v=0.
In[ ]:= LinearSolve[A, {0, 0, 0, 0, 0}] // MatrixForm
Out[ ]//MatrixForm=
0
0
0
0
0
Question #6
The augmented matrix corresponding to the given system is following:
42 MTH-150 (Exercise Sheets).nb
Question #7
Ax Ay Az
Cramer’s rule: x = A
,y= A
, z= A
In[ ]:= Ax = A;
Do[Ax = ReplacePart[Ax , {i, 1} B〚i, 1〛], {i, 1, 3}]
Ax // MatrixForm
Out[ ]//MatrixForm=
3 0 2
-1 2 2
4 -3 3
In[ ]:= Ay = A;
DoAy = ReplacePartAy , {i, 2} B〚i, 1〛, {i, 1, 3}
Ay // MatrixForm
Out[ ]//MatrixForm=
3 3 2
-3 -1 2
2 4 3
MTH-150 (Exercise Sheets).nb 43
In[ ]:= Az = A;
Do[Az = ReplacePart[Az , {i, 3} B〚i, 1〛], {i, 1, 3}]
Az // MatrixForm
Out[ ]//MatrixForm=
3 0 3
-3 2 -1
2 -3 4
Question #8
In[27]:= IdentityMatrix[4] // MatrixForm
Out[27]//MatrixForm=
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
In[32]:= MatrixRank[A]
Out[32]= 2
44 MTH-150 (Exercise Sheets).nb
Question #9
In[49]:= LinearSolve[{{4, 1, 0, 0}, {1, 4, 1, 0}, {0, 1, 4, 1}, {0, 0, 6, 4}}, {5, 6, 5, 5}]
135 65 149 28
Out[49]= , , ,-
134 67 134 67
Question #10
In[61]:= A = {{3, 4, 1, 2}, {5, 7, 1, 3}, {4, 5, 2, 1}, {7, 10, 1, 6}};
B = {{9}, {11}, {8}, {10}};
In[65]:= A1 = A2 = A3 = A4 = A;
Do[A1 = ReplacePart[A1 , {i, 1} B〚i, 1〛], {i, 1, 4}]
Do[A2 = ReplacePart[A2 , {i, 2} B〚i, 1〛], {i, 1, 4}]
Do[A3 = ReplacePart[A3 , {i, 3} B〚i, 1〛], {i, 1, 4}]
Do[A4 = ReplacePart[A4 , {i, 4} B〚i, 1〛], {i, 1, 4}]
Print["A1 =", A1 // MatrixForm, "A2 =",
A2 // MatrixForm, "A3 =", A3 // MatrixForm, "A4 =", A4 // MatrixForm]
9 4 1 2 3 9 1 2 3 4 9 2 3 4 1 9
11 7 1 3 5 11 1 3 5 7 11 3 5 7 1 11
A1 = A = A = A =
8 5 2 1 2 4 8 2 1 3 4 5 8 1 4 4 5 2 8
10 10 1 6 7 10 1 6 7 10 10 6 7 10 1 10
In[71]:= Det[A]
Out[71]= 0
MTH-150 (Exercise Sheets).nb 45
As Det(A)=0, Cramer’s rule doesn’t apply in this case. Also A is not invertible and therefore inverse
method is not applicable as well. In fact, this linear system has no solution.
Question #11
In[74]:= A = {{2, 1, 1}, {1, - 4, 2}, {3, 2, 2}};
IfDet[A] 0, Print["A is not invertible"],
Print"A is invertible, A-1 = ", Inverse[A] // MatrixForm
2 0 -1
2 1 1
A is invertible, A =-1 - -
3 6 2
7 1 3
-
3 6 2
Out[82]=
46 MTH-150 (Exercise Sheets).nb
Question #12
In[83]:= A = IdentityMatrix[3];
Table[A〚i, j〛 = 2 i - j + 1, {i, 1, 3}, {j, 1, 3}];
A // MatrixForm
Out[85]//MatrixForm=
2 1 0
4 3 2
6 5 4
Question #13
In[111]:= A = {{3, 4, 1, 2}, {5, 7, 1, 3}, {4, 5, 2, 1}, {7, 10, 1, 6}};
M = Minors[A];
r1 = Reverse[M〚4〛];
r2 = Reverse[M〚3〛];
r3 = Reverse[M〚2〛];
r4 = Reverse[M〚1〛];
Minor = {r1, r2, r3, r4};
Print["Minors of A:", Minor]
Minors of A:{{12, 8, -4, 0}, {-6, -4, 2, 0}, {-6, -4, 2, 0}, {6, 4, -2, 0}}
Question #14
In[126]:= A = {{1, 1, 1, 1}, {1, 3, - 2, 1}, {2, 0, - 3, 2}, {3, 3, - 3, 3}};
For elements above the main diagonal of Aij , i<j and for elements above the main diagonal of Aij , i>j.
Question #17
In[150]:= A = {{3, 4, 1, 2}, {5, 7, 1, 3}, {4, 5, 2, 1}, {7, 10, 1, 6}};
In[151]:= U = Table[If[i < j, A〚i, j〛, 0], {i, 1, 4}, {j, 1, 4}];
U // MatrixForm
Out[152]//MatrixForm=
0 4 1 2
0 0 1 3
0 0 0 1
0 0 0 0
In[153]:= L = Table[If[i > j, A〚i, j〛, 0], {i, 1, 4}, {j, 1, 4}];
L // MatrixForm
Out[154]//MatrixForm=
0 0 0 0
5 0 0 0
4 5 0 0
7 10 1 0
48 MTH-150 (Exercise Sheets).nb
In[156]:= d = DiagonalMatrix[Diagonal[A]];
d // MatrixForm
Out[157]//MatrixForm=
3 0 0 0
0 7 0 0
0 0 2 0
0 0 0 6
Question #19
In[160]:= A = {{4, 6, 6}, {1, 3, 2}, {- 1, - 4, - 3}};
I3 = IdentityMatrix[3];
Cayley-Hamilton Theorem:
Every square matrix is a root of it’s own characteristics polynomial.
We need to show that -A3 + 4 A2 + A - 4 I3 = 0ij
In[166]:= If[- A.A.A + 4 A.A + A - 4 I3 {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
Print["Theorem is verified"], Print["theorem is not verified"]]
Theorem is verified
-1
In[167]:= inverseA = (A.A - 4 A - I3 );
4
inverseA // MatrixForm
Out[168]//MatrixForm=
1 3 3
4 2 2
1 3 1
-
4 2 2
1 5 3
- -
4 2 2
MTH-150 (Exercise Sheets).nb 49
In[172]:= P = Transpose[Eigenvectors[A]];
In[175]:= Eigenvalues[A]
Out[175]= {4, - 1, 1}