wolfram-mathematica

Viewing a city's coordinates from above

和自甴很熟 提交于 2019-12-05 09:28:34
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 trial and error has not arrived on any sort of coherent viewpoint with most looking like they're "inside"

Tweaking style/attributes of existing Graphics objects in Mathematica

狂风中的少年 提交于 2019-12-05 09:27:30
One of Mathematica's strengths is its consistent underlying representation of objects. Thus, to change attributes of a plot without redoing the computation used to generate it, I could do something like Replace[myplot, {Graphics[x_List, y_List] :> Graphics[x,Flatten[{y, BaseStyle -> {FontFamily -> Helvetica, FontSize -> 20}}]]}] Unfortunately, every time I want to use this approach to modify a plot in order to change the style/color of lines, points, fonts, etc. I have to figure out what the appropriate replacement rule is by trial and error, which negates any efficiency gained by not having

Using Mathematica Gather/Collect properly

那年仲夏 提交于 2019-12-05 08:34:49
How do I use Mathematica's Gather/Collect/Transpose functions to convert: { { {1, foo1}, {2, foo2}, {3, foo3} }, { {1, bar1}, {2, bar2}, {3, bar3} } } to { {1, foo1, bar1}, {2, foo2, bar2}, {3, foo3, bar3} } EDIT: Thanks! I was hoping there was a simple way, but I guess not! Here is your list: tst = {{{1, foo1}, {2, foo2}, {3, foo3}}, {{1, bar1}, {2, bar2}, {3, bar3}}} Here is one way: In[84]:= Flatten/@Transpose[{#[[All,1,1]],#[[All,All,2]]}]&@ GatherBy[Flatten[tst,1],First] Out[84]= {{1,foo1,bar1},{2,foo2,bar2},{3,foo3,bar3}} EDIT Here is a completely different version, just for fun: In[106]

Is it possible to rename and block built-in functions temporarily?

拥有回忆 提交于 2019-12-05 08:32:50
I wish to temporarily rename a built-in symbol and use it with different name while block the main name of this symbol. For example, I wish the following code to print only "2" but not "1" and "3": Block[{print = Print, Print}, Print[1]; print[2]; Print[3];] In really the above code prints nothing. Is it possible to make print working inside such code while completely block symbol Print ? Solutions like With[{Print = f, print = Print}, Print[1]; print[2]; Print[3];] are not suitable since Print is not really blocked inside such code. The question appeared while thinking on a way to disable

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

大兔子大兔子 提交于 2019-12-05 08:31:37
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}], Dynamic[a]} Now I want to use Manipulate, and do the same thing. I can do the same as the first

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

落花浮王杯 提交于 2019-12-05 08:17:55
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 of the legend colors matched the order in the bars. I realize that I could set the ChartLegends to

Mathematica: Evaluation order during numerical optimisation of black box functions

给你一囗甜甜゛ 提交于 2019-12-05 07:22:35
I am attempting to perform a numerical optimisation of a "black box" function in Mathematica. Schematically it goes like this: NMinimize[{comb[x,y,z], x > 0}, {x,y,z}] where comb[x,y,z] is defined similarly to this: comb[x_,y_,z_] := Module[{}, Print[x,y,z]; M = FindMaximum[SkewNormal[a,x,y,z], {a,x}] // First; val = f[x,y,z,M]; Return[val]; ]; However, all of the minimisation functions I have tried seem to not immediately provide comb[x,y,z] with numerical values, and it ends up trying to evaluate the FindMaximum with symbolic values for x,y,z (which is easily verified because the Print[x,y,z

How to obtain accurate plot curves in Mathematica?

╄→尐↘猪︶ㄣ 提交于 2019-12-05 07:15:37
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 know what else to try. Thanks. Edit: The curves I expect to get are the three black ones (marked A1, A2,

Motorsport Lap Chart using ListLinePlot

走远了吗. 提交于 2019-12-05 06:09:26
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 by the end of the 6-lap race, car 3 won, car 4 was in second, and so on. It's easy to plot this

What is the Computational Complexity of Mathematica's CylindricalDecomposition

血红的双手。 提交于 2019-12-05 05:53:21
Mathematica' CylindricalDecomposition implements an algorithm known as Cylindrical Algebraic Decomposition. Wolfram MathWorld's article on Cylindrical Algebraic Decomposition says that this algorithm "becomes computationally infeasible for complicated inequalities." Can this statement be made more precise? Specifically, how does the time and space relate to the degree and number of variables of the multivariate polynomials? Does the time and space depend on other parameters? Tarski showed that for every formula including quantifiers there is always an equivalent quantifier free formula.