Knowledge Base
From Joon's Homepage (joonahn)
Contents |
[edit] Synchronize Directories Using rsync
- Code:
#!/bin/bash for arg in "$*"; do if [ "$arg" == "-t" ] ; then ARG="-n" fi if [ "$arg" == "-h" ] ; then echo -e "Usage:> $0 [-t] [-h]\n\t -t: show what would have been transferred\n\t -h: show this help message\n" exit 0; fi done LOCALDIR="$(dirname $0)"CMDNAME=$(basename $0) if [ "${LOCALDIR:0:1}" != "/" ] ; then LOCALDIR=${PWD}/${LOCALDIR} fi if ( ! [ -f "${PWD}/${CMDNAME}" ] ) ; then echo "This command should be executed on its enclosing folder." exit 1 fi rsync -autv $ARG -e 'ssh -l joonahn' --exclude '.*' --exclude '_*' ./ anrg.usc.edu:~/main/research/pdt-aloha/
[edit] LaTeX
- Multi-letter variable/function name or operator name like sin, max in the math mode
If you want to put in some customized function name (like sin, cos, etc), or some operator name (like max, Minimize, etc), one of the decent way to do that is using \\operatorname command. If you use the operator name a few times, you can directly put the command as follows: \operatorname{Minimize} f(x)Or if you are likely to use the operator name a lot, you might want to declare a custom command for it and use it like built-in operator as follows:
... \newcommand{\Minimize}{\operatorname{Minimize}} ... \Minimize f(x)
- Canceling Terms in LaTeX Math
- A strikeout/strikethrough with text
\usepackage{ulem}
...
blah blah blah \sout{this text will have strikethrough} blah blah blah
...
[edit] Mathematica
The following functions are defined in myfunc.nb as a Mathematica notebook file, and myfunc.m as a Mathematica package file.
[edit] Line Style Function for Plotting
lineStyle[n_]
- lineStyle[n_] gives n-th set of line options among 5 types of graphics directives for lines.
- Example:
Plot[{Sin[2 Pi x], Cos[2 Pi x], Sin[2 Pi x + Pi/4]}, {x, 0, 1}, PlotStyle -> {lineStyle[1], lineStyle[2], lineStyle[3]}]
- Output:
- Source code:
lineStyle[n_] := If[n == 1, {AbsoluteThickness[2], Hue[n/5]}, If[n == 2, {AbsoluteThickness[2], Hue[n/5], AbsoluteDashing[{9}]}, {AbsoluteThickness[ 2], Hue[n/5], AbsoluteDashing[Join[{10, 8}, Flatten[Table[{1, 8}, { n - 2}]]]]}]] lineStyle::usage="lineStyle[n_] gives n-th set of line options among 5 types \ of graphics directives for lines."
[edit] Easy FontStyle Function for Plotting
myFontForm[x_,s_]
- myFontForm[x_,s_] returns a string given by x with the predefined font of size s.
myFontForm[x_, s_] := StyleForm[x, FontSize -> s, FontWeight -> "Bold", FontFamily -> "Book Antiqua", FontSlant -> "Italic"] myFontForm::usage="myFontForm[x_,s_] returns a string given by x with the predefined font of size s."
[edit] Easy Legend Function for Plotting
legend4Lines[x_, y_, lineWidth_, fontSize_, listLabels_]
- This function returns a graphics object which describes labels given by listLabels with the lineStyle[] of the order of each label. The upper-left corner of the label box is (x,y), assuming the drawing area is [0,1]x[0,1]. The line length in the legend is specified by 'lineWidth' assuming the width of drawing area is 1, and the font size by fontSize.
- Example:
myplot1 = Plot[{Sin[2 Pi x], Cos[2 Pi x]}, {x, 0, 1}, PlotStyle -> lineStyle /@ {1, 2}] Show[{myplot1, legend4Lines[0.5, 0.9, 0.1, 12, {"sin", "cos"}]}]
- Output:
- Source code:
legend4Lines[x_,y_,lineWidth_,fontSize_,listLabels_]:=Module[{fs,hi}, fs:=fontSize; hi:=fs*1.5; Graphics[ Flatten[Table[{Flatten[{lineStyle[i], Line[{Offset[{0,-fs/2-(i-1)*hi},Scaled[{x,y}]], Offset[{0,-fs/2-(i-1)*hi},Scaled[{x+lineWidth,y}]]}]}], Text[myFontForm[listLabels[[i]],fontSize], Offset[{0,-fs/2-(i-1)*hi},Scaled[{x+lineWidth+0.02,y}]],{-1, 0}]},{i,1,Length[listLabels]}],1]]] legend4Lines::usage= "legend4Lines[x_,y_,lineWidth_,fontSize_,listLabels_] returns a graphics \ object which describes labels given by 'listLabels' with the 'lineStyle[]' of \ the order of each label. The upper-left corner of the label box is (x,y), \ assuming the drawing area is [0,1]x[0,1]. The line length in the legend is \ specified by 'lineWidth' assuming the width of drawing area is 1, and the \ font size by 'fontSize'.";
[edit] Plotting sets of data points and the average line for each set.
pointsAndAverage[listListPoints_, listListOptions_]
pointsAndAverage[listListPoints_]- These functions are for drawing sets of points with different graphical options so that the sets can be distinguished easily. They also draw the line for the average of each sets.
- pointsAndAverage[listListPoints_, listListOptions_] generates the Graphics object to plot, which represents sets of points and the average line for each set. listListPoints is the list of the list of points; {list1, list2, list2, ...}, where list1 = {pt1, pt2, pt3, ...}. A point is 2D point. If you give sets of options, i.e. graphics directives, i-th set of points gets (i mod n2)-th set of options, where n2 is the number of sets of options in listListOptions.
- pointsAndAverage[listListPoints_] is the version without any options.
- Example)
pts1 = {{1,0.96626},{2,0.386203},{3,0.306571},{4,0.28884},{5,0.886882}}; pts2 = {{1,0.284244},{2,0.343451},{3,0.895629},{4,0.519984},{5,0.36614}}; pts3 = {{1,0.203719},{2,0.307841},{3,0.226611},{4,0.667313},{5,0.562274}}; opt1 = {Black, AbsolutePointSize[4], AbsoluteThickness[2]}; opt2 = {Blue, AbsolutePointSize[4], AbsoluteThickness[2]}; opt3 = {Red, AbsolutePointSize[4], AbsoluteThickness[2]}; Show[ pointsAndAverage[{pts1, pts2, pts3}, {opt1, opt2, opt3}], Axes -> True]
- Output:
- Source code
pointsAndAverage[listListPoints_, listListOptions_]:=Module[{i,opt, n1,n2,avg, xvalues}, n1=Length[listListPoints]; n2=Length[listListOptions]; Graphics[ Reap[ For[i=1, i≤n1, i++, opt=If[n2 > 0, listListOptions[[ Mod[i,n2,1] ]], {Black}]; Sow[(Append[opt,Point[#]]&)/@listListPoints[[i]] ]; avg=Mean[ Cases[listListPoints[[i]], {_,y_}\[RuleDelayed]y] ]; xvalues = Cases[listListPoints[[i]], {x_,_}\[RuleDelayed]x]; Sow[Append[opt, Line[{{Min[ xvalues ], avg}, {Max[ xvalues], avg}}]]]; ]][[2,1]] ] ] pointsAndAverage[listListPoints_]:=pointsAndAverage[listListPoints, {}] pointsAndAverage::usage="pointsAndAverage[listListPoints_, listListOptions_] \ generates the Graphics object to plot, which represents sets of points and \ the average line for each set. listListPoints is the list of the list of \ points; {list1, list2, list2, ...}, where list1 = {pt1, pt2, pt3, ...}. A \ point is 2D point. If you give sets of options, i.e. graphics directives, \ i-th set of points gets (i mod n2)-th set of options, where n2 is the number \ of sets of options in listListOptions. pointsAndAverage[listListPoints_] is the version without any options."


