下面的Mathematica函数f创建一个长度为n的空格字符串.
f[n_]:=Fold[StringJoin,"",Array[" "&,n]]
Run Code Online (Sandbox Code Playgroud)
创建此功能必须有多种选择.
你会怎么做的?
示例和背景(注意Hold,ReleaseHold的用法):
以下代码表示用于创建scenegraph对象的静态工厂方法(来自XML文件).(output-)字段是CScenegraph(OO-System类)的一个实例.
new[imp_]:= Module[{
ret,
type = "TG",
record ={{0,0,0},"Root TG"}
},
ret = MathNew[
"CScenegraph",
2,
MathNew["CTransformationgroup",1,{type,record},0,0,0,0,Null]];
ret@setTree[ret];
ret@getRoot[]@setColref[ret];
csp = loadClass["CSphere"];
spheres = Cases[imp, XMLElement["sphere", _, __], Infinity];
codesp = Cases[spheres, XMLElement["sphere",
{"point" -> point_, "radius" -> rad_, "hue" -> hue_}, {}] -> Hold[csp@new[ToExpression[point], ToExpression[rad], ToExpression[hue]]]];
ret@addAschild[ret@getRoot[],ReleaseHold[codesp]];
ret
];
Run Code Online (Sandbox Code Playgroud)
我的问题是关于以下内容:
spheres = Cases[imp, XMLElement[\sphere\, _, __], Infinity];
codesp = Cases[spheres, XMLElement[\sphere\,
{\point\ -> point_, \radius\ -> rad_, \"hue\" -> hue_}, {}] -> Hold[csp@new[ToExpression[point], ToExpression[rad], ToExpression[hue]]]];
ret@addAschild[ret@getRoot[],ReleaseHold[codesp]];
Run Code Online (Sandbox Code Playgroud)
哪里
addAschild …Run Code Online (Sandbox Code Playgroud) 背景:另见:http://mathworld.wolfram.com/TruthTable.html
Mathematica提供以下功能.
TruthTable[op_, n_] :=
Module[{l =
Flatten[Outer[List, Sequence @@ Table[{True, False}, {n}]],
n - 1], a = Array[A, n]},
DisplayForm[
GridBox[Prepend[Append[#, op @@ #] & /@ l, Append[a, op @@ a]],
RowLines -> True, ColumnLines -> True]]]
Run Code Online (Sandbox Code Playgroud)
我打印了一张nand表如下:
TruthTable[Not[And[#1, #2]] &, 2]
A[1] A[2] !(A[1]&&A[2])
True True False
True False True
False True True
False False True
Run Code Online (Sandbox Code Playgroud)
这是预期的,除了标题,我想用P,Q或A,B作为变量.
为了解决
x^2 == 123456 mod 1299709
Run Code Online (Sandbox Code Playgroud)
在Mathematica我使用过:
Reduce[x^2 == 123456 + 1299709 k, {x, k}, Integers]
Run Code Online (Sandbox Code Playgroud)
这产生了正确的答案.
问题:减少求解二次同余方程的最佳方法(性能,优雅或其他方法)?
我想以适当的方式为Mma函数设置别名.
目前,我将几个别名复制并粘贴到新笔记本中的单元格中,如:
tf:=TableForm
fi:=FactorInteger
re:=RegularExpression
Run Code Online (Sandbox Code Playgroud)
等等.
当我在doc中搜索别名时,我找到了Esc ... Esc方法的描述,以及有关定义自定义表示法的章节.我想,我希望找到一些用于定义别名的初始化文件.我此刻有些困惑.
问题: - 定义在任何新Notebook中使用的函数别名的常用/正确/最佳方法是什么?
我想将此React.js组件用作ClojureScript应用程序中的外部Reagent组件:
https://github.com/felixrieseberg/React-Spreadsheet-Component.
但是,该组件在存储库中不可用:
如果目录中有React.js组件,那么将它与Reagent一起使用就像在下面的示例中一样简单.
(ns demo.views
(:require [reagent.core :as reagent]
[cljsjs.reactable]])
(defn example []
[:div
[:> Reactable.Table
{:data (clj->js [
{:name "Foo" :section 51}
{:name "Bar" :section 51}
])}
]
]
)
Run Code Online (Sandbox Code Playgroud)
我想知道我将如何处理React Spreadsheet组件,以便我可以以类似的简单方式使用它.如何准备React.js组件以在ClojureScript中用作外部Reagent组件?请提供明确的配方类型的描述.
注意:这个问题如何使用Cactjurescipt/Reagent的ReactJS组件看起来很相似,但没有回答我的问题.
(部分)我使用的对象的矩阵表示如下:
{
{1, A,{100, 20, 30},10},
{2, B,{100}, 0},
{3, X,{120,20},0},
{4, C,{},11}
}
Run Code Online (Sandbox Code Playgroud)
我想以XML格式将这些数据存储在外部,如下所示
<data>
<row key ="1"val1 ="A"val2 ="10"> <occ> 100 </ occ> <occ> 20 </ occ> <occ> 30 </ occ> </ row>
<行密钥= "2" VAL1 = "B" VAL2 = "0"> <OCC> 100 </ OCC> </行>
<行密钥= "3" VAL1 = "X" VAL2 = "0"> <OCC> 120 </ occ> <occ> 20 </ occ> </ row>
<row key ="4"val1 ="C"val2 ="11"> </ row>
</ data>
我正在寻找一个如何:
考虑以下假设的无意义的ClojureScript函数:
(defn tmp []
(def p 0)
(set! p (inc p))
(set! p (inc p))
(set! p (inc p)))
Run Code Online (Sandbox Code Playgroud)
在REPL中重复执行此功能会导致
3
6
9
etc.
Run Code Online (Sandbox Code Playgroud)
是否有可能创建该函数本地的可变变量,以使输出本来可以
3
3
3
etc.
Run Code Online (Sandbox Code Playgroud)
在重复执行(tmp)的情况下?
我正在寻找创建Mathematica Notebook文件的典型"Hello World"程序.
我有这个工作计划.
package graphica;
import com.wolfram.jlink.*;
/**
*
* @author Nilo
*/
public class MathematicaTester {
public static void main(String[] args) {
KernelLink ml = null;
String jLinkDir = "C:\\Program Files\\Wolfram Research\\Mathematica\\8.0\\SystemFiles\\Links\\JLink";
System.setProperty("com.wolfram.jlink.libdir", jLinkDir);
try {
ml = MathLinkFactory.createKernelLink("-linkmode launch -linkname 'C:\\Program Files\\Wolfram Research\\Mathematica\\8.0\\MathKernel.exe'");
ml.discardAnswer();
String expr = "Sum[k^2,{k,1,11}]";
ml.evaluate(expr);
ml.waitForAnswer();
String x = ml.getString();
System.out.println("Result = " + x);
} catch (MathLinkException e) {
System.out.println("Fatal error opening link: " +
e.getMessage());
return;
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到以下-expected-输出.
run: …