New answers tagged

2

To answer your question Why doesn't Mathematica automatically do this transformation for me? Mathematica don't know that x is a function of t. But you can solve your system directly: sol = NDSolveValue[{y'[x] == (x - y[x])/(1 - y[x] - x), y[0] == 0}, y, {x, 0, 1}] You get an error message: NDSolveValue::ndsz: At x == 0.603939625832659`, step ...


4

Another option is to use DenistyPlot3D. You can set your own custom OpacityFunction and ColorFunction (by default they take scaled values between 0 and 1) DensityPlot3D[ 1/(1 + x^2 + y^2 + z^2), {x, -5, 5}, {y, -5, 5}, {z, -5, 5}, PlotPoints -> 100, OpacityFunction -> Function[f, (Exp[4 f] - 1)/(E^4 - 1)], ColorFunction -> ...


2

Image3D Using Image3D Image3D[ Table[ {f[x, y, z], 0, 0} , {x, -3, 3, 0.1} , {y, -3, 3, 0.1} , {z, -3, 3, 0.1} ] ] At a different range Image3D[ Table[ {f[x, y, z], 0, 0} , {x, -10, 10, 1} , {y, -10, 10, 1} , {z, -10, 10, 1} ] ] Raster3D Or using Raster3D Here I'm squaring the Alpha channel for a more striking ...


3

OK, a partial answer without considering h["TestDataTable",All]: In the plot it is much faster to move the pars inside CDF. (Computing CDF numerically vs. symbolically, I guess.) AbsoluteTiming[d1 = CDF[f[a, b, c, p] /. pars, x];] (* <1s *) AbsoluteTiming[d2 = CDF[f[a, b, c, p], x] /. pars;] (* 14s *) And it is faster to first compute the functions ...


3

a = 5; n = 30; ListPlot[Flatten[ Table[{a/9*(i - 1), a/9*(j - 1)}, {i, 1, n}, {j, 1, n}], 1]]


6

Example plot: Plot[{Cos[x], Sin[x], Tan[x]}, {x, 0, 2 π}] Now, just copy this plot from the notebook (using ctrl-C) and paste it in the front of following expression: /. a : RGBColor[__] :> ColorConvert[a, "Grayscale"] The result:


9

This approach splits each data set in to a set of curves and then attempts to join curves whose end and start points are "close enough". The measure I have used is okay for the example data and it includes an element of rescaling with the curve data but YMMV with "real" data. It is simpler than some of the linked approaches. Firstly we use a helper ...


7

As David G. Stork has pointed out, Nearest Neighbours offer a good method of attack for this problem. Here I've not implemented a full NN chain approach but something a little more basic which gets most of the way there. I'm using a 'dumb' NN but with a distance function that only allows points to be connected to another point one x-distance away, this ...


6

We can use the following approach: start with an end point that belongs to a path and increment the path with nearest neighbor points that are "good candidates." A point is a "good candidate" if it is not too far away from the last point and it does not produce a sharp turn in the path. To determine "too far" we a look at the distances between the last, say, ...


4

You can use LabelStyle -> Directive[Bold, Red] and LabelStyle -> Directive[Bold, Blue] Manipulate[ If[reflection, Plot[{-func}, {x, -3, 3}, PlotStyle -> Red, PlotRange -> {{-3, 3}, {-3, 3}}, GridLines -> Automatic, PlotLabel -> StringForm["f(x) = ``", -func], LabelStyle -> Directive[Bold, Red]], Plot[{func}, {x, -3, ...


2

ListPlot[MapThread[ Labeled[#1, Style[#2, Bold, 12]] &, {hours, PadRight[Range[12], Length[hours], "Periodic"]}]]


4

It's because the different elements of your PlotMarkers option refer to different data sets, whereas you just have the one data set. If you were only after different coloured data points then you could Style each element of your data set, however I don't know if its possible to do this with different symbols. A kind of hacky solution is just to convert ...


4

I first thought this was a bug, but then I recalled the fact that grid dividers can be specified by part. This worked in this case too. RegionPlot[{Disk[], Disk[{1, 0}]}, BoundaryStyle -> { 1 -> Directive[Orange, Thick], 2 -> Directive[Black, Thick]}]


5

f1[y_] := f[Mod[y, 4]] Plot[f1[x], {x, -8, 8}]


0

Using @Mr.Wizard's answer to this question works quite well: textchunk[text_String, len_Integer, size_Integer] := Text[Style[Module[{aa, bb}, aa = Accumulate[Join[{0}, Length@# & /@ Module[{t = 0}, Split[StringLength@# & /@ StringSplit[text, " "], (t += #) <= len || (t = 0) &]]]]; bb = {#[[1]], #[[2]]} & /@ ...


0

I would like to point out that shenanigan's solution can be made more defensive by using FilterRules, which I think should be considered. For example, with Options[f] = PlotLabel -> "Label"; f[a_, opts : OptionsPattern[]] := Plot[Sin[a x], {x, 0, 2 π}, Evaluate[Join[{opts}, Options[f]]]] evaluating f[2, BadOpt -> All] produces While with ...


2

You want to look at RepeatedTiming Table[{n, First@RepeatedTiming[RandomPrime[{10^n, 100^(n + 1)}]]}, {n, 100, 1500, 100}] (*{{100, 0.02}, {200, 0.1}, {300, 0.5}, {400, 0.9}, {500, 0.7}, {600, 5.}, {700, 1.*10^1}, {800, 1.*10^1}, {900, 3.*10^1}, {1000, 5.*10^1}, {1100, 51.}, {1200, 3.*10^1}, {1300, 7.*10^1}, {1400, 1.*10^2}, {1500, 1.*10^2}} ...


4

When you evaluate the statement opt=="def" it evaluates to True if opt really is "def", but it doesn't give False for any other object. Read the answer here to see why you need to use SameQ (===) instead of Equal (==), f[a_, opt_] := Module[{defOpt, opt2}, defOpt = {PlotLabel -> "Label"}; If[opt === "def", opt2 = defOpt, opt2 = Join[defOpt, opt]]; ...


3

To define a function with options, give it a set of defaults and use OptionsPattern in the definition. To use the value of a particular option in the function defintion, use OptionValue: Options[f] = {"ThisIsAnOption" -> False, SoIsThis -> 1}; f[a_, opt : OptionsPattern[]] := (If[OptionValue["ThisIsAnOption"], Print[{opt}]]; a + ...


3

A compact approach is ParametricPlot[ReIm[Log[θ] Exp[I θ]], {θ, 0, 2 Pi}] producing the same curve that appears in the answer by thedude. It works for any complex function of a single real variable. Appropriate to the season, a cartiod can be plotted by ParametricPlot[ReIm[I(Exp[I θ] + 1)^2], {θ, -Pi, Pi}]


1

Upon MarcoB's suggestion: complex[θ_] = Exp[I θ]; ListPlot[Table[ReIm@complex@θ, {θ, 0, 2 Pi, 0.01}], AspectRatio -> Automatic, Joined -> True] Example complex[θ_] = Log@θ Exp[I θ]; ListPlot[Table[ReIm@complex@θ, {θ, 0, 2 Pi, 0.01}], AspectRatio -> Automatic, Joined -> True]


1

A plot of DiracDelta is at best an approximation to the behavior of the underlying mathematical construct. This has been discussed before on this site; see for instance Calling Correct Function for Plotting DiracDelta and the answers within. In your case, you could perhaps try the following: ListLinePlot[ Table[{x, Piecewise[{{1, x == -3}, {0, True}}, ...


8

If you have a relatively recent version of Mathematica, you don't need to use Evaluate. X = {Unique["x"]}; With[{x = X[[1]]}, Plot[Legended[2 x, x], {x, 0, 1}]]


13

I don't think there is a special ribbon function. But you can plot one pretty easily. Here's an example. The functions x[u] and y[u] define a curve in space and then z[s] gives it width. x[u_] := Sin[u] u^2 y[u_] := 2 Cos[u] + u^2 z[s_] := s ParametricPlot3D[{x[u], y[u], z[s]}, {u, 0, 6}, {s, -2, 2}, Boxed -> False, Axes -> False] Here's ...


7

To answer the last question, the contour domains (since V8) are enclosed separately in GraphicsGroup, each which you can cull and turn into a region: plot = ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 3}, {y, -3, 3}, PlotRange -> {0, 0.5}, ColorFunction -> "Rainbow"]; regs = With[{coords = First@Cases[plot, GraphicsComplex[p_, ___] :> p, Infinity]}, ...


4

p = ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 3}, {y, -3, 3}, PlotRange -> {0, 0.5}, ColorFunction -> "Rainbow"]; colors = Cases[p, _RGBColor, -1]; poly = Cases[Cases[Normal@p, {__, colors[[2]], __}, -1],Polygon[__], -1]; r = RegionUnion[poly]; lines = Cases[Normal@RegionPlot[r], Line[__], -1]; Graphics[lines]


22

Normally Plot uses machine precision numbers; your $x^x$ expression is hitting the limit of the numbers that can be represented in machine precision right about $x>143$. Note: Solve[$MaxMachineNumber == x^x, x] (* Out: {{x -> 143.016}} *) You can increase the WorkingPrecision setting for Plot adequately, and the plot will be complete: f[x_] = ...


3

DateHistogram was added in version 10.2, and uses date-specific bins and ticks. I'll use the same {month, day} data as my other example, but instead of transforming the dates ahead of time, I can use DateFunction to provide the interpretation automatically. blossom = {{4, 3}, {4, 22}, {4, 15}, {4, 2}, {4, 18}, {4, 20}, {4, 12}, {3, 30}, {4, 4}, {4, ...


4

A simple way could be using the PlotRange. Table[ ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 2}, {y, -1, 1}, PlotRange -> {i, j}, ColorFunction -> "Rainbow", PlotLegends -> True, PlotLabel -> {i, j}] , {i, 0.1, 0.3, 0.1}, {j, i + 0.1, 0.4, 0.1}] // TableForm For a line, simply put the value ContourPlot[x*Exp[-x^2 - y^2] == 0.3, {x, ...


7

You ask whether it is "possible to define the areas with the same color as separate geometric regions in the sense of the computation geometry, and then work with these domains separately". This seems to me to be a great task for ImplicitRegion: regions = Table[ ImplicitRegion[i < x*Exp[-x^2 - y^2] <= i + 0.05, {{x, 0, 3}, {y, -3, 3}}], {i, 0, 0.4, ...


9

I don't know how to do this in an automated way, but here is something at least: Make your plot, extract the lines, convert them to regions, and then take the RegionDifference between them plot = ContourPlot[x*Exp[-x^2 - y^2], {x, 0, 3}, {y, -3, 3}, PlotRange -> {0, 0.5}, ColorFunction -> "Rainbow"] points = Cases[Normal@plot, Line[pts__] -> ...


2

There's a easier way to position elements by using Dynamic locator. Let us define some constants to be used later. pt = Scaled[{0.5, 0.5}]; (*initial position of label1*) pt1 = Scaled[{0.5, 0.5}]; (*initial position of label2*) pt2 = Scaled[{0.5, 0.5}]; (*initial position of label3*) {w, h} = {400, 250}; (*width & height*) {{l, r1}, {b, ...


4

Your x-axis values are on a log scale, so you need to use Log values for the gridlines. Show[%, errorplot1, AxesStyle -> {Opacity[0], AbsoluteThickness[3]}, Frame -> True, GridLines -> {Log@{100, 150, 200, 250, 300, 350}, {-6, -5, -4, -3, -2, -1}}, GridLinesStyle -> LightGray] Edit This is if you want to add the gridlines ...


3

I solved it by adding the grid lines to the theoretical function. Still curious why it didn't work the way I did it in my question though. Edit: Here's my code that solved it. Needs["ErrorBarPlots`"] Needs["ErrorBarLogPlots`"] errorplot1 = ErrorListLogLinearPlot[{{{100.15, -5.3}, ErrorBar[0.4]}, {{150.05, -3.0}, ErrorBar[0.4]}, {{200.32, -2.2}, ...


4

I would suggest separating the substance of your computation from the labels/formats. I also suggest searching this site on reasons for avoiding for loops. For example, fun[n_, h_] := NestList[{#[[1]] + h, #[[2]] + h (#[[2]] + #[[1]]^2)} &, {0, 1}, n] codes your function (barring any error on my part). Then, TableForm[fun[5,0.2], TableHeadings ...


5

Always avoid using subscripts, they just confuse things. Instead of defining Subscript[t,0]=0, define t[0]=0. Finally, Do loops are easier to read and write than For loops, which generally come from other programming languages. Does this do what you were going for? t[0] = 0; x[0] = 1; h = 0.2; Do[ t[n + 1] = t[n] + h; x[n + 1] = x[n] + (t[n + 1] - ...


3

How can I just directly assign positions? You can do it manually by creating Graphics3D text objects and positioning them alongside the plot. You can specify their coordinates using Scaled coordinates, Show[ Plot3D[Evaluate[ p[r/100, c, n, 1]^-1*D[p[r/100, c, n, 1], r] /. r -> 6], {n, 1, 20}, {c, 0, 0.1}], Graphics3D[Text["years", ...


1

I think MarcoB suggestion, made in a comment, should be put on record. x = Sin[(π t)/3] (Exp[Cos[(π t)/2]] - Sin[π t] + Sin[(π t)/(3 12)]^5); y = Cos[(π t)/3] (Exp[Sin[(π t)/2]] - Cos[π t] + Sin[(π t)/(3 12)]^5); With[{a = 0, b = 30 π}, ListPlot[Table[{x, y}, {t, a, b, .02}]]]


6

In the absence of your data, I'll just use some data that I make up. One of these is an example from the help on ListContourPlot3D and one is a 3D-Gaussian, list1 = Table[{x, y, z, x^2 + y^2 - z^2}, {x, -1, 1, .05}, {y, -1, 1, .05}, {z, -1, 1, .05}]~Flatten~2; list2 = Table[{x, y, z, 2 Exp[-3^2 ((x - .3)^2 + (y - .3)^2 + (z - .3)^2)]}, {x, -1, ...


3

I post this just to illustrate another way using FrenetSerretSystem which would be useful for plotting the evolute, e.g. pt[u_] := Module[{t, fs}, fs = FrenetSerretSystem[ellipse[t], t]; {ellipse[u], ellipse[u] + (fs[[2, 2]]/fs[[1, 1]]) /. t -> u}] Visualizing: list = With[{res = pt /@ Range[0, 2 Pi, 0.1], p1 = ParametricPlot[ellipse[t], {t, ...


5

To produce the behavior you want, you should make your function Listable: Clear[normalListable] normalListable[a_, t_] := {Sin[a], 2 Cos[a]} + t*{-2 Sin[a], -Cos[a]} SetAttributes[normalListable, Listable] Your function will now be automatically threaded over any lists in its input. Notice the difference: normal[{2, 3}, t] (* Out: {{Sin[2] - 2 t Sin[2], ...


2

Some of the definitions in the original question were problematic. I edited the question to have more consistent code. In order to plot the function numerical values are needed, so using Integrate is not necessary. We can use NIntegrate instead. The plot is produced within 30 seconds on my laptop with Mathematica 10.3.1. Here is the function redefined: ...


1

The simplest way I thick is to use Dynamic["your function"] instated of 1 in your controller. Control[{{A, 0.1, "Amplitude"}, 0, Dynamic["your function"], 0.01, Appearance -> {"Labeled", "Closed"}}] I think this will give you want you want, (assuming the function of the end is f+1): Manipulate[ Plot[A Sin[2 Pi f t/12], {t, 0, 12}, PlotRange -> ...


2

Turn the data into time series, and do the arithmetic with them: ts1 = TimeSeries[{{1, 2}, {2, 3}, {3, 5}, {4, 7}, {5, 11}, {6, 13}, {7, 17}}]; ts2 = TimeSeries[{{1, 3.87}, {2, 3.53}, {3, 3.40}, {4, 3.33}, {5, 3.25}, {6, 4.25}, {7, 5.24}}]; Normal[ts1 - ts2] {{1, -1.87}, {2, -0.53}, {3, 1.6}, {4, 3.67}, {5, 7.75}, ...


0

try something like this: ListPlot@Thread[{Flatten[{#1[[1]][[All, 1]] - #1[[2]][[All,1]]}], #1[[1]][[All, 2]]}] &@{{{1, 1}, {2, 2}, {3, 3}}, {{1,1}, {1, 2}, {1, 3}}}


2

ok, you have two lists, list1 = {{1, 2}, {2, 3}, {3, 5}, {4, 7}, {5, 11}, {6, 13}, {7, 17}} list2 = {{1, 3.87}, {2, 3.53}, {3, 3.40}, {4, 3.33}, {5, 3.25}, {6, 4.25}, {7, 5.24}} and you know how to plot them, ListPlot[{list1, list2}] List Manipulation giving massive and solid knowledge about List list1[[All, 2]] - list2[[All, 2]] {-1.87, ...


4

I'm not sure if it's a bug but it very may well be. This doesn't happen when you use other Wrapper objects, like Tooltip or PopupWindow.But what seems to be going on is that it wants to give the same plot marker and style to each sublist. One way to get your colors back is to use ListPlot[Transpose@{Table[{Cos[t], Sin[2 t]}, {t, 0, 2 Pi, Pi/20}]}, ...


6

TL;DR - Evaluate the function for just one value before trying to plot it. This will always save you hassle and headaches. And if your function involves a summation out to infinity, make sure it converges. Use atomic units when working on atomic-scale problems. I personally stay away from the Units functionality altogether, and just enter the numbers in ...


5

I share the sentiment that this question should have shown a lot more effort. Nonetheless, plot styling is quite possibly the most maddening and least intuitive aspect of Mathematica, at least in my opinion. The sheer quantity of options is daunting. With that in mind, here is a way to achieve something similar to what the OP requested, to get started. ...


2

This one is much faster then Plot (but the use depends on your quality needs) Graphics[Line@Transpose[{#, f[#] + g[#]}]] & @ Range[1.2, 10, 0.01]; Show[ ListLinePlot[{Transpose[list], Transpose[list2]}, PlotRange -> {0, 30}], Graphics[Line@Transpose[{#, f[#] + g[#]}]] &@Range[1.2, 10, 0.1] ] Some note on time Plot[f[x] + g[x], {x, ...



Top 50 recent answers are included