0% found this document useful (0 votes)
9 views15 pages

All-Solutions 250422 141738

The document contains various computational examples using loops (Do, For, While) to calculate sums and analyze prime and Fibonacci numbers. It also includes graphical representations of data, solutions to differential equations, and calculations involving eigenvalues and eigenvectors. Additionally, it covers topics such as limits, areas under curves, and solving systems of equations.

Uploaded by

ekarasspranto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views15 pages

All-Solutions 250422 141738

The document contains various computational examples using loops (Do, For, While) to calculate sums and analyze prime and Fibonacci numbers. It also includes graphical representations of data, solutions to differential equations, and calculations involving eigenvalues and eigenvectors. Additionally, it covers topics such as limits, areas under curves, and solving systems of equations.

Uploaded by

ekarasspranto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

I n [ ] : = (*1a: Using Do loop*)

sum = 0;
1
Dosum = sum + , {i, 1, 100}, {j, 1, i};
j
N[sum]
O u t [ ] =
423.925

(*1a: Using For loop*)

1
I n [ ] : = For sum = 0; i = 1, i ≤ 100, i = i + 1, Forj = 1, j ≤ i, j = j + 1, sum = sum + 
j
sum;
sum // N
O u t [ ] =
423.925

(*1a: Using While loop*)

I n [ ] : = sum = 0;
i = 1;
1
Whilei ≤ 100, j = 1; Whilej ≤ i, sum = sum + ; j ++;
j
i ++
sum;
sum // N
O u t [ ] =
423.925

(*1b: UPrime & Fibonacci*)

Clear[p, k, f, i, c];
2 All solutions.nb

I n [ ] : = p = {};
k = 1;
While[Prime[k] < 1500, p = Append[p, Prime[k]]; k ++]
f = {};
i = 1;
While[Fibonacci[i] < 1500, f = Append[f, Fibonacci[i]]; i ++]
Length[p]
Length[f]
Intersection[p, f]
O u t [ ] =
239
O u t [ ] =
16
O u t [ ] =
{2, 3, 5, 13, 89, 233}

I n [ ] : = {2, 3, 5, 13, 89, 233}


Length[%]
O u t [ ] =
{2, 3, 5, 13, 89, 233}
O u t [ ] =
6

(*2(A)*)
All solutions.nb 3

I n [ ] : = overs = Range[1, 10];


runs = {9, 3, 5, 7, 12, 10, 10, 7, 11, 18};
BarChart[runs, ChartLabels  Placed[overs, Below],
ChartStyle  "Pastel", BarOrigin  Bottom, AxesLabel  {"Overs", "Runs"},
PlotLabel  "Runs Scored per Over", ImageSize  Large]
O u t [ ] =
Runs Scored per Over
Runs

15

10

0 Overs
1 2 3 4 5 6 7 8 9 10

(*2(b)*)

I n [ ] : = eqn = x ^ 2 - 5 x y + 4 y ^ 2 + x + 2 y - 3  0;
a = 1; h = -5 / 2; b = 4; g = 1 / 2; f = 1; c = -3;

del = a * b * c + 2 * f * g * h - a * f ^ 2 - b * g ^ 2 - c * h ^ 2;
del  0
O u t [ ] =
False

(*3(a)*)
4 All solutions.nb

I n [ ] : = f[x_] := x3 + 5 * x + 3
Plot[{f[x], f '[x], f ''[x]}, {x, -10, 10},
PlotStyle  {RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[0, 0, 1]},
PlotLegends  {"f[x]", "f'[x]", "f''[x]"}]
SetDelayed: Tag Integer in 1[x_] is Protected.
O u t [ ] =
$Failed
O u t [ ] =

1.0

0.5

f[x]
f'[x]
-10 -5 5 10
f''[x]
-0.5

-1.0

(*3(b)*)
All solutions.nb 5

I n [ ] : = f = x2 + y2  1;
g = y2  1 - x;
ContourPlot[{f, g}, {x, -2, 2}, {y, -2, 2}]
Solve[{f, g}, {x, y}]
Solve[f, y]
Solve[g, y]
O u t [ ] =
2

-1

-2
-2 -1 0 1 2

O u t [ ] =
{{x  0, y  -1}, {x  1, y  0}, {x  0, y  1}}
O u t [ ] =

y  - 1 - x2 , y  1 - x2 

O u t [ ] =

y  - 1 - x , y  1 - x 

* The area of portion of the circle outside the parabola *)

1
I n [ ] : = 2  1 - x2 - 1 - x  x
0
O u t [ ] =
2 π
2 - +
3 4

(*The required area *)


6 All solutions.nb

2 π
I n [ ] : = π-2 - + // Simplify
3 4
O u t [ ] =
1
(8 + 3 π)
6

(*4(a)*)

I n [ ] : = f[x_] = 3 x3 + 4 x2 - x + 2;
f1[x_] = f[x] / 3
O u t [ ] =
1
2 - x + 4 x2 + 3 x3 
3

I n [ ] : = f1[x] /. x  (y - 4 / 9) // Simplify
O u t [ ] =
722 25 y
- + y3
729 27

(*4(b)*)

I n [ ] : = u = {2, 3, 4};
v = {1, 0, 0};
w = {0, 1, 0};
p = {0, 0, 1};
u.v
angle1 = ArcCos  // N
u.u v.v
O u t [ ] =
1.19029

u.w
I n [ ] : = angle2 = ArcCos  // N
u.u w.w
O u t [ ] =
0.979924

u.p
I n [ ] : = angle3 = ArcCos  // N
u.u * p.p
O u t [ ] =
0.733581

(*5(a)*)
All solutions.nb 7

4 1 -1
I n [ ] : = A= 2 5 -2 ;
11 1
Eigenvalues[A]
O u t [ ] =
1 1
 7 + 13 , 3, 7 - 13 
2 2

I n [ ] : = Eigenvectors[A]
O u t [ ] =

-3 - 13 2 3 + 13  3- 13 2 -3 + 13 
- , , 1, {-1, 1, 0}, - , , 1
1+ 13 1+ 13 -1 + 13 -1 + 13

I n [ ] : = CharacteristicPolynomial[A, x]
O u t [ ] =
27 - 30 x + 10 x2 - x3

I n [ ] : = -MatrixPower[A, 3] + 10 MatrixPower[A, 2] - 30 A + 27 IdentityMatrix[3] // MatrixForm


O u t [ ] / / M a t r i x F o r m =
0 0 0
0 0 0
0 0 0

(*5(b(i))*)

eqn =
NDSolve[{y ''[x] + (y '[x] + 1) ^ 2 * y '[x] + y[x]  0, y[0]  1, y '[0]  0}, y[x], {x, 0, 1}]

O u t [ ] =

Domain: {{0., 1.}}


y[x]  InterpolatingFunction [x]
Output: scalar

I n [ ] : = sol[x_] = eqn〚1, 1, 2〛
O u t [ ] =

Domain: {{0., 1.}}


InterpolatingFunction [x]
Output: scalar

I n [ ] : = sol[0.4]
sol[0.6]
sol[0.11]
O u t [ ] =
0.927686
O u t [ ] =
0.843017
O u t [ ] =
0.99415
8 All solutions.nb

I n [ ] : = data = Table[{x, sol[x]}, {x, 0, 1, 0.1}];


TableForm[data, TableHeadings  {None, {"x", "Numerical"}}]
O u t [ ] / / T a b l e F o r m =
x Numerical
0. 1.
0.1 0.995152
0.2 0.981113
0.3 0.958478
0.4 0.927686
0.5 0.889094
0.6 0.843017
0.7 0.78977
0.8 0.729692
0.9 0.663172
1. 0.590672

I n [ ] : = Plot[sol[x], {x, 0, 1}]


O u t [ ] =

1.0

0.9

0.8

0.7

0.2 0.4 0.6 0.8 1.0

(*5(b(ii))*)
All solutions.nb 9

I n [ ] : = NDSolve[{y '[x]  1 + 1 / 2 y[x] ^ 2, y[0]  1}, y[x], {x, 0, 1}]

Plot[Evaluate[y[x] /. %], {x, 0, 1},


PlotLabel  "Solution to dy/dx = 1 + 1/2 y^2", AxesLabel  {"x", "y(x)"}]

O u t [ ] =

Domain: {{0., 1.}}


y[x]  InterpolatingFunction [x]
Output: scalar

O u t [ ] =
Solution to dy/dx = 1 + 1/2 y^2
y(x)

x
0.2 0.4 0.6 0.8 1.0

(*6(b)*)

In[14]:= f[x_] = x;
LHL = Limitx2 + 1, x  0, Direction  1;
RHL = Limit[x, x  0, Direction  -1];
Fvalue = f[0];
LHL  RHL  Fvalue
Out[18]=
False

(*6(a)*)

In[25]:= eq1 = x  -y ^ 2;
eq2 = y  x + 2;
Solve[{eq1, eq2}, {x, y}]
Out[27]=
{{x  -4, y  -2}, {x  -1, y  1}}
10 All solutions.nb

In[24]:= area = Integrate[Integrate[1, {y, -Sqrt[-x], x + 2}], {x, -4, -1}]


Out[24]=
19
6

(*7(a)*)

In[28]:= x1 = 1;
y1 = 2;
z1 = 4;
x2 = 2;
y2 = 4;
z2 = 5;
l1 = 2;
m1 = 3;
n1 = 3;
l2 = 2;
m2 = 4;
n2 = 5;

θ = ArcSin (m1 * n2 - m2 * n1)2 + (n1 * l2 - n2 * l1)2 + (l1 * m2 - l2 * m1)2 
l = (m1 * n2 - m2 * n1) / Sin[θ];
m = (n1 * l2 - n2 * l1) / Sin[θ];
n = (l1 * m2 - l2 * m1) / Sin[θ];
SD = l * (x2 - x1) + m * (y2 - y1) + n * (z2 - z1) // Simplify
ArcSin[23]
Out[33]=
3
-
23

x - x1 y - y1 z - z1
In[35]:= A1 = l1 m1 n1
l m n
sd1 = Det[A1] // Simplify;
sd1  0
Out[35]=
3 4 2
{-1 + x, -2 + y, -4 + z}, {2, 3, 3},  ,- , 
23 23 23
Out[37]=
1
(40 + 18 x + 5 y - 17 z)  0
23
All solutions.nb 11

x - x1 y - y1 z - z1
In[38]:= A2 = l2 m2 n2
l m n
sd2 = Det[A2] // Simplify;
sd2  0
Out[38]=
3 4 2
{-1 + x, -2 + y, -4 + z}, {2, 4, 5},  ,- , 
23 23 23
Out[40]=
1
(30 + 28 x + 11 y - 20 z)  0
23

(*7(b)*)

In[41]:= x1 = 1; y1 = 4; x2 = 2; y2 = 7; x3 = 4; y3 = 11;
f[x_, y_] := x ^ 2 + y ^ 2 + 2 g * x + 2 f * y + c  0;
P := f[x, y] /. {x  x1, y  y1};
Q := f[x, y] /. {x  x2, y  y2};
R := f[x, y] /. {x  x3, y  y3};
Solve[{P, Q, R}, {f, g, c}]

{{f  3, g  -27, c  13}}

In[47]:= x ^ 2 + y ^ 2 + 2 g * x + 2 f * y + c  0 /. %
Out[47]=
13 - 54 x + x2 + 6 y + y2  0

(*8(a)*)
12 All solutions.nb

In[48]:= f[x_, y_] = x5 * y7 ;


fx [x_, y_] = Limit[(f[x + h, y] - f[x, y]) / h, h  0]
fy [x_, y_] = Limit[(f[x, y + k] - f[x, y]) / k, k  0]
fxx [x_, y_] = Limit[(fx [x + h, y] - fx [x, y]) / h, h  0]
fyy [x_, y_] = Limit[(fy [x, y + k] - fy [x, y]) / k, k  0]
fxy [x_, y_] = Limit[(fx [x, y + k] - fx [x, y]) / k, k  0]
fyx [x_, y_] = Limit[(fy [x, y + k] - fy [x, y]) / h, h  0]
Out[49]=
5 x 4 y7
Out[50]=
7 x5 y6
Out[51]=
20 x3 y7
Out[52]=
42 x5 y5
Out[53]=
35 x4 y6
Out[54]=
Indeterminate

In[55]:= fx [3, 4]
fy [3, 4]
fxx [3, 4]
fyy [3, 4]
fxy [3, 4]
fyx [3, 4]
Out[55]=
6 635 520
Out[56]=
6 967 296
Out[57]=
8 847 360
Out[58]=
10 450 944
Out[59]=
11 612 160
Out[60]=
Indeterminate

(*8(b)*)
All solutions.nb 13

In[68]:= p = 2 x * y - x2 ;
q = x2 + y2 ;
1 1
Int1 =  p /. y  x2   x +  q /. y  x2  2 x  x;
0 0
0 0
Int2 =  p /. x  y  2 y  x +  q /. x  y2   y;
2
1 1
lhs = Int1 + Int2
1 x
rhs =   (∂x q - ∂y p)  y  x
0 x2
lhs  rhs
Out[72]=
7
- 2 y 2 y3 - y4 
15
Out[73]=
0
Out[74]=
7
- 2 y 2 y3 - y4   0
15

(*9(a+b)*)

In[82]:= f[i_, j_] := (i + 2 j)2 /; i + j < 4


f[i_, j_] := (2 i - j)2 /; i + j ≥ 4
A = Array[f, {4, 4}];
A // MatrixForm
9 25 1 4
16 4 1 0
25 16 9 4
49 36 25 16

In[86]:= Tr[A]
Out[86]=
38

(*10(a)*)
14 All solutions.nb

In[111]:=
u = {3, 4};
v = {1, 2};
w = {2, 0};
pt1 = {u, v, w};
pt2 = {u, v, w, u};
p1 = ListPlot[pt1, PlotStyle  {Hue[0.56], PointSize[0.04]}]
P2 = ListPlot[pt2, PlotStyle  {Hue[0.56], PointSize[0.04]}, Joined  True]
Show[p1, P2]
Out[116]=

1.5 2.0 2.5 3.0

Out[117]=

1.5 2.0 2.5 3.0


All solutions.nb 15

Out[118]=

1.5 2.0 2.5 3.0

(*10(b)*)
In[121]:=
-1 2 3
A= 1 -2 4 ;
5 -3 -4
B = MatrixPower[A, 5] + 2 MatrixPower[A, 4] -
3 MatrixPower[A, 3] + 4 MatrixPower[A, 2] - 5 A + 6 IdentityMatrix[3];
B // MatrixForm
456 31 -930
-1528 2425 -505
-521 -393 1764

In[123]:=
3 - Length[NullSpace[B]] × MatrixRank[B]
Out[123]=
3

You might also like