-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMathematicaBasic.txt
107 lines (72 loc) · 1.84 KB
/
MathematicaBasic.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(* THE VERY BASIC (1) *)
5/6
3+4
9^2
E^(I Pi)
Pi
N[Pi]
(* THE VERY BASIC (2) *)
3 + 4
%/2
N[%]
10*10 == 100
10 < Exp[10]
10 < Log[10]
(* THE VERY BASIC (3) *)
(x - 1) (x + 1)
Simplify[%]
(x + 1) (x + 2) (x + 3)
Expand[%]
x^10 - 1
Factor[%]
=============================================================================
(* DEFINITION *)
a = 1
b = 2
a + b
a*b
y = Sin[x]
Plot[y, {x, -Pi, Pi}]
(* The last command (Plot[y,{x,-Pi,Pi}]) is not recommended. Instead, you should define a function. *)
f[x_] := Cos[x]
f[Pi]
f[Pi/2]
Plot[f[x], {x, -Pi, Pi}]
=============================================================================
(* Substitution (VERY IMPORTANT!) *)
y = Sin[x] + Cos[x]
y /. {x -> 4}
y /. Sin -> Tan
y /. {Sin -> Exp, x -> 4}
ReplaceAll[y, x -> 4]
(* /. is a syntax suger of ReplaceAll. *)
(* REPEATED substitution *)
energy = m*gamma
ReplaceAll[energy, {gamma -> 1/Sqrt[1 - beta^2], beta -> v/c}]
ReplaceRepeated[energy, {gamma -> 1/Sqrt[1 - beta^2], beta -> v/c}]
(* ReplaceRepeated has a syntax sugar //. *)
energy //. {gamma -> 1/Sqrt[1 - beta^2], beta -> v/c}
=============================================================================
(* EMERGENCY EXIT *)
(* ALT (or command)+period if you want to stop evaluation. *)
(* You can stop evaluation from the menu: Evaluation>Abort Evaluation. *)
Integrate[(Sin[x] + Tan[x])^100, x]
(* This is important when you induce an infinite-evaluation. *)
Sin[x] /. x -> Sin[x]
Sin[x] //. x -> Sin[x]
=============================================================================
(* THAT'S MATHEMATICA BASIC. *)
(* Now Let's forget all == ABORT THE KERNEL. *)
energy
Exit[]
(* Now the kernel has been initialized. Everything is now cleared. *)
energy
(* is now undefined. *)
(* Note that you can clear a variable with Clear *)
abc = a + b + c
{a, b, c} = {1, 2, 3}
abc
Clear[a]
abc
Clear[b,c]
abc