我有一段时间有这个问题.只是想知道这样做的最佳方式(效率和优雅)是什么.我能想到的方法是使用RandomPermutation随机化列表的索引,然后从列表中选择第一个m(当然需要小于列表的长度)元素.但这需要Combinatorica包装.
有更好的选择吗?
谢谢.
考虑:
ListPlot[Range[10],
Background -> Gray,
PlotLabel -> "I don`t want the background here !"]
Run Code Online (Sandbox Code Playgroud)

有没有办法让背景仅适用于实际的绘图区?
不在轴上,不在标签后面.那么基本上就是那个矩形{{0,0},{10,10}}?
编辑:我们可以使用PolarListPlot做同样的事情吗?
使用Mathematica在笛卡尔图上使用Sjoerd解决方案 到极坐标直方图:
dalist = {{21, 22}, {26, 13}, {32, 17}, {31, 11}, {30, 9},
{25,12}, {12, 16}, {18, 20}, {13, 23}, {19, 21},
{14, 16}, {14,22}, {18, 22}, {10, 22}, {17, 23}}
ScreenCenter = {20, 15}
ListPolarPlot[{ArcTan[##],EuclideanDistance[##]} & @@@ (# - ScreenCenter & /@ dalist),
PolarAxes -> True, PolarGridLines -> Automatic, Joined -> False,
PolarTicks -> {"Degrees", Automatic},
BaseStyle -> …Run Code Online (Sandbox Code Playgroud) 我想创建的汉克尔功能,在n阶导数的定义的列表,但第N阶导数获得了在该文档下"的未知函数导"中描述的方式进行处理,并留下未评估.这是一个例子:
Clear[x, gaussianExponential]
gaussianExponential[x_] := Exp[- x^2]
FullSimplify[Derivative[2][gaussianExponential[x]]]
Run Code Online (Sandbox Code Playgroud)
我得到:(E ^ -x ^ 2)^ [Prime] [Prime]
(而不是看到评估的衍生物(并且最终表达式未被简化)).
知道这里发生了什么吗?
这是一个功能,使用了几天前我问过的问题答案的建议.让我们在Mathematica中创建一个Graphics3D对象.我从这里使用这个3D几何数据.
cd = Import[NotebookDirectory[] <> "withwake.obj"];
vertices = cd[[1, 2, 1]];
polygons = Flatten[cd[[1, 2, 2, 1]] /. Polygon -> List, 2];
Graphics3D[GraphicsComplex[vertices, Polygon[polygons]]]
Run Code Online (Sandbox Code Playgroud)

对于每个多边形,我们创建一个指向其顶点的数字列表,然后是指向每个边连接到的多边形的数字.重要的是要注意表面正常; 定义面板的节点顺序应为逆时针.通过右手规则,如果手指弯曲以跟随编号,拇指将显示应指向"向外"几何的法线向量.
如果Graphics3D对象中的所有多边形都是三角形,则此函数会创建此类列表.
EdgeSorting[vertices_, polygons_] :=
Block[{triangleEdges, singleEdges, edgesNeighbors, relations, n, n1,
n2, trires, triangleNeigbours, TriangleMaker, polygonArea, tring},
(*Split every triangle in 3 edges,with nodes in each edge sorted*)
triangleEdges = (Sort /@ Subsets[#, {2}]) & /@ polygons;
(*Generate a list of edges*)
singleEdges = Union[Flatten[triangleEdges, 1]];
(*Define a function …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个Mathematica脚本,它将两个变量的函数作为输入,然后以详细的方式计算所有必要的步骤(找到第一个偏导数的根,检查相关的二阶条件)(例如,显示全部寻找局部极值点的偏导数.
大部分都是直截了当的,我最大的问题是如何重用Solve[]连续计算中找到的根.我开始是这样的:
f[x_,y_] := y^3 -3 x^2 y
dfx[x_,y_]:=D[f[x,y],x]
dfy[x_,y_]:=D[f[x,y],y]
dfxx[x_,y_]:=D[f[x,y],x, x]
dfyy[x_,y_]:=D[f[x,y],y, y]
dfx[x_,y_]:=D[f[x,y],x]
dfxy[x_,y_]:=D[f[x,y],x,y]
dff[x_,y_]:=dfxx[x,y]*dfyy[x,y]-(dfxy[x,y])^2
Solve[{dfx[x,y]==0, dfy[x,y]==0},{x,y}]
Apply[dff, %]
Evaluate[dff[%]]
Run Code Online (Sandbox Code Playgroud)
我被困在这里,任何帮助都会很棒!
我必须编写一个算法来找到矩阵的行列式,这是通过递归函数完成的:

A_ij矩阵在哪里,当你删除第ith行和第jth列时出现A.当A有维n x n,那么对于尺寸A_ij为(n-1) x (n-1).我不允许使用Minor[]或Det[].
我该如何编写这个算法?
这是我到目前为止的代码:
det1[Mi_ /; Dimensions[Mi][[1]] == Dimensions[Mi][[2]]] :=
Module[{det1},
det1 = Sum[
If[det1 == 1, Break[], (-1)^(1 + j) *Mi[[1, j]]*det1[Drop[Mi, {1}, {j}]]],
{j, 1, Length[Mi]}];
Return[det1 // MatrixForm, Module]
]
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个条件表达式来初始化一些函数,变量等.在C中看起来像这样的东西:
#if option==1
int foo(int x){/*some code here*/}
int q=10;
#else
char foo(int x){/*some other code*/}
double q=3.141592;
#endif
use_q(q);
f(some_var);
Run Code Online (Sandbox Code Playgroud)
在Mathematica中,我尝试过使用If,像这样:
If[option==1,
foo[x_]=some_expression1;
q=10;
,
foo[x_]=some_expression2;
q=3.141592;
]
use_q[q];
f[some_var];
Run Code Online (Sandbox Code Playgroud)
但结果是函数的参数被涂成红色,并且在If中没有任何内容被初始化或计算.那么,我该怎样做才能获得有条件的"编译"?
以下代码无缝执行
wave = HaarWavelet[];
type = "PrimalLowpass";
h = WaveletFilterCoefficients[
wave, type,
WorkingPrecision -> \[Infinity]
];
h = Flatten[
Take[h,
Range[1, Length[h]],
Table[2, {Length[h]}]
]
]
Run Code Online (Sandbox Code Playgroud)
但是当它包裹在一起时Module会出错.考虑这个功能
getWaveletFilter[wave_, type_]:=
Module[{filter}, (* treated as local *)
filter = WaveletFilterCoefficients[
wave, type, WorkingPrecision -> \[Infinity]
]
filter = Flatten[
Take[filter,
Range[1, Length[filter]],
Table[2, {Length[filter]}]
]
]
filter
]
Run Code Online (Sandbox Code Playgroud)
我想getWaveletFilter[HaarWavelet[], "PrimalHighpass"]
回来
{1/2, -1/2}
Run Code Online (Sandbox Code Playgroud)
相反,Mathematica有各种各样的抱怨.有什么建议吗?
注意: 对于那些无法做出比无聊,无知的评论甚至是关闭有效问题的建议更好的人,请在此处查看接受的答案:使用GNU/Linux系统调用`splice`进行零拷贝Socket to Socket Haskell中的数据传输是如何为那些真正寻求建设性答案的人提供适当帮助的一个很好的例子!
嗨,我刚刚阅读PowerMod了Mathematica 8的文档,想要测试Haksell RSA包(ghc --make -O2 -O3 -fllvm -optlo-O3 test.hs):
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad
import System.Random
import Codec.Crypto.RSA
import Data.ByteString.Lazy
import Data.ByteString.Char8
import Criterion.Main
import Criterion.Config
main :: IO ()
main = do
print m1
print m4
print m8
defaultMainWith defaultConfig (return ()) [
bgroup "RSA" [
bench "1" $ ed m1
, bench "4" $ ed m4
, bench "8" $ …Run Code Online (Sandbox Code Playgroud) 我想PlotLegend在剧情的右上角有一个,但是这个选项不起作用.
我该怎么加入PlotLegend我的Plot?我应该买Mathematica 8吗?
u=Sech[x];
w=Cos[x];
v=Sin[x]^2;
Plot[{u,w,v},{x,-5,5},PlotStyle->{Automatic,Dashed,DotDashed},
PlotLegend->{"Sech[x]","Cos[x]","Sin[x]"}]
Run Code Online (Sandbox Code Playgroud)