-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMA library.m
121 lines (88 loc) · 2.53 KB
/
MMA library.m
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
(* ::Package:: *)
(* ::Chapter:: *)
(*General Mathematica helpers*)
exportNotebookPDF[]:=
Module[{name},
name=("FileName"/.NotebookInformation[])[[2]];
name=StringReplace[name,".nb"->".pdf"];
Export[FileNameJoin[{NotebookDirectory[],name}],EvaluationNotebook[]]
]
(* ::Subsection:: *)
(*Vector equations*)
splitVectorEqn[eqn_]:=Module[{},
If[Head[eqn]==Equal,Thread[eqn],eqn]
]
(* ::Subsection:: *)
(*Polar Coordinates*)
rhat={1,0};
\[Theta]hat={0,1};
polaraccel[]:=r''[t]rhat+2 r'[t] \[Theta]'[t] \[Theta]hat+r[t]\[Theta]''[t] \[Theta]hat-r[t] \[Theta]'[t]^2 rhat
(* ::Subsection:: *)
(*Template cell*)
makeTemplate[]:=makeTemplate["Template"]
makeTemplate[name_] :=
Module[{namespace},
namespace = ToLowerCase@StringReplace[name,Whitespace->""];
makeTemplate[name, namespace]
]
makeTemplate[name_, namespace_]:=
Module[{cell, replacerules},
replacerules = <| "Template"->name,
"\"\<xxx\>\""->StringReplace["\"\<xxx`\>\"","xxx"->namespace] |>;
cell=
Cell[CellGroupData[{Cell["Template", "Section"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{
RowBox[{"With", "[",
RowBox[{
RowBox[{"{",
RowBox[{"context", "=", "\"\<xxx\>\""}], "}"}], ",",
RowBox[{"If", "[",
RowBox[{
RowBox[{
RowBox[{"Context", "[", "]"}], " ", "\[NotEqual]", " ",
"context"}], ",",
RowBox[{"Begin", "[", "context", "]"}]}], "]"}]}], "]"}], ";",
RowBox[{"Dynamic", "[",
RowBox[{"Refresh", "[",
RowBox[{
RowBox[{"Context", "[", "]"}], ",",
RowBox[{"UpdateInterval", "\[Rule]", "1"}]}], "]"}],
"]"}]}]], "Input"],
Cell[BoxData[
DynamicBox[ToBoxes[
Refresh[
Context[], UpdateInterval -> 1], StandardForm],
ImageSizeCache->{57., {0., 12.}}]], "Output"]
}, Open ]],
Cell[CellGroupData[{Cell[BoxData[
RowBox[{
RowBox[{"With", "[",
RowBox[{
RowBox[{"{",
RowBox[{"context", "=", "\"\<xxx\>\""}], "}"}], ",",
RowBox[{"If", "[",
RowBox[{
RowBox[{
RowBox[{"Context", "[", "]"}], "\[Equal]", "context"}], ",",
RowBox[{"End", "[", "]"}]}], "]"}]}], "]"}], ";",
RowBox[{"Dynamic", "[",
RowBox[{"Refresh", "[",
RowBox[{
RowBox[{"Context", "[", "]"}], ",",
RowBox[{"UpdateInterval", "\[Rule]", "1"}]}], "]"}],
"]"}]}]], "Input",
GeneratedCell->False,
CellAutoOverwrite->False],
Cell[BoxData[
DynamicBox[ToBoxes[
Refresh[
Context[], UpdateInterval -> 1], StandardForm],
ImageSizeCache->{71., {0., 13.}}]], "Output",
GeneratedCell->False,
CellAutoOverwrite->False]
}, Open ]]
}, Open ]];
CellPrint[cell/.replacerules]
]