I made Monte Carlo simulation of a cone shaped light source - like lighthouse. Then I tried to draw results. I took the points from which the rays have come. Then I tried to draw SmoothDensityHistogram, but I have problems with binning. I know that the most rays came from {0,0,0}, but that is just not obvious from the picture. The center is somehow translated, but it should't be.
Here's a link to picture.
Thanks for help.
try to play with the PlotPoints option. Even value of the parameter could help, even though I cannot reproduce your problem:
tb = Table[{RandomVariate[NormalDistribution[0, 3]],
RandomVariate[NormalDistribution[0, 3]]}, {n, 10000}];
SmoothDensityHistogram[tb, PlotPoints -> 6]
Related
I want to solve the following equation. I want to get an expression of x in terms of unknown constants alpha and beta. Does anyone know how to solve this in Matlab or Mathematica?
Thanks.
Here's my one line code in wolfram Mathematica.
'Assuming[alpha>beta>0,Solve[Cos(alpha*Cos(x)) + Cos(beta*Cos(x)) -1.96 ==0,x]] '
Since it doesn't appear simple to get an analytic solution, perhaps a graphic showing the behavior might provide some insight about what to do next.
ListPointPlot3D[Reap[Do[
{alpha, beta, x} = RandomReal[{0, 2 Pi}, 3];
If[alpha > beta,
err = Norm[Cos[alpha*Cos[x]]+Cos[beta*Cos[x]]-1.96];
If[err < .01, Sow[{alpha, beta, x}]]
],{10^6}]][[2, 1]], ViewPoint->{0, -2., 0}]
Once that displays on your monitor you can either adjust the numbers inside that Viewpoint or you might be able to place your mouse inside the graphic, press and hold the left mouse button and drag to rotate the image around.
That graphic seems to show that the solutions lie within a fairly well defined region.
Once you have looked at this then you might bump the range of the random numbers up to {0,4Pi} because it looks like there is more interesting behavior for larger values of alpha and beta.
I’m learning how to use SphericalPlot3D. I’m using the following statement:
SphericalPlot3D[Cos[θ],{θ,0,π},{ɸ,0,2 π}]
I was expecting to get a cosine curve along y-axis rotated around the same axis. More or less like an hourglass. What I get is a sphere. What do I have to specify in SphericalPlot3D in order to get rotated vertical cosine?
When I use the following statement:
SphericalPlot3D[Cos[2 θ],{θ,0,π},{ɸ,0,2 π}]
I would expect to get 2 hourglasses, one standing on the other along y-axis. I get something different. Where do I go wrong?
Thanks/Mikael
I guess, what you wanted is a surface or revolution with a cosine shape rotated about one axis to get a Hourglass. It is more a Cylindrical plot. The Spherical Plot more or less bends the top and bottom together to form a kind of sphere.
My solution for your problem would be:
RevolutionPlot3D[{Cos[t], t}, {t, 0, π}, {ɸ, 0, 2 π}]
which gives the following plot:
This may be a bit late, but a friend of mine just had the same problem so I thought I'd document the solution somewhere.
The confusion comes from the way in which Mathematica defines θ and φ. In most cases they're defined as follows:
However, Mathematica actually defines θ as what you think should be φ and φ as what you think should be θ for some reason. The following screenshot is taken from the documentation page for SphericalPlot3D explaining these definitions.
A simple fix to this is to swap the way you define the variables when calling SphericalPlot3D. So instead of writing
SphericalPlot3D[Cos[2 θ],{θ,0,π},{ɸ,0,2 π}]
You would want to write:
SphericalPlot3D[Cos[2 θ],{ɸ,0,2 π},{θ,0,π}]
I noticed this fantastic example of D3's cluster layout. Instead of having a bounding box; is it possible to force cluster them into a polygon? http://codepen.io/zslabs/pen/MKaRNJ is an example of the polygon shape, but I'm looking for the added benefit of collision detection as well as a performant way of mapping the data. Thanks so much!
Update
https://github.com/d3/d3-shape looks like an interesting library about creating these shapes, I still have not seen an example of plotting and spreading within a defined polygon.
.
I was also looking for the same thing and I found this similar thread: Force chart d3.js inside a triangle.
The most voted answer has a method to detect collisions inside a triangle and also propose a generalized version to make it work with a polygon. You can see it in this demo.
One thing that the answer does not mention and that might be useful to you is to compute the center of your different polygons in order to make the different force layouts centered inside those polygons and I would suggest to use polygonCentroid for that.
var polygon = require('d3-polygon');
var polygon_data = [ [0,0], [10, 0], [10, 10], [0, 10]]; // a small box
var centroid = polygon.polygonCentroid(polygon_data); // [5, 5]
I would definitely love to see this polygon constraint as a feature in d3 but it may be too specific :/
Update:
Just a small correction: the proprosed solution takes account of the polygon's centroid contrary to what I said. My bad.
Update 2:
I've created a block with an implementation for the polygon collision detection: http://bl.ocks.org/pbellon/4b875d2ab7019c0029b636523b34e074.
It uses the collision detection mentionned in the SO's answer I linked & I used it to create a "force" like forceCollide on d3.v4.
It's not perfect but I had a lot of trouble to tweak the way nodes can be repelled from the polygon's border... If anyone has suggestions I would be happy to hear them!
In order to avoid "retinal persistence" after the presentation of a stimuli, I need to create a visual noise mask.
This for a screen that has a dimension, in pixel of : 1280 * 960
I believe I could randomly (uniform) assign gray shade to pixels but my attempts yet failed.
Thank you for your attention.
Just noticed:
RandomImage[1, {1280, 960}]
New in Mathematica 8, apparently...
Damn, at last a question on Stack Overflow I could have answered and I was too late... :)
Oh well, here's an alternative solution...
ImageEffect[Image[Table[{0.5, 0.5, 0.5}, {i, 1, 960}, {j, 1, 1280}] ], "GaussianNoise"]
Probably got too many colours in it?
ImageEffect also works on greyscale images.
ImageEffect[Image[Table[0.5, {400}, {600}]], "GaussianNoise"]
Did you try looking in the help docs? One of the first examples for Image should have done it.
Image#RandomReal[1, {960, 1280}]
You can specify a different range of values:
Image#RandomReal[{0.4, 1}, {400, 600}]
Others have already shown you ways of creating a random image. In case you were designing your application to use up the full screen (or based on the current screen's dimensions), you might find it convenient to not hard code the values, but to capture the screen size programmatically. Here's an example showing how:
screenSize = Last /# ("FullScreenArea" /.
Flatten#SystemInformation["Devices", "ScreenInformation"]);
RandomImage[1, screenSize]
Is it possible that when I Plot a function in Mathematica, it will automatically put near it it's equation(i.e. y = 2x) or even some other text?
At first glance I don't find any option for it, but if there is one I'd like to know.
Thanks
Using Mathematica 6 or higher, I often use Tooltip to help me identify plot curves:
Plot[Tooltip[Sin[x]], {x, 0, 8 Pi}]
Alas, this is only useful when using the graph interactively since you must hover the mouse cursor over the curve. It doesn't work so well on paper or on a static image.
You can use the Epilog option to manually place some text on the plot, as in this example:
Plot[
Sin[x], {x, 0, 8 Pi},
Epilog -> Text["My Text", Offset[{32, 0}, {14, Sin[14]}]]
]
Tweak the arguments of Offset to taste.
This works if you do not mind manual placement. Automatic placement poses some challenges, depending upon the kinds of functions that you wish to plot. But if you know something of the general characteristics of the functions of interest, you could write a function that calculates nice looking values for the Offset arguments. For example, if I knew I was going to plot lots of exponential decline functions, I might define something like the function myPlot in this example:
SetAttributes[myPlot, HoldAll]
myPlot[function_, {var_, min_, max_}] :=
Plot[
function, {var, min, max},
Epilog -> Text[function, Offset[{40, 0}, {var, function} /. var -> min + (max - min)/20]],
PlotRange -> All, AxesOrigin -> {0, 0}
]
... where the arguments to Offset are computed automatically using some arbitrary constants that work reasonably well for these kinds of plots:
Manipulate[
myPlot[1000 E^(-d t), {t, 0, 100}, "My Label"],
{d, 0.01, .2}
]
Since all of these options are programmable, the sky's limit as to how much sophistication you could code up for the label placement. Of course, such programming drifts farther and farther away from the ideal of a built-in option to Plot that just magically drops on some text next to the function. Mathematica 8 or 9 maybe :)
One way to do this, which automatically associates the expression with the style used to plot it, is to use the PlotLegends standard add-on package. The output doesn't look very good by default; I recommend setting the LegendShadow -> None option and using Style on the expressions you stick in the legend to make them look better. Also, loading the package inflicts some funny redefinitions on Plot and related functions which can break some other things if you're not careful.
"Near its equation" is the problem. This isn't an easy problem to solve, and it becomes somewhat impossible when you start getting "busy" graphs with overlapping plots and so on.
I don't have a good example to show, but usually I'll define a "labelling function" that takes the same input as the function being plotted, which places a dot on the graph and writes some text nearby. This has the advantage of being able to easily vary the location of the text but still have it tied to the function.