wolfram-mathematica

How to create a Mathematica Notebook in Java?

和自甴很熟 提交于 2019-12-01 08:06:21
I am looking for the prototypical 'Hello World' program that creates a Mathematica Notebook file. I have this working program. 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'");

Table[ ] Output Cardinality

南楼画角 提交于 2019-12-01 08:04:30
The Table[ ] command usually returns a list with the same cardinality of its iterator. Table[i, {i,4}] (* ->{1,2,3,4} *) It is easy to show that is possible to return a list with a greater cardinality than the iterator Table[Sequence @@ ConstantArray[1, i], {i, 2}] (* ->{1,1,1} *) But ... Are there ways to return a list with LESS cardinality than the iterator? A simple example: Table[Sequence @@ ConstantArray[1, i - 1], {i, 2}] Out[1] = {1} This need not always return a list with smaller cardinality. For e.g., {i,3} returns equal and {i,4} returns more. Or an even sillier example would be

Accidental shadowing and `Removed[symbol]`

僤鯓⒐⒋嵵緔 提交于 2019-12-01 07:54:46
If you evaluate the following code twice, results will be different. Can anyone explain what's going on? findHull[points_] := Module[{}, Needs["ComputationalGeometry`"]; ConvexHull[points] ]; findHull[RandomReal[1, {10, 2}]]; Remove["Global`ConvexHull"]; findHull[RandomReal[1, {10, 2}]] Janus The problem is that even though the module is not evaluated untill you call findHull , the symbols are resolved when you define findHull (i.e.: The new downvalue for findHull is stored in terms of symbols, not text). This means that during the first round, ConvexHull resolves to Global`ConvexHull because

Controlling the Rasterize[] width for notebook-related expressions

喜夏-厌秋 提交于 2019-12-01 07:41:32
Update Mr Wizard's answer gives pixel-perfect results, but it is Windows-only and destroys the clipboard contents. My answer should work on any platform, but it's less precise: e.g. it omits In/Out labels. It does allow setting the rasterization width though. This problem came up when I was trying to make a preview window for an image uploader (see the end of that answer). I would like to create a palette button that will upload the current notebook selection as an image. Before uploading, I would like to show a preview of the image, to reduce the chance of something going awry before

Mathematica output formatting

心不动则不痛 提交于 2019-12-01 07:34:26
问题 How does Mathematica decide when to round numbers in its output? For example, giving the input 250000.5 gives the output 2500001 While 25000.5 is indeed printed as 25000.5 N[] isn't helpful here either, I need to use NumberForm[] to get it to actually print 250000.5 as 250000.5 I'm a Mathematica newbie, and I'm sure its ridiculously easy to control this threshold for when it starts ignoring decimals in its output, but could somebody please point me in the right direction? 回答1: In the default

Why is a big loop within a small loop faster than a small loop within a big one?

北城以北 提交于 2019-12-01 07:14:38
This is my Perl code $big=10_000_000; #A:big loop outside my $begin_time = time; foreach my $i (1..$big) { foreach my $p (1..10){ } } my $end_time = time; my $t1=$end_time-$begin_time; #B:small loop outside my $begin_time = time; foreach my $i (1..10){ foreach my $p (1..$big){ } } my $end_time = time; my $t2=$end_time-$begin_time; #output print $t1; print "\n"; print $t2; t1=8 seconds t2=3 seconds And the mathematica code: Timing[Do[2, {i, 1, 10}, {j, 2*1, 10^7}]] output:{14.328, Null} Timing[Do[2, {j, 1, 2*10^7}, {i, 1, 10}]] output:{30.937, Null} Why does the big loop outside take more time?

Table[ ] Output Cardinality

我只是一个虾纸丫 提交于 2019-12-01 07:12:14
问题 The Table[ ] command usually returns a list with the same cardinality of its iterator. Table[i, {i,4}] (* ->{1,2,3,4} *) It is easy to show that is possible to return a list with a greater cardinality than the iterator Table[Sequence @@ ConstantArray[1, i], {i, 2}] (* ->{1,1,1} *) But ... Are there ways to return a list with LESS cardinality than the iterator? 回答1: A simple example: Table[Sequence @@ ConstantArray[1, i - 1], {i, 2}] Out[1] = {1} This need not always return a list with smaller

How to create a Mathematica Notebook in Java?

喜夏-厌秋 提交于 2019-12-01 07:09:34
问题 I am looking for the prototypical 'Hello World' program that creates a Mathematica Notebook file. I have this working program. 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(

ConvexHull in Graphics - Mathematica

你离开我真会死。 提交于 2019-12-01 06:39:04
Trying to plot a ConvexHull Using PlanarGraphPlot from the ComputationalGeometry package, it does not work when used in graphics. Any Idea on how to plot the ConvexHull using Graphics ? Needs["ComputationalGeometry`"] pts = RandomReal[{0, 10}, {60, 2}]; Graphics[ { Point@pts, FaceForm[], EdgeForm[Red], Polygon@pts[[ConvexHull[pts]]] } ] or cpts = pts[[ConvexHull[pts]]]; AppendTo[cpts, cpts[[1]]]; Graphics[ { Point@pts, Red, Line@cpts } ] Not sure exactly what is wanted. Maybe the code below will get you started. pts = RandomReal[{-10, 10}, {20, 2}] (* Out[1]= {{1.7178, -1.11179}, {-7.10708, -8

Accidental shadowing and `Removed[symbol]`

大城市里の小女人 提交于 2019-12-01 05:49:42
问题 If you evaluate the following code twice, results will be different. Can anyone explain what's going on? findHull[points_] := Module[{}, Needs["ComputationalGeometry`"]; ConvexHull[points] ]; findHull[RandomReal[1, {10, 2}]]; Remove["Global`ConvexHull"]; findHull[RandomReal[1, {10, 2}]] 回答1: The problem is that even though the module is not evaluated untill you call findHull , the symbols are resolved when you define findHull (i.e.: The new downvalue for findHull is stored in terms of symbols