You are on page 1of 49

Basics and Number Theory

Question #1
In[ ]:= n = Input["Any integer"];
a = 2n-1
Out[ ]= 107

In[ ]:= PrimeQ[a]


Out[ ]= True

In[ ]:= divs = Divisors[n];


Print["The divisors of ", n, " are: ", divs]
The divisors of 54 are: {1, 2, 3, 6, 9, 18, 27, 54}

(Sum and product of the divisors)


In[ ]:= sum = 0;
Sum[sum + divs〚i〛, {i, 1, Length[divs]}]
Out[ ]= 120

In[ ]:= product = 1;


Product[product * divs〚i〛, {i, 1, Length[divs]}]
Out[ ]= 8 503 056

(Factorial using loops)


In[ ]:= fact = 1.0;
Do[fact = fact * i, {i, 1, n}]
Print["The factorial of ", n, " is: ", fact]
The factorial of 54 is: 2.30844 × 1071

In[ ]:= fact = 1.0;


For[i = 1, i ≤ n, i ++, fact = fact * i]
Print["The factorial of ", n, " is: ", fact]
The factorial of 54 is: 2.30844 × 1071
2 MTH-150 (Exercise Sheets).nb

In[ ]:= fact = 1.0;


i = 1;
While[i ≤ n, fact = fact * i; i ++]
Print["The factorial of ", n, " is: ", fact]
The factorial of 54 is: 2.30844 × 1071

In[ ]:= Print[n, "th prime number: ", Prime[n]]


54th prime number: 251

In[ ]:= Print[n, "th Fibonacci number: ", Fibonacci[n]]


54th Fibonacci number: 86 267 571 272

In[ ]:= PrimeQ22 n + 1


Out[ ]= False

(Values for which 22 n + 1 is not a prime number


In[ ]:= list = {};
r = Input["Enter the range of the list"];
Fori = 1, i ≤ ∞, i ++, IfPrimeQ22 i + 1  False, AppendTo[list, i];
If[Length[list]  r, Break[]]
Print"The first ", r, " values for which 22 n +1 is not prime: ", list
The first 15 values for which 22 n +1 is not prime:
{3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}

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

In[ ]:= PrimeQ[Factorial[n] + 1]


Out[ ]= False
MTH-150 (Exercise Sheets).nb 3

(Values for which n ! + 1 is not a prime number)


In[ ]:= list = {};
r = Input["Enter the range of the list"];
Do[If[PrimeQ[Factorial[i] + 1]  False, AppendTo[list, i]];
If[Length[list]  r, Break[]], {i, 1, ∞}]
Print["The first ", r, " values for which n!+1 is not prime: ", list]
The first 10 values for which n!+1 is not prime: {4, 5, 6, 7, 8, 9, 10, 12, 13, 14}

(Combination with loop)


n!
We know that nC4 = .
4! (n-4)!

In[ ]:= fact1 = 1;


Do[fact1 = fact1 * i, {i, 1, n}]
fact2 = 1;
Do[fact2 = fact2 * i, {i, 1, 4}]
fact3 = 1;
Do[fact3 = fact3 * i, {i, 1, n - 4}]
fact1
Print"nC4= ", 
fact2 * fact3

nC 4= 316 251

Question #2
(Do loop)
In[ ]:= n = Input["Number of terms"];
elem = 0.0;
sum = 0.0;
1
Doelem = 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

In[ ]:= n = Input["Number of terms"];


elem = 0.0;
product = 1.0;
1
Doelem = elem + ; product = product * elem, {i, 1, n}
2i+1
Print["Product of the first ", n, " terms of the sequence= ", product]
Product of the first 20 terms of the sequence= 2.78915
4 MTH-150 (Exercise Sheets).nb

(For loop)
In[ ]:= n = Input["Number of terms"];
elem = 0.0;
sum = 0.0;
1
Fori = 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

In[ ]:= n = Input["Number of terms"];


elem = 0.0;
product = 1.0;
1
Fori = 1, i ≤ n, i ++, elem = elem + ; product = product * elem
2i+1
Print["Product of the first ", n, " terms of the sequence= ", product]
Product of the first 20 terms of the sequence= 2.78915

Question #3
(Using symbol)
In[ ]:= nom = 1.0;
denom = 2.0;
∞ nom = nom * (i + 1)

i=2
denom = denom * (2 * i)

Sum: Sum does not converge.


∞ 0.25 (1 + i)
Out[ ]= 
i=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)

Sum of the series upto 10 terms

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
Donom = 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

In[ ]:= n = Input[] + 1;


nom = 1.0;
denom = 2.0;
sum = 0.0;
Fori = 2, i ≤ n, i ++, nom = nom * (i + 1);
denom = denom * (2 * i);
nom
sum = sum + 
denom
Print["Sum of the series upto ", n, " terms= ", sum]
Sum of the series upto 10 terms= 0.993652
6 MTH-150 (Exercise Sheets).nb

Question #4
(Sum)
In[ ]:= n = Input["Number of terms(Enter odd integer≥15)"];
elem = 0.0;
sum = 0.0;
i
Doelem = 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

In[ ]:= n = Input["Number of terms(Enter odd integer≥15)"];


elem = 0.0;
sum = 0.0;
i
Fori = 1, i ≤ n, i ++, elem = elem + ; sum = sum + elem
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
Doelem = 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

In[ ]:= n = Input["Number of terms(Enter odd integer≥15)"];


elem = 0.0;
product = 1.0;
i
Fori = 1, i ≤ n, i ++, elem = elem + ; product = product * elem
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
MTH-150 (Exercise Sheets).nb 7

Question #5
In[ ]:= sum = 0.0;
elem = 0.0;
1
Fori = 1, i ≤ 20, i ++, elem = elem + ; sum = sum + elem
i
Print["Sum of the sequence= ", sum]
Sum of the sequence= 55.5525

In[ ]:= product = 1.0;


elem = 0.0;
1
Fori = 1, i ≤ 20, i ++, elem = elem +
; product = product * elem
i
Print["Product of the sequence= ", product]
Product of the sequence= 3.12157 × 108

Question #6
In[ ]:= list1 = RandomInteger[{- 10, 10}, 10]
Out[ ]= {4, 1, - 6, - 7, - 6, - 2, 7, 6, - 4, - 7}

In[ ]:= list2 = list1 ^ 2


Out[ ]= {16, 1, 36, 49, 36, 4, 49, 36, 16, 49}

In[ ]:= list3 = {};


DoAppendTolist3, list1〚i〛3 , {i, 1, Length[list1]}
Print[list3]
{64, 1, -216, -343, -216, -8, 343, 216, -64, -343}

In[ ]:= TableForm[{list1, list2, list3},


TableHeadings  {{"Random integers", "Square", "Cube"}, None}]
Out[ ]//TableForm=
Random integers 4 1 -6 -7 -6 -2 7 6 -4 -7
Square 16 1 36 49 36 4 49 36 16 49
Cube 64 1 - 216 - 343 - 216 -8 343 216 - 64 - 343

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

In[ ]:= list = {};


Do[If[Mod[intlist〚i〛, 5] ≠ 0, AppendTo[list, intlist〚i〛]], {i, 1, Length[intlist]}]
Print["Elements of intlist not divisible by 5: ", list]
Elements of intlist not divisible by 5: {49, 48, 47, 46, 44, 43, 42, 41, 39, 38, 37, 36, 34, 33, 32,
31, 29, 28, 27, 26, 24, 23, 22, 21, 19, 18, 17, 16, 14, 13, 12, 11, 9, 8, 7, 6, 4, 3, 2, 1}

In[ ]:= Grid[Partition[list, 4]]


49 48 47 46
44 43 42 41
39 38 37 36
34 33 32 31
29 28 27 26
Out[ ]=
24 23 22 21
19 18 17 16
14 13 12 11
9 8 7 6
4 3 2 1

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}

In[ ]:= list2 = {};


Do[If[Mod[list1〚i〛, 7]  0, If[Mod[list1〚i〛, 3] ≠ 0, AppendTo[list2, list1〚i〛]]],
{i, 1, Length[list1]}]
Print[list2]
{7, 14}

In[ ]:= list3 = {};


Do[If[PrimeQ[list2〚i〛]  True, AppendTo[list3, list2〚i〛]], {i, 1, Length[list2]}]
Print[list3]
{7}

In[ ]:= Union[list1, list2]


Out[ ]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}

In[ ]:= Intersection[list1, list2]


Out[ ]= {7, 14}
MTH-150 (Exercise Sheets).nb 9

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}

In[ ]:= MeanDeviation[FIB21] // N


Out[ ]= 1833.35

In[ ]:= StandardDeviation[FIB21] // N


Out[ ]= 2781.74

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}

In[ ]:= FIB30〚19〛


Out[ ]= 4181

In[ ]:= FIB30〚23〛


Out[ ]= 28 657

In[ ]:= Mean[FIB30] // N


Out[ ]= 72 610.3

In[ ]:= MemberQ[FIB30, 33]


Out[ ]= False

Question #11
In[ ]:= f0 = 1;
f1 = 1;
f[n_] := f[n - 1] + f[n - 2]

In[ ]:= fibs = {};


AppendTo[fibs, f0 ];
AppendTo[fibs, f1 ];
Do[fi = fi-1 + fi-2 ; AppendTo[fibs, fi ], {i, 2, 299}]
Print["First 300 values of the sequence: ", fibs]
10 MTH-150 (Exercise Sheets).nb

In[ ]:= PnFIB = {};


Do[If[PrimeQ[fibs〚i〛]  True, AppendTo[PnFIB, fibs〚i〛]], {i, 1, Length[fibs]}]
Print["Prime numbers from the sequence: ", PnFIB]
Prime numbers from the sequence:
{2, 3, 5, 13, 89, 233, 1597, 28 657, 514 229, 433 494 437, 2 971 215 073,
99 194 853 094 755 497, 1 066 340 417 491 710 595 814 572 169, 19 134 702 400 093 278 081 449 423 917}

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}

In[ ]:= perfects = {};


Do[If[DivisorSigma[1, list〚i〛]  2 * list〚i〛, AppendTo[perfects, list〚i〛]],
{i, 1, Length[list]}]
Print["Perfect numbers less than 500: ", perfects]
Perfect numbers less than 500: {6, 28, 496}
MTH-150 (Exercise Sheets).nb 11

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[ ]:= B = {};


Do[If[PrimeQ[i]  True, AppendTo[B, i]], {i, 1, n - 70}]
Print["Prime numbers less than (n-70): ", B]
Prime numbers less than (n-70): {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}

In[ ]:= c = {};


For[i = 1, i ≤ ∞, i ++, If[Fibonacci[i] < n - 40, AppendTo[c, Fibonacci[i]], Break[]]]
Print["Fibonacci numbers less than (n-40): ", c]
Fibonacci numbers less than (n-40): {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}

In[ ]:= d = {};


Do[If[DivisorSigma[1, i]  2 * i, AppendTo[d, i]], {i, 1, 5 n}]
Print["Perfect numbers less than 5n: ", d]
Perfect numbers less than 5n: {6, 28, 496}

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 = Tablei * , {i, 0, 60, 5};
180
body = Table[{deg〚i〛, rad〚i〛}, {i, 1, Length[deg]}];
TableFormbody, TableHeadings  None, "Degree(°)", "Radian( c )" 
Out[ ]//TableForm=
Degree(°) Radian(c )
0 0
π
5
36
π
10
18
π
15
12
π
20
9

25
36
π
30
6

35
36

40
9
π
45
4

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}

In[ ]:= perfect = {};


Do[If[DivisorSigma[1, list〚i〛]  2 * list〚i〛, AppendTo[perfect, list〚i〛]],
{i, 1, Length[list]}];
Print["perfect numbers from the list: ", perfect]
perfect numbers from the list: {28}

In[ ]:= Print["# of perfect numbers in the list: ", Length[perfect]]


# of perfect numbers in the list: 1
MTH-150 (Exercise Sheets).nb 13

Calculus
Question #1
In[ ]:= f[x_] := (x - 1) (x - 2) (x - 3)

In[ ]:= g[x_] := Piecewisex2 , x ≥ 0, {x - 1, - 5 ≤ x < 0}, {- 8, x < - 5}

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

In[ ]:= Plot[f[x], {x, - 10, 10}, PlotStyle  Directive[Hue[Red], Thickness[Medium]],


PlotRange  {{- 10, 10}, {- 10, 10}}, AxesLabel  {X, Y}, GridLines  Automatic]
Y
10

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

In[ ]:= Show[%8, %16]


Y
10

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

In[ ]:= Dt[f[x], {x, 2}] // Simplify


Out[ ]= 6 (- 2 + x)

In[ ]:= Plot[{f[x], f '[x], f ''[x]}, {x, - 10, 10},


PlotLegends  "Expressions", PlotRange  {{- 5, 5}, {- 10, 10}}]
10

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}}

In[ ]:= FindMaximum[f[x], {x, 1.5}]


Out[ ]= {0.3849, {x  1.42265}}
16 MTH-150 (Exercise Sheets).nb

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

In[ ]:= Show[%32, %58]


10

f (x)
Out[ ]= f ′ (x)
-4 -2 2 4
f ′′ (x)

-5

-10

In[ ]:= RHL = Limit[g[x], x  - 2, Direction  - 1];


LHL = Limit[g[x], x  - 2, Direction  + 1];
If[LHL  RHL, Print["Limiting value= ", RHL], Print["Limit doesn't exist"]]
Limiting value= -3

In[ ]:= RHL = Limit[g[x], x  0, Direction  - 1];


LHL = Limit[g[x], x  0, Direction  + 1];
If[LHL  RHL, Print["Limiting value= ", RHL], Print["Limit doesn't exist"]]
Limit doesn't exist

In[ ]:= RHL = Limit[g[x], x  2, Direction  - 1];


LHL = Limit[g[x], x  2, Direction  + 1];
If[LHL  RHL, Print["Limiting value= ", RHL], Print["Limit doesn't exist"]]
Limiting value= 4
MTH-150 (Exercise Sheets).nb 17

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

In[ ]:= Dom = Reduce[5 - x ≥ 0 && x - 5 ≥ 0, x]


Out[ ]= x5

In[ ]:= Ran = 5-5 + 5 - 5 + 1.0(*Taking x=5*)


Out[ ]= 1.

1
In[ ]:= Plot , {x, - 10, 10}
Abs9 - x2 
0.5

0.4

0.3

Out[ ]=

0.2

0.1

-10 -5 5 10

In[ ]:= Dom = Reduce9 - x2 > 0 || 9 - x2 < 0, x


Out[ ]= x < - 3 || - 3 < x < 3 || x > 3

In[ ]:= Ran = x > 0;


18 MTH-150 (Exercise Sheets).nb

In[ ]:= Plot 15 - 13 x - 3 x2 + x3 , {x, - 10, 10}


25

20

15

Out[ ]=

10

-10 -5 5 10

In[ ]:= Dom = Reduce15 - 13 x - 3 x2 + x3 ≥ 0, x


Out[ ]= - 3 ≤ x ≤ 1 || x ≥ 5

In[ ]:= Ran = x ≥ 0;

In[ ]:= PolarPlot[3 + 5 * Sin[θ], {θ, 0, 2 π}]


8

4
Out[ ]=

-4 -2 2 4
MTH-150 (Exercise Sheets).nb 19

In[ ]:= PolarPlot[5 + 5 * Sin[θ], {θ, 0, 2 π}]


10

Out[ ]=
4

-6 -4 -2 2 4 6

In[ ]:= PolarPlot[5 + 3 * Sin[θ], {θ, 0, 2 π}]


8

Out[ ]=

-4 -2 2 4

-2
20 MTH-150 (Exercise Sheets).nb

In[ ]:= ParametricPlot[{t - Sin[t], 1 - Cos[t]}, {t, 0, π}]

2.0

1.5

Out[ ]= 1.0

0.5

0.5 1.0 1.5 2.0 2.5 3.0

Question #3
In[ ]:= f[x_] := Cos[x]

In[ ]:= g[x_] := Sin[x]

In[ ]:= Plot[{f[x], g[x]}, {x, - 7, 7},


PlotLegends  "Expressions", PlotRange  All, AxesLabel  {X, Y}]
Y

2.5

2.0

f (x)
Out[ ]=
1.5 g(x)

1.0

0.5
X
-6 -4 -2 2 4 6

(Intersection points in the graph)


In[ ]:= FindRoot[f[x]  g[x], {x, - 6}]
FindRoot[f[x]  g[x], {x, - 3}]
FindRoot[f[x]  g[x], {x, 3}]
Out[ ]= {x  - 5.49779}

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

In[ ]:= Show[%173, %187]


Y

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]

In[ ]:= list1 = Range[- 5, 5, 0.1];


list2 = Table[f[i], {i, - 5, 5, 0.1}];
TableForm[{list1, list2}, TableHeadings  {{"x", "f(x)"}, None}]
22 MTH-150 (Exercise Sheets).nb

In[ ]:= ListPlot[Table[{list1〚i〛, list2〚i〛}, {i, 1, Length[list1]}]]

Out[ ]=

-4 -2 2 4

-5

In[ ]:= Plot[f[x], {x, - 5, 5}, PlotStyle  Red]


8

2
Out[ ]=

-4 -2 2 4

-2

-4

-6

In[ ]:= Show[%227, %226]


8

2
Out[ ]=

-4 -2 2 4

-2

-4

-6
MTH-150 (Exercise Sheets).nb 23

Question #5
In[ ]:= DtLog[x y]  Sin x2 y + 2 y , x

y + x Dt[y, x] Cos 2 y + x2 y  2 x y + 2 Dt[y, x] + x2 Dt[y, x]


Out[ ]= 
xy 2 2 y + x2 y

y + x y' Cos 2 y + x2 y  2 x y + 2 y ' + x2 y '


In[ ]:= Solve  , y '
xy 2 2 y + x2 y

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 

In[ ]:= Dt[Sin[Log[x y]]  x y, x]


Cos[Log[x y]] (y + x Dt[y, x])
Out[ ]=  y + x Dt[y, x]
xy

Cos[Log[x y]] (y + x y ')


In[ ]:= Solve  y + x y ', y '
xy
y
Out[ ]= y′  - 
x

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, limxc f (x ) exists and limxc f (x )=f(c).
24 MTH-150 (Exercise Sheets).nb

In[ ]:= f[4]


Out[ ]= Indeterminate

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

In[ ]:= Plot[f[x], {x, - 10, 10}]

-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_] := Piecewisea 9 - x , x < 0, {Sin[b x] + 1, 0 ≤ x ≤ 3},  x - 2 , x > 3

In[ ]:= Solvea 9 - 0  Sin[0 * x] + 1, a(*In order to ensure cotinuity at x=0*)

1
Out[ ]= a  
3

In[ ]:= FindInstanceSin[b * 3] + 1  3 - 2 , b(*In order to ensure cotinuity at x=3*)

Out[ ]= {{b  0}}

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

In[ ]:= Reduce[a  b * Cos[0], b]


Out[ ]= b2

Question #10
In[ ]:= f[x_] := Piecewise3 x2 , x ≤ 1, {a x + b, x > 1}

In[ ]:= D3 x2 , x


Out[ ]= 6x
26 MTH-150 (Exercise Sheets).nb

In[ ]:= D[a * x + b, x]


Out[ ]= a

In[ ]:= Solve[6 * 1  a, a](*At x=1,both derivatives must be the same*)


Out[ ]= {{a  6}}

So if we take a=6 and b= any constant, f(x) will be differentiable at 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 

In[ ]:= Integratex2 1 - x2 , {x, 0, 1}


π
Out[ ]=
16

Question #12
In[ ]:= f[x_] := Piecewisex2 + 1, - 5 ≤ x < 0, x2 , 0 ≤ x < 2, x2 - 1, 2 ≤ x < 5

In[ ]:= Plot[f[x], {x, - 10, 10}]

25

20

15
Out[ ]=

10

-10 -5 5 10

In[ ]:= RHL1 = Limit[f[x], x  0, Direction  - 1]


Out[ ]= 0

In[ ]:= LHL1 = Limit[f[x], x  0, Direction  1]


Out[ ]= 1
MTH-150 (Exercise Sheets).nb 27

In[ ]:= RHL2 = Limit[f[x], x  2, Direction  - 1]


Out[ ]= 3

In[ ]:= LHL2 = Limit[f[x], x  2, Direction  1]


Out[ ]= 4

We know that a function f(x) is continuous at x=c if f(c) is defined, limxc f (x ) exists and limxc f (x )=f(c).
In[ ]:= f[0]
Out[ ]= 0

In[ ]:= If[RHL1  LHL1, Print["limx0 f(x)= ", RHL1], Print["Limit doesn't exist"]]
Limit doesn't exist

Question #13
-1
In[ ]:= Solve2 + Abs[x - 1]  x + 7, x
5
Out[ ]= {{x  - 5}, {x  5}}

-1
In[ ]:= Plot2 + 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

In[ ]:= g[x_] := Piecewisex3 + 2, x ≥ 0, {0, True}


28 MTH-150 (Exercise Sheets).nb

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

In[ ]:= q[t_] := {g[t], f[t]}


MTH-150 (Exercise Sheets).nb 29

In[ ]:= para = ParametricPlot[q[t], {t, a, b}]

1.0

0.8

0.6

Out[ ]=

0.4

0.2

0.2 0.4 0.6 0.8 1.0

In[ ]:= points = ListPlot[{q[a], q[b], q[c]}, Epilog 


{PointSize[0.02], Point[{q[a], q[b], q[c]}, VertexColors  {Pink, Green, Purple}]}]

Out[ ]=
30 MTH-150 (Exercise Sheets).nb

In[ ]:= line = ListLinePlot[{q[a], q[b]}]


1.0

0.8

0.6

Out[ ]=

0.4

0.2

0.2 0.4 0.6 0.8 1.0

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.

In[ ]:= h[x_] := 1 - x2

In[ ]:= q[c]


1 1
Out[ ]=  , 
2 2

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 

So the equation of the tangent line is y = 2 -x


MTH-150 (Exercise Sheets).nb 31

In[ ]:= tangent = Ploty = 2 - x, {x, - 5, 5}

2
Out[ ]=

-4 -2 2 4

-2

-4

In[ ]:= Show[para, points, line, tangent]

1.0

0.8

0.6

Out[ ]=

0.4

0.2

0.2 0.4 0.6 0.8 1.0

Question #16
In[ ]:= f[x_] := x3 - 4 x + 1
32 MTH-150 (Exercise Sheets).nb

In[ ]:= a = - 4;
b = 4;
f[b] - f[a]
Solvef '[w]  , w
b-a
4 4
Out[ ]= w  - , w  
3 3

In[ ]:= ListLinePlot[{{a, f[a]}, {b, f[b]}}, PlotStyle  Green]

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

In[ ]:= Show[%84, %86]

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

In[ ]:= Reduce[f '[c]  0, c]


Out[ ]= c1
34 MTH-150 (Exercise Sheets).nb

In[ ]:= Plot[{f[x], f[1]}, {x, - 10, 10}]

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.

In[ ]:= f[x_] := x3 - 3 x2 + 9


a = 0;
b = 3;
f[a]
f[b]
Out[ ]= 0

Out[ ]= 9

In[ ]:= k = Input["Any number between 0 and 9"]


Reduce[f[c]  k, c]
Out[ ]= 5

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

In[ ]:= FindRoot[f '[c]  0, {c, 0}]


Out[ ]= {c  0.785398}

In[ ]:= Plot[{f[x], f[0.7854]}, {x, - 10, 10}]

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

In[ ]:= MaxHeight = f[0.5];


Print["Highest distance of the particle from the ground= ", MaxHeight, " unit"]
Highest distance of the particle from the ground= 0.25 unit

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[ ]:= f[x_] := x4 + 3 x3 - 9 x2 - 17 x + 30

In[ ]:= Reduce[f[x]  0, x]


Out[ ]= x  - 3 || x  2 || x  - 1 - 6 || x  - 1 + 6
36 MTH-150 (Exercise Sheets).nb

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"]]

f(x) satisfies 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

In[ ]:= FindRoot[f '[c], {c, - 1}]


Out[ ]= {c  - 0.755051}

In[ ]:= FindRoot[f '[c], {c, 1.7}]


Out[ ]= {c  1.73999}

(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[A + (B + c)  (A + B) + c, Print["Statement is true"], Print["Statement is false"]]


Statement is true

In[ ]:= If[A.(B.c)  (A.B).c, Print["Statement is true"], Print["Statement is false"]]


Statement is true

In[ ]:= If[A.(B - c)  A.B - A.c, Print["Statement is true"], Print["Statement is false"]]


Statement is true

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[ ]:= M = Minors[A](*Not the convention we're used to*)


Out[ ]= {{- 7, - 8, 25}, {21, - 6, - 25}, {- 14, 4, 40}}

In[ ]:= R1 = Reverse[M〚3〛];


R2 = Reverse[M〚2〛];
R3 = Reverse[M〚1〛];
AM = {R1, R2, R3}(*In Conventional format*)
Out[ ]= {{40, 4, - 14}, {- 25, - 6, 21}, {25, - 8, - 7}}

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}}

In[ ]:= Transpose[A] // MatrixForm


Out[ ]//MatrixForm=
-3 2 0
5 -1 -7
-5 6 2

In[ ]:= MatrixRank[A]


Out[ ]= 3

In[ ]:= Det[A]


Out[ ]= - 70
38 MTH-150 (Exercise Sheets).nb

In[ ]:= Det[Inverse[A]]


1
Out[ ]= -
70

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[ ]:= Dimensions[A]


Out[ ]= {4, 4}

In[ ]:= Det[A]


Out[ ]= - 3955

In[ ]:= Diagonal[A]


Out[ ]= {3, 10, 0, - 20}

In[ ]:= Tr[A]


Out[ ]= -7

In[ ]:= IfDet[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

In[ ]:= Transpose[A] // MatrixForm


Out[ ]//MatrixForm=
3 6 1 -9
1 10 0 3
-5 3 0 11
-7 8 - 6 - 20
MTH-150 (Exercise Sheets).nb 39

In[ ]:= MatrixPower[A, 3] + MatrixPower[A, 2] + A // MatrixForm


Out[ ]//MatrixForm=
- 1255 457 1244 - 3031
2170 1029 - 1104 3117
- 961 209 836 - 2262
- 3470 1019 3449 - 8609

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

In[ ]:= n = Input["Dimensions of the matrix"];


B = IdentityMatrix[n];
Table[B〚i, j〛 = Input[], {i, 1, n}, {j, 1, n}];
B // MatrixForm
Out[ ]//MatrixForm=
2 2 5
-2 -1 3
11 - 13 - 1

In[ ]:= n = Input["Dimensions of the matrix"];


c = IdentityMatrix[n];
Table[c〚i, j〛 = Input[], {i, 1, n}, {j, 1, n}];
c // MatrixForm
Out[ ]//MatrixForm=
2 -9 -1
3 0 -9
0 1 7

In[ ]:= If[A + B  B + A, Print["Statement is true"], Print["Statement is false"]]


Statement is true

In[ ]:= If[k (A + B)  k A + k B, Print["Statement is true"], Print["Statement is false"]]


Statement is true

In[ ]:= If[A.(B + c)  A.B + A.c, Print["Statement is true"], Print["Statement is false"]]


Statement is true

In[ ]:= If[Inverse[A.B]  Inverse[A].Inverse[B],


Print["Statement is true"], Print["Statement is false"]]
Statement is false
40 MTH-150 (Exercise Sheets).nb

In[ ]:= If[Inverse[A.B]  Inverse[B].Inverse[A],


Print["Statement is true"], Print["Statement is false"]]
Statement is true

In[ ]:= If[Transpose[A.B]  Transpose[A].Transpose[B],


Print["Statement is true"], Print["Statement is false"]]
Statement is false

In[ ]:= If[Transpose[A.B]  Transpose[B].Transpose[A],


Print["Statement is true"], Print["Statement is false"]]
Statement is true

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}};

In[ ]:= LinearSolve[A, B] // MatrixForm


Out[ ]//MatrixForm=
25
-
12
1
2
9
-
4
1
2
13
6

In[ ]:= Inverse[A] // MatrixForm


Out[ ]//MatrixForm=
65 7 17 7 1
-
12 12 12 6 6
1 1 1
1 - - 0
2 2 2
23 3 5 1
- 1
4 4 4 2
3 1 1
- - 0 0
2 2 2
16 7 5 5 1
- - - -
3 6 6 6 3

In[ ]:= If[Inverse[A].A  IdentityMatrix[5], Print["Verified"], Print["Not verified"]]


Verified

We have, AX=B  A-1 A X = A-1 B  X = A-1 B


MTH-150 (Exercise Sheets).nb 41

In[ ]:= X = Inverse[A].B;


X // MatrixForm
Out[ ]//MatrixForm=
25
-
12
1
2
9
-
4
1
2
13
6

In[ ]:= AugMat = Join[A, B, 2];


RowReduce[AugMat] // MatrixForm
Out[ ]//MatrixForm=
25
1 0 0 0 0 -
12
1
0 1 0 0 0
2
9
0 0 1 0 0 -
4
1
0 0 0 1 0
2
13
0 0 0 0 1
6

In[ ]:= rref = RowReduce[AugMat];


sol = {};
Do[AppendTo[sol, rref〚i, 6〛], {i, 1, 5}]
Print["X=", sol // MatrixForm]
25
-
12
1
2
9
X= -
4
1
2
13
6

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

In[ ]:= AugMat = {{- 2, 1, - 2, 4}, {2, - 4, - 2, - 4}, {1, - 4, - 2, 3}};


AugMat // MatrixForm
Out[ ]//MatrixForm=
-2 1 -2 4
2 -4 -2 -4
1 -4 -2 3

In[ ]:= rref = RowReduce[AugMat];


rref // MatrixForm
Out[ ]//MatrixForm=
1 0 0 -7
0 1 0 -4
0 0 1 3

In[ ]:= sol = {};


Do[AppendTo[sol, rref〚i, 4〛], {i, 1, 3}]
x
Print"y =", sol // MatrixForm
z
x -7
y = -4
z 3

Question #7
Ax Ay Az
Cramer’s rule: x = A
,y= A
, z= A

In[ ]:= A = {{3, 0, 2}, {- 3, 2, 2}, {2, - 3, 3}};


B = {{3}, {- 1}, {4}};

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;
DoAy = ReplacePartAy , {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

Det[Ax ] DetAy  Det[Az ]


In[ ]:= Print"x=", , ", y=", , ", z=", 
Det[A] Det[A] Det[A]
13 7 15
x= , y=- , z=
23 23 23

Inverse matrix method:


We have, AX=B  A-1 A X = A-1 B  X = A-1 B

In[ ]:= X = Inverse[A].B;


X // MatrixForm
Out[ ]//MatrixForm=
13
23
7
-
23
15
23

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[29]:= DiagonalMatrix[{- 2, 6, 3}] // MatrixForm


Out[29]//MatrixForm=
-2 0 0
0 6 0
0 0 3

In[30]:= A = {{2, 3, 5}, {- 4, 2, 3}};


B = {{0}, {0}};

In[32]:= MatrixRank[A]
Out[32]= 2
44 MTH-150 (Exercise Sheets).nb

In[36]:= AugMat = Join[A, B, 2];


RowReduce[AugMat] // MatrixForm
Out[37]//MatrixForm=
1
1 0 0
16
13
0 1 0
8

In[38]:= LinearSolve[A, B] // MatrixForm


Out[38]//MatrixForm=
0
0
0

In[47]:= Nullity = Length[NullSpace[A]]


Out[47]= 1

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

In[50]:= LinearSolve[{{4, 1, - 1}, {- 1, 3, 1}, {2, 2, 2}}, {5, - 4, 1}]


10 23 3
Out[50]=  ,- ,- 
7 28 28

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}};
IfDet[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

In[79]:= B = {7, 2, 13};


X = Inverse[A].B;
x
Print"y =", X // MatrixForm
z
1
x 3
y = 2
z 7
2

In[82]:= ContourPlot3D[{2 x + y + z  7, x - 4 y + 2 z  2, 3 x + 2 y + 2 z  13},


{x, - 10, 10}, {y, - 10, 10}, {z, - 10, 10}]

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

In[86]:= IfDet[A]  0, Print["A is not invertible"],


Print"A is invertible & A-1 =", Inverse[A] // MatrixForm
A is not invertible

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}}

In[121]:= CF = Table(- 1)i+j Minor〚i, j〛, {i, 1, 4}, {j, 1, 4};


Print["Cofactors of A:", CF]
Cofactors of A:{{12, -8, -4, 0}, {6, -4, -2, 0}, {-6, 4, 2, 0}, {-6, 4, 2, 0}}

In[123]:= IfDet[A]  0, Print["A is not invertible"],


Print"A is invertible & A-1 =", Inverse[A] // MatrixForm
A is not invertible

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.

In[127]:= list1 = {};


Do[Do[If[i < j, AppendTo[list1, A〚i, j〛]], {j, 1, 4}], {i, 1, 4}]
MTH-150 (Exercise Sheets).nb 47

In[131]:= Sum[list1〚i〛, {i, 1, Length[list1]}]


Out[131]= 4

In[132]:= Product[list1〚i〛, {i, 1, Length[list1]}]


Out[132]= -4

In[136]:= list2 = {};


Do[Do[If[i > j, AppendTo[list2, A〚i, j〛]], {j, 1, 4}], {i, 1, 4}]

In[139]:= Sum[list2〚i〛, {i, 1, Length[list2]}]


Out[139]= 6

In[140]:= Product[list2〚i〛, {i, 1, Length[list2]}]


Out[140]= 0

In[142]:= list3 = Diagonal[A];


Sum[list3〚i〛, {i, 1, Length[list3]}]
Out[143]= 4

In[144]:= Product[list3〚i〛, {i, 1, Length[list3]}]


Out[144]= - 27

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

In[158]:= If[A  U + L + d, Print["Verified"], Print["Not verified"]]


Verified

Question #19
In[160]:= A = {{4, 6, 6}, {1, 3, 2}, {- 1, - 4, - 3}};
I3 = IdentityMatrix[3];

In[162]:= Det[A - λ I3 ](*Characteristics polynomial*)


Out[162]= - 4 + λ + 4 λ2 - λ3

In[163]:= Reduce[Det[A - λ I3 ]  0, λ](*Eigenvalues*)


Out[163]= λ  - 1 || λ  1 || λ  4

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

From Cayley-Hamilton theorem, we have


-4 I3 + A + 4 A2 - A3 =0
A-1 (-4 I3 ) + A-1 A + A-1 4 A2  - A-1 A3  =0
 -4 A-1 + I3 + 4 A - A2 = 0
1
 A-1 = - A2 - 4 A - I3 
4

-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[169]:= If[inverseA.A  I3 , Print["Verified"], Print["Not verified"]]


Verified

In[172]:= P = Transpose[Eigenvectors[A]];

In[174]:= Inverse[P] // MatrixForm


Out[174]//MatrixForm=
1 2 2
- - -
3 5 5
1 1
0
5 5
1
-1 0
3

In[175]:= Eigenvalues[A]
Out[175]= {4, - 1, 1}

In[176]:= If[Inverse[P].A.P  DiagonalMatrix[{4, - 1, 1}], Print["Verified"], Print["Not verified"]]


Verified

You might also like