0% found this document useful (0 votes)
63 views12 pages

Harshit Singh Practical2

The document contains the solutions to various questions involving graphing functions, taking derivatives, matrix operations, factoring numbers, solving equations, and writing a function to calculate square roots. For each question, the relevant calculations and code are shown along with the outputs.

Uploaded by

Harshit Singh
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)
63 views12 pages

Harshit Singh Practical2

The document contains the solutions to various questions involving graphing functions, taking derivatives, matrix operations, factoring numbers, solving equations, and writing a function to calculate square roots. For each question, the relevant calculations and code are shown along with the outputs.

Uploaded by

Harshit Singh
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/ 12

Practical 2

Harshit Singh
Q1 Graph each of the functions. Experiment with different domains
or viewpoints to display the best images.

a) y = x/(1+x^2)
In[5]:= Plot[x / (1 + x^2), {x, - 10, 10}]

0.4

0.2

Out[5]=
-10 -5 5 10

-0.2

-0.4

In[3]:= Plot[x / (1 + x^2), {x, - 2, 2}]

0.4

0.2

Out[3]=
-2 -1 1 2

-0.2

-0.4
2

b) y = x sin(1/x)
In[6]:= Plotx Sin[1 / x], {x, - π , π}

1.0

0.8

0.6

Out[6]= 0.4

0.2

-3 -2 -1 1 2 3

-0.2

In[7]:= Plotx Sin[1 / x], {x, - π / 6, π / 6}

0.5

0.4

0.3

0.2
Out[7]=
0.1

-0.4 -0.2 0.2 0.4

-0.1

-0.2
3

c) y = cos(x) +sin(y)
In[10]:= Plot3DCos[x] + Sin[y], {x, - π , π}, y, - 2 π , 2 π
Out[10]=

In[1]:= Plot3DCos[x] + Sin[y], {x, - π , π}, y, - 6 π , 6 π

Out[1]=
4

d) f(x) = x y/(x^2+y^2)
In[11]:= Plot3Dx y / (x ^ 2 + y ^ 2), {x, - 5, 5}, {y, - 10, 10}
Out[11]=

In[12]:= Plot3Dx y / (x ^ 2 + y ^ 2), {x, - 25, 25}, {y, - 100, 100}


Out[12]=

Q2. Let f(x) = x/(1 + x^2)


a) Find f'(x) and f"(x)
In[23]:= f[x_] := x / (1 + x ^ 2)
5

In[24]:= D[f[x]]
D[f[x], {x, 2}]
Out[24]=
x
1 + x2
Out[25]=

4x 8 x2 2
- +x -
1 + x 
2 2
1 + x  2 3
1 + x2
2

b) Find f'(-1) and f'(0).


In[4]:= f[x_] := x / (1 + x ^ 2)

In[5]:= f '[- 1]
f '[0]
Out[5]= 0

Out[6]= 1

c) Find f"(0) and f"(1).


In[7]:= f ''[x]
f ''[0]
f ''[1]

8 x3 6x
Out[7]= -
1 + x2 1 + x2
3 2

Out[8]= 0
1
Out[9]= -
2

Q3. Find the prime factorization of each integer.


a) 3,527,218,133,309,949,276,293
In[32]:= FactorInteger 3 527 218 133 309 949 276 293
Out[32]=

{{15 013, 2}, {25 013, 3}}


6

b) 471,945,325,930,166,269
In[34]:= FactorInteger[471 945 325 930 166 269]
Out[34]=

{{4211, 1}, {34 589, 1}, {46 747, 1}, {69 313, 1}}

c) 471945325930166281
In[35]:= FactorInteger[471 945 325 930 166 281]
Out[35]=

{{471 945 325 930 166 281, 1}}

Q4. Compute each expression.


a) 3^6 mod 7
In[36]:= Mod[3 ^ 6, 7]
Out[36]=

b) 6^10 mod 11
In[37]:= Mod[6 ^ 10, 11]
Out[37]=

c) 7^20 mod 21
In[38]:= Mod[7 ^ 20, 21]
Out[38]=

d) 7^22 mod 22
In[39]:= Mod[7 ^ 22, 23]
Out[39]=

1
7

Q8. Let M=[1 1 1 0]


a) Find M^2, M^3, . . . , M10
In[11]:= M = {{1, 1}, {1, 0}}
Out[11]=

{{1, 1}, {1, 0}}


8

In[12]:= MatrixPower[M, 2] // MatrixForm


MatrixPower[M, 3] // MatrixForm
MatrixPower[M, 4] // MatrixForm
MatrixPower[M, 5] // MatrixForm
MatrixPower[M, 6] // MatrixForm
MatrixPower[M, 7] // MatrixForm
MatrixPower[M, 8] // MatrixForm
MatrixPower[M, 9] // MatrixForm
MatrixPower[M, 10] // MatrixForm

Out[12]//MatrixForm=
2 1
1 1
Out[13]//MatrixForm=
3 2
2 1
Out[14]//MatrixForm=
5 3
3 2
Out[15]//MatrixForm=
8 5
5 3
Out[16]//MatrixForm=
13 8
8 5
Out[17]//MatrixForm=
21 13
13 8
Out[18]//MatrixForm=
34 21
21 13
Out[19]//MatrixForm=
55 34
34 21
Out[20]//MatrixForm=
89 55
55 34

In[30]:= Fori = 1, i < 10, i ++ Print[MatrixForm[MatrixPower[M, i]]]


9

2 1
1 1
3 2
2 1
5 3
3 2
8 5
5 3
13 8
8 5
21 13
13 8
34 21
21 13
55 34
34 21
89 55
55 34

b) Find the 100th Fibonacci number


In[31]:= M = {{1, 1}, {1, 0}}
Out[31]=

{{1, 1}, {1, 0}}

In[32]:= MatrixPowerM, 100


Out[32]=

{{573 147 844 013 817 084 101, 354 224 848 179 261 915 075},
{354 224 848 179 261 915 075, 218 922 995 834 555 169 026}}

Conclusion : The second element in the first row gives the nth Fibonacci Number in the nth power of M.

Q9. Find solutions to the following equations or systems


of equations.
a) Find x, if x^2 + x = 1.
In[34]:= Solvex ^ 2 + x ⩵ 1, x
Out[34]=
1 1
x → - 1 - 5 , x → - 1 + 5 
2 2
10

b) Find x, if x^2 + x = -1.


In[35]:= Solvex ^ 2 + x ⩵ - 1, x
Out[35]=

x → - (- 1)13, x → (- 1)23

c) Find x and y
4x - 3y = 5
6x + 2y = 14
In[36]:= Solve4 x - 3 y ⩵ 5, 6 x + 2 y ⩵ 14, x, y
Out[36]=

{{x → 2, y → 1}}

d) -2x - 2y + 3z + t = 8
-3x + 0y - 6z + t = -19
6x - 8y + 6z + 5t = 47
x + 3y - 3z - t = -9
Find x, y, z, and t.
In[38]:= Solve- 2 x - 2 y + 3 z + t ⩵ 8, - 3 x + 0 y - 6 z + t ⩵ - 19,

6 x - 8 y + 6 z + 5 t ⩵ 47, x + 3 y - 3 z - t ⩵ - 9, x, y, z, t


Out[38]=

{{x → 2, y → 1, z → 3, t → 5}}

Q 10. To find the (continuous) rate of return, solve this


equation for r: 250e^1.0r + 300e^0.75r + 350e^0.5r +
400e^0.25r = 1365.
In[39]:= FindRoot

250 * E ^ (r) + 300 * E ^ 0.75 * r + 350 * E ^ 0.5 * r + 400 * E ^ 0.25 * r ⩵ 1365, r, 10
Out[39]=

{r → 0.084104}

Q11. Write a function called mysqrt that accepts one


11

argument, begins with an initial guess of 1.0, finds 20 new


guesses, and returns the answer.
In[50]:= S[n_] := Module{g}, g = 1.0; For i = 20, i ≥ 1, --i Print[g], g = (g + (n / g)) / 2

In[41]:= N[S[2], 5]
N[S[3], 6]
1.5

1.41667

1.41422

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

1.41421

2.

1.75

1.73214

1.73205

1.73205

1.73205

1.73205

1.73205

1.73205
12

1.73205

1.73205

1.73205

1.73205

1.73205

1.73205

1.73205

1.73205

1.73205

1.73205

1.73205

You might also like