wolfram-mathematica

Compute distance in Cartesian Coordinate System in Mathematica

北城以北 提交于 2019-12-07 06:04:18
问题 Analyzing Eye-movements on a screen, I set my origin to the bottom left corner of it (Hard to modify at that point). Trying to compute distance between some points and the center of the screen I use the simple formula displayed below. Problem is that using this in conditional statement, it gets ugly. Sqrt[ ( (fixationX - centerX)^2 + (fixationY - centerY)^2 ) ] Is there a way to customize Norm to compute distance between points and not between a point and the origin ? Or in my case, set the

Different results using f@expr and expr // f in Mathematica

余生长醉 提交于 2019-12-07 05:25:38
问题 I was playing around with the Prefix and Postfix operators ( @ and // respectively) and I ran into the following issue. Given the following code, they evaluate in the same exact way: Hold[MatrixPlot@Sort@data] // FullForm (* Hold[MatrixPlot[Sort[data]]] *) Hold[data // Sort // MatrixPlot] // FullForm (* Hold[MatrixPlot[Sort[data]]] *) However, given the following expressions, I get different results: FunctionExpand@Abs'[0] (* Abs'[0] *) Abs'[0] // FunctionExpand (* 0 *) I'm not quite sure

How can I constrain locators to a limited (but not regular) set of positions?

a 夏天 提交于 2019-12-07 04:51:45
问题 In Mathematica, locators can be constrained to certain screen regions via the parameters of LocatorPane (See LocatorPane documentation.) A list of three ordered pairs {{{minX, minY}, {maxX, maxY}, {dX, dY}}} is usually the key to determining the behavior of locators. {minX, minY} and {maxX, maxY} set the region. {dX, dY} sets the jump size: zero for unrestrained, any other positive number for the size of each hop. In the code below, {{{-.9, 0}, {1, 0}, {0, 0}}} sets the region and jumps for

is it possible to use second argument of Dynamic in setting up control variables inside Manipulate?

一世执手 提交于 2019-12-07 04:24:49
问题 I can't get the syntax to do what I want, and I am now not sure if it is even possible. small review: One can do this: {Slider[Dynamic[b], {-2 Pi, 2 Pi}], Dynamic[Sin[b]]} and now each time the slider moves, 'b' changes, and its Sin[] is automatically printed But suppose I want to do the computation (Sin[]) directly where the slider is and only show the final result of Sin[], then I can use the second argument of Dynamic like this: {Slider[Dynamic[b, (b = #; a = Sin[b]; #) &], {-2 Pi, 2 Pi}],

Viewing a city's coordinates from above

此生再无相见时 提交于 2019-12-07 04:20:47
问题 As a little project I've been thinking to create a little Google Earth-like animation. I want to play back a timeline while rotating the globe to center over various cities. At present I can use the default view settings to render a globe with the cities indicated by points. When I try to orient the camera with a view vector looking down on a city (for example Denver), I end up with the following: The ViewVector needs to be computed for some point out in space above the globe. However my

Motorsport Lap Chart using ListLinePlot

家住魔仙堡 提交于 2019-12-07 03:27:25
问题 I'm trying to take a table of motorsport lap positions and plot a lap chart similar to this http://www.fia.com/en-GB/sport/championships/f1/2010/bahrain/Pages/lap_chart.aspx. Each row corresponds to a lap, with the first lap in the first row. The car numbers are listed across each row in the order they pass the start/finish line The table may look like this (4-car race, 6 laps: 1 3 2 4 1 3 2 4 1 3 4 2 3 1 4 2 3 1 4 2 3 4 1 2 In the above example, the order was 1,3,2,4 after the first lap, and

How to obtain accurate plot curves in Mathematica?

孤者浪人 提交于 2019-12-07 03:14:43
问题 Run the following code In Mathematica: r=6197/3122; p[k_,w_]:=Sqrt[w^2/r^2-k^2];q[k_,w_]:=Sqrt[w^2-k^2]; a[k_,w_,p_,q_]:=(k^2-q^2)^2 Sin[p]Cos[q]+4k^2 p q Cos[p]Sin[q] a[k_,w_]:=a[k,w,p[k,w],q[k,w]]; ContourPlot[a[k,w]==0,{w,0,6},{k,0,14}] This gives me very inaccurate curves: I have tried setting the PlotPoints and WorkingPrecision options of ContourPlot to 30 and 20 respectively, to no avail. You will also notice that the only numerical parameter, r , is an exact rational number. I don't

Mathematica: Can I match the BarChart Legend to the stacked bars?

♀尐吖头ヾ 提交于 2019-12-07 02:29:03
问题 I would like to have the vertical arrangement of colors in stacked bars match the arrangement of colors in the chart legend. But no matter what I try, they don't match. Here's the situation BarChart[{{5, 37, 56}, {22, 49, 28}, {31, 60, 10}}, ChartLayout -> "Percentile", ChartLegends -> Placed[{"1-Volume", "2-Area", "3-Length"}, Right], ChartLabels -> {{"Before", "During", "After"}, None}] In the real-world example the legend has quite a few more entries (6), so it would be nice if the order

Applying transformation of `GatherBy` to a different list

霸气de小男生 提交于 2019-12-07 01:46:44
问题 I have listA and listB of the same size. I'm doing GatherBy on listA , which rearranges that list. What is an elegant way to apply identical rearrangement to listB ? For example listA = {1, 2, 3}; listB = {a, b, c}; listA1 = GatherBy[{1, 2, 3}, OddQ]; listB1 should become {{a, c}, {b}} Update Thanks for interesting ideas, I eventually ended up doing something similar to belisarius. This reminds me of Python's "decorate-sort-undecorate" pattern decorated = Thread[{listA, listB}]; grouped =

How to show the animation control by default

南笙酒味 提交于 2019-12-07 01:22:49
问题 In this simple control object in mathematica like the following, Control[{x, 0, 1}] we have to bring the mouse pointer to the right upper corner of the object to get the hint called "Show Animation Controls" and then click it to see the animation controls like play, step forward etc. Is there a way by setting some options to get all the animation controls OPEN by default so that when one opens a notebook containing dynamic object the animation controls remains open? Anybody knows such a magic