wolfram-mathematica

Compute average distance from point to line segment and line segment to line segment

时间秒杀一切 提交于 2019-12-21 17:07:56
问题 I'm searching for an algorithm to calculate the average distance between a point and a line segment in 3D. So given two points A(x1, y1, z1) and B(x2, y2, z2) that represent line segment AB, and a third point C(x3, y3, z3), what is the average distance between each point on AB to point C? I'm also interested in the average distance between two line segments. So given segment AB and CD, what is the average distance from each point on AB to the closest point on CD? I haven't had any luck with

Cryptographic hash (sha1 or md5) of data given as a string in Mathematica

北战南征 提交于 2019-12-21 17:00:51
问题 The sha1 hash of "abc" is a9993e364706816aba3e25717850c26c9cd0d89d The only way to get Mathematica to tell you that with its Hash function is Hash[abc, "SHA"] // IntegerString[#, 16]& (The IntegerString thing is just to output it in hex like most implementations do.) Note that Hash["abc", "SHA"] gives the hash of "\"abc\"" -- not what you want! In fact, the only reason we could get the correct hash of "abc" was because the Mathematica representation of the symbol abc happens to be the string

Photo Mosaic in Mathematica: an example from 2008 doesn't work in Mathematica 8

两盒软妹~` 提交于 2019-12-21 16:18:53
问题 I'm trying to get a Mathematica example working. It's the one on Theo Gray's blog. I think that Mathematica must have changed since he wrote that code (May 2008), since I'm unable to get anything reasonable out of it, despite changing nearly everything. Do I use ImageData instead of Import? Can anyone suggest a version of this code that works for Mathematica 8? imagePool = Map[With[{i = Import[#]}, {i, Mean[Flatten[N[i[[1, 1]]], 1]]}] &, FileNames["Pool/*.jpg"]]; closeMatch[c_] :=

Photo Mosaic in Mathematica: an example from 2008 doesn't work in Mathematica 8

主宰稳场 提交于 2019-12-21 16:18:08
问题 I'm trying to get a Mathematica example working. It's the one on Theo Gray's blog. I think that Mathematica must have changed since he wrote that code (May 2008), since I'm unable to get anything reasonable out of it, despite changing nearly everything. Do I use ImageData instead of Import? Can anyone suggest a version of this code that works for Mathematica 8? imagePool = Map[With[{i = Import[#]}, {i, Mean[Flatten[N[i[[1, 1]]], 1]]}] &, FileNames["Pool/*.jpg"]]; closeMatch[c_] :=

How to import data from a file as list/array in Mathematica

爷,独闯天下 提交于 2019-12-21 13:20:11
问题 I have data(points) that I have to import from another program to Mathematica, so I can plot it. I have control on how the points are going to be written to the file, so I can put them in any way I want. What is the best way to import them to Mathematica? As I'm going to use StreamDensityPlot, the variable I'll have to pass to StreamDensityPlot will have to be in the following way: data = { { { a, b, c }, {a, b, c}, {a, b, c}, { a, b, c }, {a, b, c}, {a, b, c}, { a, b, c }, {a, b, c}, {a, b,

A problem in Mathematica 8 with function declaration

删除回忆录丶 提交于 2019-12-21 12:31:46
问题 This is a strange result with a function defined as "functionB" in this example. Can someone explain this? I want to plot functionB[x] and functionB[Sqrt[x]] , they must be different, but this code shows that functionB[x] = functionB[Sqrt[x]] , which is impossible. model = 4/Sqrt[3] - a1/(x + b1) - a2/(x + b2)^2 - a3/(x + b3)^4; fit = {a1 -> 0.27, a2 -> 0.335, a3 -> -0.347, b1 -> 4.29, b2 -> 0.435, b3 -> 0.712}; functionB[x_] := model /. fit Show[ ParametricPlot[{x, functionB[x]}, {x, 0, 1}],

Exporting sounds as WAV files

社会主义新天地 提交于 2019-12-21 11:23:10
问题 I never worked too much with sounds in Mma. I have t = Sound[List["Violin",SoundNote[-6]]] How could I Export t as a .WAV file? When I try the obvious Export["c:\\test.wav",t] I get In this old thread Szabolcs said that it can't be done. Perhaps things have improved since 2007! 回答1: I think that it still can't be done. Mathematica supports creating and modifying MIDI objects, but leaves the sound generation from the midi to the underlying operating system. For now, you'll have to export to

Coloring specific points with a different color in Mathematica

久未见 提交于 2019-12-21 09:29:35
问题 The output of the Mathematica command ListPointPlot3D[ Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}], PlotStyle -> PointSize[0.02]] is the following image. I want to color the points (0,0) and (1,2) with the color red. How do I modify the above command for this? 回答1: A very simple and straightforward way would be: list = Join @@ Table[{x, y, 0}, {x, -6, 6, 1}, {y, -6, 6, 1}]; pts = {{0, 0, 0}, {1, 2, 0}}; ListPointPlot3D[{Complement[list, pts], pts}, PlotStyle -> PointSize[0.02]] Of

How do I combine the graphic of a ListPlot with the graphic of a Plot?

痞子三分冷 提交于 2019-12-21 07:19:13
问题 Is there a way to combine the graphic of a ListPlot to the graphic of a Plot ? (I need to plot a graphic of a function on the graphic of a ListPlot) 回答1: You can combine any graphics with the Show function like so: Show[myListPlot, myPlot] This generalizes to combining any number of plots at once: Show[p1, p2, p3, p4, ...] or Show[{p1,p2,p3,p4,...}] Reference and image source: http://reference.wolfram.com/mathematica/ref/Show.html You can use Epilog as well if Show is not stacking the

Proper way to simplify integral result in Mathematica given integer constraints

耗尽温柔 提交于 2019-12-21 07:14:17
问题 Evaluating the following integral should be non-zero, and mathematica correctly gives a non-zero result Integrate[ Cos[ (Pi * x)/2 ]^2 * Cos[ (3*Pi*x)/2 ]^2, {x, -1, 1}] However, attempting a more general integral: FullSimplify[ Integrate[Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/2], {x, -1, 1}], Element[{m, n}, Integers]] yields zero, which is definitely not true for m = n = 1 I'd expect a conditional expression. Is it possible to "tell" mathematica about my constraints on