0% found this document useful (0 votes)
151 views18 pages

Some Mathematica Practice

This document contains definitions of mathematical expressions, functions, and operations on various types of mathematical objects like numbers, vectors, matrices, and complex numbers. It also contains plots of standard trigonometric and other functions over different ranges.

Uploaded by

ChandraManShakya
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)
151 views18 pages

Some Mathematica Practice

This document contains definitions of mathematical expressions, functions, and operations on various types of mathematical objects like numbers, vectors, matrices, and complex numbers. It also contains plots of standard trigonometric and other functions over different ranges.

Uploaded by

ChandraManShakya
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/ 18

a = 3 +2

3+2
b =

2
c =
1
2

1+

2
2

1 +

d = 1.5
4.48169
a +b+c+d
10.103 + 2.
% + 2
12.103 + 2.
e = 5*d
22.4084
f = c +d
5.6887958515246115`
5.6888
y = x2
x2
TrigToExp[[sinx]]
Part::pkspec1 : The expression sinx cannot be used as a part specification.

TrigToExpsinx
Part::pkspec1 : The expression sinx cannot be used as a part specification.

TrigToExp[sin[x]]
sin[x]
sin[x] x
sin[x] x
ExpToTrig[Exp[x]]
Cosh[x] + Sinh[x]

Untitled-1.nb

TrigToExp[Sin[x]]
1
2
1
2

- x - x -

1
2
1
2

x
x

x2 Sin
Sin x2
x2 + Sin[x] /. x y 2 + z
y2 + z2 + Siny2 + z
Expandx + 1 x - 1
- 1 + x2
- 1 + x2
Simplifyx2 + 2 x2 + Sin[x]
3 x2 + Sin[x]
Factorx2 - 1
(- 1 + x) (1 + x)
N[, 1000]
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089
98628034825342117067982148086513282306647093844609550582231725359408128481117450
28410270193852110555964462294895493038196442881097566593344612847564823378678316
52712019091456485669234603486104543266482133936072602491412737245870066063155881
74881520920962829254091715364367892590360011330530548820466521384146951941511609
43305727036575959195309218611738193261179310511854807446237996274956735188575272
48912279381830119491298336733624406566430860213949463952247371907021798609437027
70539217176293176752384674818467669405132000568127145263560827785771342757789609
17363717872146844090122495343014654958537105079227968925892354201995611212902196
08640344181598136297747713099605187072113499999983729780499510597317328160963185
95024459455346908302642522308253344685035261931188171010003137838752886587533208
38142061717766914730359825349042875546873115956286388235378759375195778185778053
2171226806613001927876611195909216420199
poly = 1 + 3 x2 + 5 x3 + Sin[x]
1 + 3 x2 + 5 x3 + Sin[x]
Coefficientpoly, x2
3

Untitled-1.nb

Coefficientpoly, x23
0
Coefficientpoly, x3
5
Solvez x2 + 1, x
x -

- 1 + z , x

- 1 + z

Solve[x + y + z == 1 && x - y 2, {x, y, z}]


Solve::svars : Equations may not give solutions for all "solve" variables.

{{y - 2 + x, z 3 - 2 x}}
z=
z = 3+2
3+2
z2
5 + 12
Abs[z]
13
Arg[z]
2
ArcTan
3
Conjugate[z]
3-2
Im[z]
2
Re[z]
3
A = {{1, 2}, {3, 4}}
{{1, 2}, {3, 4}}
v = {v1, v2}
{v1, v2}
A // MatrixForm
1 2
3 4

Untitled-1.nb

Det[A]
-2
Inverse[A] // MatrixForm
-2
3
2

1
- 12

MatrixPower[A, 2] // MatrixForm
7 10
15 22
A2 // MatrixForm
1 4
9 16
Transpose[A] // MatrixForm
1 3
2 4
Eigenvalue[A] // MatrixForm
Eigenvalue[{{1, 2}, {3, 4}}]
kroneckerProduct[A, A] // MatrixForm
kroneckerProduct[{{1, 2}, {3, 4}}, {{1, 2}, {3, 4}}]
A[[1]] // MatrixForm
1
2
M = Table[i * j + Sin[i + j], {i, 1, 10}, {j, 1, 10}];
M // MatrixForm
1 + Sin[2]
2 + Sin[3]
2 + Sin[3]
4 + Sin[4]
3 + Sin[4]
6 + Sin[5]
4 + Sin[5]
8 + Sin[6]
5 + Sin[6]
10 + Sin[7]
6 + Sin[7]
12 + Sin[8]
7 + Sin[8]
14 + Sin[9]
8 + Sin[9] 16 + Sin[10]
9 + Sin[10] 18 + Sin[11]
10 + Sin[11] 20 + Sin[12]
f[x_] := Cos[x] + Sin[x]
g[x_] := Cos[x] - 2
f[1]
Cos[1] + Sin[1]

3 + Sin[4]
6 + Sin[5]
9 + Sin[6]
12 + Sin[7]
15 + Sin[8]
18 + Sin[9]
21 + Sin[10]
24 + Sin[11]
27 + Sin[12]
30 + Sin[13]

4 + Sin[5]
8 + Sin[6]
12 + Sin[7]
16 + Sin[8]
20 + Sin[9]
24 + Sin[10]
28 + Sin[11]
32 + Sin[12]
36 + Sin[13]
40 + Sin[14]

5 + Sin[6]
10 + Sin[7]
15 + Sin[8]
20 + Sin[9]
25 + Sin[10]
30 + Sin[11]
35 + Sin[12]
40 + Sin[13]
45 + Sin[14]
50 + Sin[15]

6 + Sin[7]
12 + Sin[8]
18 + Sin[9]
24 + Sin[10]
30 + Sin[11]
36 + Sin[12]
42 + Sin[13]
48 + Sin[14]
54 + Sin[15]
60 + Sin[16]

7 + Sin[8]
14 + Sin[9]
21 + Sin[10
28 + Sin[11
35 + Sin[12
42 + Sin[13
49 + Sin[14
56 + Sin[15
63 + Sin[16
70 + Sin[17

Untitled-1.nb

N[f[1], 500]
1.3817732906760362240534389290732756033548734814162932933428489653730107991657114
33466591599630235785197920769067950763391119752681013562337599922593146530994198
76312030124610123302568856337166311867608410418769546667439231134551209714938534
80398013498165869124104602627981486197213374456044404049404666336278310353974401
30547095806709981280179805908665319691711301032983221716525400979343699088941502
89443838031558602049036028725914746540820001749882286504111943958159236925450922
90576418206053957280
h[x_, y_] := Sin[x] + Cos[y]
h[1, 2]
Cos[2] + Sin[1]
data = {1, 2, 3, 4, 5};
avd[v_] :=

av2[v_] :=

Length[v]

Length[v]

i=1

Total[v]
Length[v]

vi;

av1[data]
1
5

({1, 2, 3, 4, 5}[1] + {1, 2, 3, 4, 5}[2] +


{1, 2, 3, 4, 5}[3] + {1, 2, 3, 4, 5}[4] + {1, 2, 3, 4, 5}[5])

av2[data]
3
vd[v_] :=
vd[data]
3
3

Length[v]

Length[v]

i=1

vi;

Untitled-1.nb

Plot[Sin[x], {x, 0, 10}]


1.0

0.5

10

-0.5

-1.0

Plot[Sin[x], Cos[x] {x, 0, 10}]


Plot::pllim : Range specification Cos[x] {x, 0, 10} is not of the form {x, xmin, xmax}.

Plot[{Sin[x], Cos[x]} , {x, 0, 10}]


1.0

0.5

10

10

-0.5

-1.0

Show[%54, AxesStyle Black]


1.0

0.5

-0.5

-1.0

Untitled-1.nb

Show[%55, AxesStyle Gray]


1.0

0.5

10

10

-0.5

-1.0

Show[%56, AxesStyle White]


1.0

0.5

-0.5

-1.0

x
x
Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}]

Untitled-1.nb

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5},


PlotStyle Directive[RGBColor[0., 0.4, 1.], Opacity[0.724]]]

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5},


Axes
Axes
AxesLabel - {"x", "y", "z"}
AxesLabel {- x, - y, - z}
Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5},
AxesLabel - {"x", "y", "z"}]
Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, {z, 0, 5}
Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, {z, 0, 5}, AxesLabel - {"x", "y", "z"}]
Plot3D::nonopt : Options expected (instead of {z, 0, 5}) beyond position 3 in
Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, {z, 0, 5}, AxesLabel -{x, y, z}]. An option must be a rule or a list of rules.

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, {z, 0, 5}, AxesLabel - {x, y, z}]
Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, {z, 0, 5}, AxesLabel - {"x", "y", "z"}]
Plot3D::nonopt : Options expected (instead of {z, 0, 5}) beyond position 3 in
Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, {z, 0, 5}, AxesLabel -{x, y, z}]. An option must be a rule or a list of rules.

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, {z, 0, 5}, AxesLabel - {x, y, z}]

Untitled-1.nb

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, AxesLabel - {"x", "y", "z"}]

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, AxesLabel {"x", "y", "z"}]

10

Untitled-1.nb

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, Mesh None, AxesLabel {"x", "y", "z"}]

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, Mesh Automatic,


MeshFunctions Automatic, Mesh None, AxesLabel {"x", "y", "z"}]

Untitled-1.nb

11

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, Mesh All, MeshFunctions Automatic,
Mesh Automatic, MeshFunctions Automatic, Mesh None, AxesLabel {"x", "y", "z"}]

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, Mesh None,


Mesh All, MeshFunctions Automatic, Mesh Automatic,
MeshFunctions Automatic, Mesh None, AxesLabel {"x", "y", "z"}]

12

Untitled-1.nb

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5},


BaseStyle {FontSize 14}, AxesLabel {"x", "y", "z"}, Mesh None]

Plot3D[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, PlotStyle RGBColor[0., 0.13, 0.83],
BaseStyle {FontSize 14}, AxesLabel {"x", "y", "z"}, Mesh None]

Untitled-1.nb

DensityPlot[Sin[x] Cos[y], {x, 0, 5}, {y, 0, 5}, AxesLabel - {"x", "y", "z"}]

ParametricPlot3D[{Cos[t], Sin[t], t, {t, 0, 2 }}]


ParametricPlot3D::argtu : ParametricPlot3D called with 1 argument; 2 or 3 arguments are expected.

ParametricPlot3D[{Cos[t], Sin[t], t, {t, 0, 2 }}]


ParametricPlot3D[{Cos[t], Sin[t], t}, {t, 0, 4 }]

D[Sin[x], x]
Cos[x]

13

14

Untitled-1.nb

Integrate[%, x]
Sin[x]
Integrate[sinx, x]
sinx x
Integrate[Sin[x], x]
- Cos[x]
NIntegrate[Cos[x], {x, 0, 5}]
- 0.958924
DSolve[2 * y '[x] + 3 * y[x] + cos[x] x, y[x], x]
y[x] -3 x/2 C[1] + -3 x/2

x
1

y[x] -3 x/2 C[1] + -3 x/2

x
1

1
2
1
2

3 K[1]
2

3 K1

(- cos[K[1]] + K[1]) K[1]

- cos[K[1]] + K[1] K[1]

DSolve[2 * y '[x] + 3 * y[x] + cos[x] x, y[x], x]


y[x] -3 x/2 C[1] + -3 x/2
y[x] -3 x/2 C[1] + -3 x/2

2
x1

3 K1

3 K[1]
2

- cos[K[1]] + K[1] K[1]

(- cos[K[1]] + K[1]) K[1]

DSolve[{y1 '[x] y2[x], y2 '[x] + 3 y1[x]}, {y1[x], y2[x]}, x]


y1[x] 3
4

-x (- -x + x ) - 1 + 2 x +

-2 x 1 + 2 x 2 +

y2[x] 1

3
4

n (1 + n) (1 + 2 n)

i=1

n (1 + n) (1 + 2 n)

2
x x

x3
3

-x 1 + 2 x C[1] +

-x - 1 + 2 x C[1] +

i2
1

-x (- -x + x ) 1 + 2 x +

Sumi2 , {i, 1, n}
1

1
2

3
4

1
2

-x - 1 + 2 x C[2],

-2 x - 1 + 2 x 1 + 2 x +

-x 1 + 2 x C[2]

Untitled-1.nb

sin[x] x
-1
1

sin[x] x
-1
1

Sin[x] x
-1

0
n

i+1
i=1

1 + n!
d[x_] := If[x 0, 1, 0]
d {1}
{d}
d[1]
1
a = 0;
Fori = 1, ii 10, i ++, a = a + i2 ;
a = 0; Fori = 1, ii 10, i ++, a = a + i2 ;
a = 0;
a = 0;
a = 0; For[i = 1, i 10, i ++,]
a = 0;
total = 0
While[a < 10,
a = a + 1;
total = total + a;

Print[total];
total

a = 0;
total = 0
While[a < 10, a = a + 1; total = total + a; Print[total]]

15

16

Untitled-1.nb

Manipulate[Plot[{Sin[ax], Cos[2 ax]}, {x, 0, 5}], {a, 0, 2}]

1.0

0.5

-0.5

-1.0

Manipulate[Plot[{Sin[a x], Cos[2 a x]}, {x, 0, 5}], {a, 0, 2}]

1.0

0.5

-0.5

-1.0

x2+sin[x]
x2+sin[x]
x2 + Sin[x]
x2 + Sin[x]

Untitled-1.nb

17

n = 100;
p = 0.5;
m = 1000;
finalposition = Table[0, {i, 1, n}];
Foriter = 1, iter m, iter ++
x = Floorn 2;
If[Random[],
x = x + 1,
x = x-1
];
;
finalpositionx + 1;
finalposition = finalposition / iter;
ListLinePlot[finalposition, Plotrange All]
Set::write : Tag Times in 1 x is Protected.
Set::write : Tag Times in 2 x is Protected.
Set::write : Tag Times in 3 x is Protected.
General::stop : Further output of Set::write will be suppressed during this calculation.
Part::pkspec1 : The expression x cannot be used as a part specification.
ListLinePlot::optx : Unknown option Plotrange All in
ListLinePlot[{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 50}, Plotrange All].
ListLinePlot::optx : Unknown option Plotrange All in
ListLinePlot[{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 50}, Plotrange All].

ListLinePlot[{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Plotrange All]
List1[1, 2, 3, 4}
List1[1, 2, 3, 4]
List2[] 5, 6, 7, 8]
List1 + List2
List1 + List2

A
A

18

Untitled-1.nb

A = {{1, 2, 3}, {4, 5, 6}, {7, 8, 10}}


{{1, 2, 3}, {4, 5, 6}, {7, 8, 10}}
A // MatrixForm
1 2 3
4 5 6
7 8 10
Det[A]
-3
Inverse [A] // MatrixForm
Inverse::sing : Matrix {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} is singular.

Inverse[{{1, 2, 3}, {4, 5, 6}, {7, 8, 10}}]


Inverse[A] // MatrixForm
- 23 - 43
2
3

11
3

-2
-2 1

You might also like