From 9e37c5b9e4005859b9376900bc6e7d00928f29f9 Mon Sep 17 00:00:00 2001 From: George Alverson Date: Sat, 22 Apr 2017 15:05:36 -0400 Subject: [PATCH] Add Mathematica commands. Update to jupyter for python notebook interface. --- mathesaurus.xml | 244 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 231 insertions(+), 13 deletions(-) diff --git a/mathesaurus.xml b/mathesaurus.xml index a3f3681..80c1e62 100644 --- a/mathesaurus.xml +++ b/mathesaurus.xml @@ -1,6 +1,6 @@ -Time-stamp: "2016-06-07T21:11:16 vidarg" +Time-stamp: "\$Id: mathesaurus.xml 353 2017-04-22 14:04:50Z George \$, 2016-06-07T21:11:16 vidarg" help help.start() help() + Help (from Menu) help? ? )hd @@ -96,7 +97,11 @@ describe(keyword)$ ?keyword - ?keyword + + ?plot + ??plot + F1 + ?keyword @@ -181,7 +186,7 @@ Start session octave -q Rgui - ipython -pylab + jupyter console or jupyter notebook idlde bc -lq pgnuplot @@ -191,7 +196,9 @@ Auto completion TABM-? ! // commands in history + TAB TAB + TAB z = 1j + I {0,1} complex(0,1) %i @@ -961,6 +1023,7 @@ z = 3+4j z = complex(3,4) + z = 3 + 4 I {3,4} z = complex(3,4) 3+4*%i @@ -973,6 +1036,7 @@ abs(z) abs(3+4i)Mod(3+4i) abs(3+4j) + Abs[3 + 4 I] abs({3,4}) abs(z) abs(z); @@ -984,6 +1048,7 @@ real(z) Re(3+4i) z.real + Re[z] real({3,4}) real_part(z) realpart(z) @@ -995,6 +1060,7 @@ imag(z) Im(3+4i) z.imag + Im[z] imaginary(z) imag({3,4}) imagpart(z) @@ -1003,6 +1069,7 @@ Argument arg(z) + Arg[z] Arg(3+4i) arg({3,4}) @@ -1013,6 +1080,7 @@ conj(z) Conj(3+4i) z.conj(); z.conjugate() + Conjugate[z] conj(z) @@ -1060,6 +1128,7 @@ atan(a,b) atan2(b,a) atan2(b,a) + ArcTan[a,b] @@ -1079,6 +1148,7 @@ Hypotenus; Euclidean distance hypot(x,y) + Norm[{x,y}] \sqrt{x^2+y^2} @@ -1099,6 +1169,7 @@ random((10,)) uniform(0,1,(10,)) + RandomReal[1,10] randomu(seed, 10) @@ -1111,6 +1182,7 @@ random.uniform(2,7,(10,)) uniform(2,7,(10,)) + RandomReal[{2,7},10] 2+5*randomu(seed, 10) @@ -1123,6 +1195,7 @@ random.uniform(0,1,(6,6)) uniform(0,1,(6,6)) + RandomReal[1,{6,6}] randomu(seed,[6,6]) @@ -1136,6 +1209,7 @@ standard_normal((10,)) + RandomReal[NormalDistribution[],10] randomn(seed, 10) @@ -1173,6 +1247,7 @@ a=[2 3 4 5]; a=array([2,3,4,5]) + a = {2,3,4,5} a = [2, 3, 4, 5] @@ -1187,6 +1262,7 @@ r_[1:10,'c'] transpose(array([2,3,4,5])) + a = {2,3,4,5} transpose([2,3,4,5]) + {a,b} @@ -1627,6 +1720,7 @@ array(0,c(3,5)) zeros((3,5),Float) + ConstantArray[0.,{3,5}] dblarr(3,5) 0 filled array of integers zeros((3,5)) + ConstantArray[0,{3,5}] intarr(3,5) @@ -1653,6 +1748,7 @@ array(1,c(3,5)) ones((3,5),Float) + ConstantArray[1.,{3,5}] dblarr(3,5)+1 a.fill(9)--> ones((3,5))*9 + ConstantArray[9,{3,5}] intarr(3,5)+9 eye(3,3) diag(1,3) identity(3) + IdentityMatrix[3] identity(3) diag([4 5 6]) diag(c(4,5,6)) diag((4,5,6)) + DiagonalMatrix[{4,5,6}] diag_matrix([4,5,6]) diagonalMatrix([4,5,6]) Empty array a = empty((3,3)) + a = {} @@ -1775,6 +1875,10 @@ then di(1:10,3) works as per Octave. a.shape = (2,3) a.setshape(2,3) + + Partition[Range[6], 3] + ArrayReshape[Range[6], {2, 3}] + reform(a,2,3) array(1:6,c(2,3)) arange(1,7).reshape(-1,2).transpose() + Transpose[Partition[Range[6], 2, 2]] Flatten to vector (by rows, like comics) - a'(:) + a(:)' as.vector(t(a)) a.flatten() ravel(a) + Flatten[a] @@ -1853,6 +1959,7 @@ then di(1:10,3) works as per Octave. b = a b = a b = a.copy() + b = a a_{23} @@ -1933,6 +2043,7 @@ then di(1:10,3) works as per Octave. a(1,:) a[1,] a[0,] + a[[1]] a(*,0) a(:,1) a[,1] a[:,0] + a[[All,1]] a(0,*) \left[ @@ -1983,6 +2095,10 @@ then di(1:10,3) works as per Octave. a(2:$,:) a[-1,] a[1:,] + + a[[2;;]] + Take[a,2;;] + a(*,1:*) Last two rows a(end-1:end,:) a[-2:,] + a[[-2;;]] Strides: Every other row a(1:2:end,:) a[::2,:] + a[[1;;-1;;2]] a.take([0,2,3],axis=1) take(a,[0,2,3],axis=1) + Drop[a,None,2] total(a,2) @@ -2271,6 +2404,7 @@ then di(1:10,3) works as per Octave. sum(a,'r') apply(a,1,sum) a.sum(axis=1) + Apply[Plus, a] total(a,1) @@ -2288,7 +2422,9 @@ then di(1:10,3) works as per Octave. Sum along diagonal + trace(a) a.trace(offset=0) + Tr[a] @@ -2296,6 +2432,7 @@ then di(1:10,3) works as per Octave. cumsum(a) apply(a,2,cumsum) a.cumsum(axis=0) + Accumulate[Transpose[a]] show() # as normal + ListPlot[{Transpose[{x1, y1}], Transpose[{x2, y2}]}] plot, x1, y1 oplot, x2, y2 @@ -3147,6 +3300,7 @@ R> meshgrid(1:5,10:12) subplot(211) + GraphicsGrid[...] !p.multi(0,2,1) @@ -3160,6 +3314,9 @@ R> meshgrid(1:5,10:12) plot(x,y,color='r',marker='o') --> + ListLinePlot[Transpose[{x, y}], + PlotStyle -> {Hue[0.63, 0.66, 0.64], Dashing -> Medium}, + PlotMarkers ]]> {Automatic, 12}] plot, x,y, line=1, psym=-1 @@ -3184,6 +3341,7 @@ R> meshgrid(1:5,10:12) plot(c(1:10,10:1), asp=1) figure(figsize=(6,6)) + ListPlot[z, AspectRatio -]]> 1] set size ratio -1 @@ -3218,6 +3376,7 @@ R> meshgrid(1:5,10:12) xlabel('x-axis') ylabel('y-axis') + Plot[...,Frame-]]>True,FrameLabel-]]>{x,y}]> plot(1:10, main="title", xlab="x-axis", ylab="y-axis") @@ -3254,6 +3413,7 @@ R> meshgrid(1:5,10:12) semilogy(a) plot(x,y, log="y") semilogy(a) + ListLogPlot[a] plot, x,y, /YLOG plot_io, x,y @@ -3265,6 +3425,7 @@ R> meshgrid(1:5,10:12) semilogx(a) plot(x,y, log="x") semilogx(a) + ListLogLinearPlot[a] plot, x,y, /XLOG plot_oi, x,y @@ -3276,6 +3437,7 @@ R> meshgrid(1:5,10:12) loglog(a) plot(x,y, log="xy") loglog(a) + ListLogLogPlot[a] plot_oo, x,y @@ -3793,6 +3955,7 @@ R> meshgrid(1:5,10:12) Set unique unique(a) + DeleteDuplicates[a] unique(a) for(i in 1:5) print(i) for i in range(1,6): print(i) + For[i=0,i6,i++,Print[i]] for k=1,5 do print,k @@ -4453,6 +4656,9 @@ R> polyval(c(1,2,1,2),1:10) should work. print(i) print(i*2) + + For[i=0,i5,i++,Print[i];Print[i i]] + for k=1,5 do begin $ @@ -4490,12 +4696,15 @@ endwhile 0) a <- 100]]> if 1>0: a=100 + If[1]]>0,a=100] if 1 gt 0 then a=100 if-else-statement if 1>0 a=100; else a=0; end + if 1>0: a=100 else: a=0 + If[1]]>0,a=100, a=0] if 1 gt 0 then a=100 else a=0 @@ -4539,6 +4748,7 @@ a <- switch(as.character(i),"1"=66, "5"=77, -99) Most recent evaluated expression ans + % .Last.value % % @@ -4554,6 +4764,7 @@ a <- switch(as.character(i),"1"=66, "5"=77, -99) Clear variable $x$ from memory clear xclear [all] + Clear[x] rm(x) )clear properties x @@ -4563,6 +4774,7 @@ a <- switch(as.character(i),"1"=66, "5"=77, -99) disp(a) print(a) print a + Print[a] print, a @@ -4599,6 +4811,7 @@ a <- switch(as.character(i),"1"=66, "5"=77, -99) dir() os.listdir(".") + FileNames[] dir @@ -4607,6 +4820,7 @@ a <- switch(as.character(i),"1"=66, "5"=77, -99) what list.files(pattern="\.r$") grep.grep("*.py") + FileNames[{"*.wl","*.nb"}] @@ -4614,6 +4828,7 @@ a <- switch(as.character(i),"1"=66, "5"=77, -99) pwd getwd() os.getcwd() + Directory[] pwd sd @@ -4624,6 +4839,7 @@ a <- switch(as.character(i),"1"=66, "5"=77, -99) chdir('foo') setwd('foo') os.chdir('foo') + SetDirectory["foo"] cd 'foo' cd,'foosd,'foo )cd "foo" @@ -4638,7 +4854,9 @@ a <- switch(as.character(i),"1"=66, "5"=77, -99) os.system('notepad') os.popen('notepad') + subprocess.call(['notepad']) + RunProcess["command"] !notepad spawn,'notepad'