Skip to main content

Posts

Showing posts from March, 2016

Solve integro differential equation numerically

I want to solve the following equation numerically: with initial condition y[0]=0 and y'[0]=0 I tried to do so by using the NDSolve function: eqn = Derivative[2][y][x] == 1+y[x] - Integrate[Derivative[1][y][x - t]/sqrt[t], {t, 0, x}]; NDSolve[{eqn, y[0] == 0, Derivative[1][y][0] == 0}, y, {x, 0, 1}] But it seems like Matlab cannot solve it directly. Do you have any suggestions?

plotting - Magnifying Glass on a Plot

Although there is a trick in TEX magnifying glass but I want to know is there any function to magnifying glass on a plot with Mathematica ? For example for a function as Sin[x] and at x=Pi/6 Below, this is just a picture desired from the cited site. the image got huge unfortunately I don't know how can I change the size of an image here! Answer Insetting a magnified part of the original Plot A) by adding a new Plot of the specified range xPos = Pi/6; range = 0.2; f = Sin; xyMinMax = {{xPos - range, xPos + range}, {f[xPos] - range*GoldenRatio^-1, f[xPos] + range*GoldenRatio^-1}}; Plot[f[x], {x, 0, 5}, Epilog -> {Transparent, EdgeForm[Thick], Rectangle[Sequence @@ Transpose[xyMinMax]], Inset[Plot[f[x], {x, xPos - range, xPos + range}, Frame -> True, Axes -> False, PlotRange -> xyMinMax, ImageSize -> 270], {4., 0.5}]}, ImageSize -> 700] B) by adding a new Plot within a Circle mf = RegionMember[Disk[{xPos, f[xPos]}, {range, range/GoldenRatio}]] Show

function construction - How to input a dynamically changing parameter in NDSolve?

I am trying to solve a system of DEs with additional conditions, and one condition depends on a parameter. Let us consider the following example: eq = D[y,x]==2; cond = y[1]==param; NDSolve[{eq,cond},y[x],x] How do I make a function that takes the input of a number param and outputs the NDSolve result with the corresponding parameter? I tried to make the condition itself a function, but this doesn't work: eq = D[y,x]==2; cond[param_] := y[1]==param fun[param1_] := NDSolve[{eq,cond[param1]},y[x],x] PS. There is a somewhat similar question , but there the parameter is of Boolean nature.

plotting - Can I make a plot with gradient filling?

Bloomberg has a standard plot style for its line plots in which it uses a gradient filling. Actually the way this seems to be constructed is that a gradient from the ymax to ymin is used as the background in the plot area and then the area above the line is set to transparent . What is the best way to make a plot like that in Mathematica for plotting {x,y} data? Answer How about this? bankerPlot[data_] := ListLinePlot[ data, AxesOrigin -> {0, 0}, Prolog -> Polygon[Join[data, Reverse[data.DiagonalMatrix[{1, 0}]]], VertexColors -> Join[ Blend[{Black, Blue}, #] & /@ Normalize[data[[All, 2]], Max], ConstantArray[Black, Length[data]] ] ], PlotStyle -> White, Background -> Black, AxesStyle -> White ] bankerData = Transpose[{Range[100], Accumulate[RandomReal[{-1, 1}, 100]] + 10}]; bankerPlot[bankerData]

probability or statistics - Histograms with pre-counted data

I've got some large data sets which have been counted but not binned already - essentially, a list of pairs of values (not bins) and counts.* (Or, equivalently, it's been binned into too-small bins.) I want to plot histograms for them. I remember the deprecated version of Histogram from a separate package had a FrequencyData option, but that seems to have disappeared. Is there any built-in way to accomplish this now? (I'd like to still have all the fancy features of Histogram, i.e. I don't want to just rebin the data myself and plot it directly. Notably I'd like to still be able to use Histogram's automatic bin specification, or something like it.) *That is, my data is represented as {{1, 6}, {2, 4}, {3, 2}, ...} instead of {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, ...} . (And before anyone suggests just expanding the data to the latter form to pass to Histogram: there are over 100K values, and the total count is over 100M.) Edit: okay, let me be really explicit. T

plotting - How to 2D-plot function in two varibles

I try to make a plot of a function in multi variables as in that paper arXiv:1312.1935 , FIG. 2 . I tried some thing like: k[s_,f_] = s + f; ListPlot[Table[k[s, f], {s, -1, 1, 0.5}, {f, -1, 1, 0.5}]] But it plotted k[s, f] on the y- axis. While I'd like to have s and f on the x and y axises. There is also ContourPlot, or PlotRegion, but to my knowledge the function k[s,f] will be plotted as continuous regions, while i'd like to present it as points (with known values like in the FIG). So any help ? " If the data is 3D and the third entry is obtained by applying a function like k[s,f] to the first two entries (like data set dt3d below), then the function we use to style the data is slightly different:" Actually I don't understand from here. I understand in the example of td and styleddt that in Style[{##} and k[##] , that ## refers to the two variables which k is function of them. But now I try to plot another function, like Y[s,f,d]= s+f+d; , with -1 < s &

conditional - Set conditions at a permutation

I need to find all permutations of 3 elements from {a,b,c,d,e} with this condition: These must include element d maximum once, and a must be before c . I'm using the following code and I don't know how to set the condition. Anyone help :) Permutations[list, {3}]; perm[a_, b_, c_, d_, e_] := Module[{perm}, list = {a, b, c, d, e}; k = Tuples[list, 3]; perm];

variable definitions - Can I create a dynamic number of rows in TabView through an iteration?

I have written code, with the help of stackoverflow of course, and I want to make it user friendly so that other people in my lab can use it. I'm playing with DialogCreate and similar functions. I want to do something like this so far: CreateDialog[TabView[{ "General" -> Column[{ Row[{TextCell["Project Name:"], InputField[Dynamic[Project]]}], Row[{TextCell["Number of Wells:"], InputField[Dynamic[num]], Button["Set", DialogReturn[num]]}]}], "Row Selection" -> Column[{Do[ Row[TextCell["Well " <> ToString[i] <> ":"], FileNameSetter[Dynamic[Evaluate[Symbol["w" <> ToString[i]]]], "Open"]], {i, 1, num}]}]}, ControlPlacement -> Left] ] I want to dynamically create more rows based on the input of "Number of Wells" within the same dialogbox but in a different tab. Is anything like this possible or some sort of a

General function taking general number of arguments

The following is an edit of this post, for which a working solution was provided by John McGee. I have a different function and am not sure how to adapt the solution for it: I want to construct a function that accepts multiple arguments, but where the number of arguments can change according to the length of a list that I insert as the set of arguments. For example, I have a table which has as elements the following lists: {{1,2,3,4},{1,2,3,4,5,6},{1,2,3,4,5,6,7,8}, ...} Note that the first list within the table has a length of 4, with progressive lists having an extra length of 2 compared to its previous. I have created the following function which works for the first list in the table: f[{a,b,c,d}]:= (y[2] - c)*(y[2] - d)*Exp[2y[1](a - b) + (a^2 - b^2)+ 2y[2](c - d) + (c^2 - d^2)] Similarly the function for the second list in the table should be: f[{a,b,c,d,e,f}]:= (y[3] - e)*(y[3] - f)*Exp[2y[1](a - b) + (a^2 - b^2)+ 2y[2](c - d) + (c^2 - d^2) + 2y[3](e - f) +

plotting - Plot3D constrained to a non-rectangular region

I would like to make a nice 3D graphic of a parabolic bowl, with a cylindrical rim. If I do the following: Plot3D[x^2 + y^2, {x, -3, 3}, {y, -3, 3}] I get a paraboloid, but the box is rectangular, so the edges come to points. I want a cylindrical bounding box. The best I've come up with is this: Plot3D[Piecewise[{{x^2 + y^2, x^2 + y^2 < 1}}], {x, -1, 1}, {y, -1, 1}] This creates a bowl, but there is also a "floor" to the graphic that I would like to get rid of. I might be able to play games with the coloring, but that seems like a poor hack. Does anyone have any suggestions? More generally, is it possible to create a 3D bounding box of arbitrary shape?

functions - Fitting ellipse to 5 given points on the plane

Five points are required to define a unique ellipse. An ellipse has five degrees of freedom: the $x$ and $y$ coordinates of each focus, and the sum of the distance from each focus to a point on the ellipse, or alternatively, the $x$ and $y$ coordinates of the center, the length of each radius, and the rotation of the axes about the center. I need a function, that fits an ellipse, for given five $(x,y)$ pairs. Is there a function in Mathematica to do that? If it's possible I need a plot with the ellipse and the given points, and also the equation of the fitted ellipse. I need an other function, that could check that if a point is on an ellipse. For example on an ellipse, that we just fitted with the previous function. Answer The following is based on the fact that the determinant of a matrix is equal to zero when two rows are the same. Thus, if you plug any of the points in, you get a true statement. SeedRandom[3]; pts = RandomReal[{-1, 1}, {5, 2}]; row[{x_, y_}] := {1, x, y, x*y

equation solving - Finding intersections of two parametric curves

I am dealing with the root finding of two parametric data curves (data below). I have already checked Parametric Interpolation of 2D data , which I found useful for plotting, though it is not adequate for interpolating the data and consequently, for finding the point/s where both curves cross. dat=# {1,10}&/@SortBy[im,-#[[1]]&]; a=First@dat; b=Rest@dat; pathim={1,.1} #&/@First@Last@Reap@Do[b=DeleteCases[b,a=Sow@Nearest[b,a][[1]],1];,{Length@b}]; dat=# {1,10}&/@SortBy[re,-#[[1]]&]; a=First@dat; b=Rest@dat; pathre={1,.1} #&/@First@Last@Reap@Do[b=DeleteCases[b,a=Sow@Nearest[b,a][[1]],1];,{Length@b}]; Graphics[Line@{pathre,pathim},AspectRatio->1,Frame->True] Consider that if you perform a parametric interpolation, you would still have the problem that both curves will have different parameters $t$ and $t'$. Any help will be welcome. Thanks in advance, Francisco im={{0.0531041079509168`,0.4537856055185257`},{0.05466627362026595`,0.4363323129985824`},{0.0553

plotting - How to simulate Placed in workaround for PlotLegends ParametricPlot bug?

I'd like Legended output for call like: rcap = {Cos[#], Sin[#]} & ; p1 = ParametricPlot[{Sin[t] rcap[t], Sin[t]^2 rcap[t]}, {t, 0, Pi}, PlotRange -> {-1, 1}, AxesLabel -> {x, y} , PlotLegends -> Placed[{"sin(\[Theta])", "\!\(\*SuperscriptBox[\(sin\), \(2\)]\)(\[Theta])"}, {Right, Bottom}] ] But have hit the ParametricPlot has PlotLegends bug detailed in ParametricPlot and PlotLegends don't seem to cooperate . I applied the list of functions answer to my plot (adding expressions for my labels) like so: x1 = With[{funcList = {Sin[t] rcap[t], Sin[t]^2 rcap[t]}, labelList = {"sin(\[Theta])", "\!\(\*SuperscriptBox[\(sin\), \(2\)]\)(\[Theta])"} }, With[{n = Length@funcList}, Legended[ ParametricPlot[funcList, {t, 0, Pi}, PlotRange -> {-1, 1}, AxesLabel -> {x, y}], LineLegend[(ColorData[1][#]) & /@ #, labelList[[#]]] &@Range@n]] ] which does successfully include a legen

Scroll Position for a Notebook

If you have a notebook with lot of content open you will see a scroll bar on the far right and bottom. I'm looking for a function that will return the current value of of the scroll bars. I'd also like to be able to set the value of the scroll bars with a function call. In a pane, there is a ScrollPosition option which allows you to set both scroll positions to an ordered pair like {500,600}. However, I don't see an option for the entire notebook. Does anyone know of a way to do this?

front end - Complete list of FrontEndResources

tl;dr I'm interested in finding a complete list of the strings that can be passed to FrontEndResource (I only need the first string, in the cases where two strings would normally be passed) Full explanation I've been playing with button appearances recently and I stumbled upon the "FEExpressions" argument to FrontEndResource . This is great as it significantly improves the appearances of the my various interface components, particularly buttons and panels, as many appearances are documented there: Button[ Style["Orange Button", White], Appearance -> FrontEndResource["FEExpressions", "OrangeButtonNinePatchAppearance"] ] which generates the following button set: Or they can be constructed from what's there already: Panel[ InputField["", String], Alignment -> Center, Appearance -> { "Default" -> Last@Last@ FrontEndResource["NotebookTemplatingExpressions",

Number elements in a list

I'm trying to learn more about list replacement without using Table . I have a list like this: list = {{{"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"}}} Now, I want to modify the list elements, i.e. add the position of the respective elements in front of it and replace every element in the list with that: listMod = {{{1->"a", 2->"b",3->"c"}, {1->"d", 2->"e", 3->"f"}, {1->"g", 2->"h", 3->"i"}}} Answer list = {{{"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"}}}; Map[MapIndexed[First@#2 -> #1 &], #, {2}] &@list (* Out: {{{1 -> "a", 2 -> "b", 3 -> "c"}, {1 -> "d", 2 -> "e", 3 -> "f"}, {1 ->

interoperability - How to trigger UNIX command-line command from Mathematica notebook?

At UNIX command line, one can run ls -la $HOME . How to trigger this from Mathematica notebooks? Run["!ls -la $HOME"] 32512 Returns some integer -- what is it? -- but not the normal output. Answer The Run command returns the exit code of the program being run. In your case, the program is "!ls" which probably doesn't exist on your system (If you try sh -c '!ls -la $HOME' you'll also get an error). Why it returns 32512 instead of 127 (which is the return value I get by the shell) I don't know; however I notice that $32512 =127\cdot 256$, so I guess it's in order to better distinguish valid exit codes (usually telling about errors during the execution) from errors occurring when trying to execute the command (like not finding the executable). If you start a raw kernel and type Run["ls -la $HOME"] ( without exclamation mark) you'll see the output of the ls command on standard output, and a returned value of 0 (the exit co

front end - How to set focus of a dialog window?

I have a dialog, which, when pops up, requests input from the user. How can I set the window up that the focus is on the InputField of the new window (i.e. the caret stands in the InputField ), so that when the user starts typing, it is immediately registered by the field? At the moment, I have to click inside the field first to make it the active control on screen. DialogInput[{InputField["", String], Button["Ok", DialogReturn[]]}] Answer After István Zachar's points, I was investigating Input definitions to learn more. It seams that 2 years later WRI changed approach from SelectionMove based to more automatic BoxReferenceFind . usage So what we only have to do is to set BoxID option for fields of interest and find those references when we want, with: MathLink`CallFrontEnd[ FrontEnd`BoxReferenceFind[ FE`BoxReference[ _NotebookObject, {{ID_String}}, FE`BoxOffset -> {FE`BoxChild[1]}, FE`SearchStart -> "StartFromBeginning"

arithmetic - Puzzle with Mathematica

Hello everyone, This is a puzzle I got from someone via social media. Basically, we need to fill up the boxes with the numbers 1-9 (no repetitions) that fit the multiplication and addition operations. I managed to solve this puzzle by using a brute force method in Excel+VBA. However, it would be very interesting if it can be solved in Mathematica with its specialty as computational software. Any idea will be appreciated. Thanks. Answer A non brute-force approach is the following, similar to my answer for the Zebra Puzzle . Both puzzles are examples of constrainst satisfaction problems, that can be solved with Reduce / Minimize / Maximize or, more efficiently, with LinearProgramming . The good about this approach is that you can easily extend and apply to many similar problems. The common part: Assign an index $i$ to each box from top left, $i=1,2,\ldots,9$. In each box you should put a digit $k$, $k=1,\ldots,9$. Assign an index $l$ to the whole number/row, $l=1,\ldots,5$. the vari

Question about using a pattern in ReplacePart

I noticed that "ReplacePart" can use pattern. For example: ReplacePart[{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {i_, i_} -> x] {{x, 0, 0}, {0, x, 0}, {0, 0, x}} So I naively think I can do a little change like ReplacePart[{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {i_+1, i_} -> x] But it gives {x, x, x} Why? I anticipated that the result whould be {{0, 0, 0}, {x,0,0}, {0, x, 0}} Can anyone help?

parallelization - ParallelTable and DistributeDefinitions

I have a function in the following form: function[...] := With[ {...}, Table[ anotherfunction[i, j, ...], {i, ...}, {j, ...}, ... ] ] If I'd like to replace Table with ParallelTable , do I need to put DistributeDefinitions["Global`"] somewhere? If yes, where? (Before With , before ParallelTable , or before calling function ?) anotherfunction is defined globally, and uses other global variables. Answer ParallelTable will automatically distribute the definitions of symbols used in the body of the table, as well as any dependencies, in version 8 and later. It is not necessary to use DistributeDefinitions with ParallelTable in these versions. Note that ParallelEvaluate does not automatically distribute definitions like Parallelize , ParallelTable , ParallelMap , ParallelDo , etc. do. You do need to use DistributeDefinitions if you rely on ParallelEvaluate , however, you do not need to distribute the definitions of all symbols. Just distribute

Eliminating the backward play in a SWF export of Manipulate

I find that the Export of Manipuate contains backforward play, see a simplified example: Export["try.swf", Manipulate[ Plot[Sin[2 x + φ], {x, 0, 10}], {φ, 0, 2 π}]] You can see the problem in the SWF file. Is there any simple way to get a animation with only forward play? Note that the problem in the the Export command. Indeed, Manipulate does the job (no need to specify AnimationDirection -> Forward ).

graphics - BarChart FrameLabels with only partial Frame?

This test BarChart is generated by the code that follows it: data = Table[RandomInteger[{1, 10}], {3}, {4}]; BarChart[MapThread[Labeled[#1, #2, Above] &, {data, {1, 2, 3}}], ChartLayout -> "Stacked", ChartStyle -> Reverse@{Lighter@Blue, Blue, Darker@Blue, Darker@Darker@Blue}, ChartLabels -> {{"a", "b", "c"}, None}, Frame -> {False, True, False, False}, FrameLabel -> {"x axis", "y axis"}, BaseStyle -> {FontFamily -> "Helvetica", FontSize -> 14}] Since only a y-axis component of Frame is rendered: Frame -> {False, True, False, False} the "x axis" label of FrameLabel -> {"x axis", "y axis"} is omitted - and that's consistent with documentation. Is it possible to display "x axis" at the location it would be if the bottom component of the Frame were there and preserving the set BaseStyle values (eg Font , FontSize )? This can be done

Check if symbol is in core language

How can I check if a symbol is pre-defined by Mathematica, in a way that's backwards compatible with old versions? i.e. I would like some CoreLanguageQ[x_Symbol] which matches CoreLangaugeQ[Print] , but not CoreLanguageQ[f] Then it can be used to help make code backwards compatible, eg. If[!CoreLanguageQ[Echo], Echo[x_]:= (Print[x];x)] Thank you. Answer You can look it up using WolframLanguageData , which has a list of all pre-defined symbols: ClearAll[CoreLanguageQ] SetAttributes[CoreLanguageQ, HoldAll] CoreLanguageQ[x_] := With[{name = SymbolName[x]}, CoreLanguageQ[name]] CoreLanguageQ[x_String] := With[{ names = WolframLanguageData[All, "Name"] }, MemberQ[names, x]] CoreLanguageQ[Plot] (* Out: True *) CoreLanguageQ[Plott] (* Out: False *) Looking at the context of the symbol is also a viable approach. However, the WolframLanguageData approach is appealing because the documentation states that WolframLanguageData[] gives a list of all Wolfram Language symbols.

functions - How to add periodicity to condition?

Is it possible to set the following function f[a] , where a can be any real number? $$ f(\alpha) = \begin{cases} 1 & \text{if } 2\pi n < \alpha < \pi (2n+1) \\ 2 & \text{if } \pi (2n+1) \le \alpha \le 2\pi (n+1) \end{cases}, \ n \in \mathbb{Z}\ $$ The issue here is n which I want to be substituted consecutively by an integer in order to produce propriate continuous conditions. I guess, it is not the case where Assumptions should be used as my attempt underneath doesn't work. f[a_] := \[Piecewise] { {1, 2 \[Pi]n < a && a < \[Pi] (2 n + 1)}, {2, \[Pi] (2 n + 1) <= a && a <= 2 \[Pi] (n + 1)} }, Assumptions -> n \[Element] Integers Thanks. Answer Here's one way to make your function periodic: f[t_] := Which[0 <= t < Pi, 1, Pi <= t < 2 Pi, 2, t < 0, f[t + 2 Pi], t > 2 Pi, f[t - 2 Pi]] For example: Plot[f[t], {t, -10, 10}] This method works well for any function you care to use (not just square waves). For i

plotting - Roots of a characteristic equation. Can Mathematica solve it?

I have been using Mathematica for a few years, but with basic things. Now I need to find the first 10 roots of the following equation: Cos[y] - 2 E^(-y)/(1 + E^(-2 y)) == 0 I have been trying to use the commands Solve , SolveAlways and FindRoot . But the only one that worked is the last one, but it needs a value near the root. Could you help me?

Fourier in Mathematica different from octave

First I create a table of sin(x) within 0, 10 In[97]:= Table[Sin[1.0 x], {x, 0, 10}] Out[97]= {0.,0.841471,0.909297,0.14112,-0.756802,-0.958924,-0.279415,0.656987,0.989358,0.412118,-0.544021} Then I try to apply fft on this data ( wolfram Link ) In[100]:= Fourier[{0.,0.841471,0.909297,0.14112,-0.756802,-0.958924,-0.279415,0.656987,0.989358,0.412118,-0.544021}]//MatrixForm Out[100]//MatrixForm= ( 0.425489 +0.I 0.570407 -0.270821I -0.860518+1.09804I -0.0342615+0.218599I 0.0450821 +0.095328I 0.0665458 +0.0283187I 0.0665458 -0.0283187I 0.0450821 -0.095328I -0.0342615-0.218599I -0.860518-1.09804I 0.570407 +0.270821I) I do the same using octave fft([0.;0.841471;0.909297;0.14112;-0.756802;-0.958924;-0.279415;0.656987;0.989358;0.412111]) ans = 1.41119 + 0.00000i 1.89183 + 0.89821i -2.85402 - 3.64178i -0.11363 - 0.72501i 0.14952 - 0.31617i 0.22071 - 0.09392i 0.22071 + 0.09392i 0.14952 + 0.31617i -0.11363 + 0.72501i -2

dynamic - What is wrong with combining two programs with event handlers?

I can delete the unwanted nodes of a RandomGraph by double-clicking on them from the first program, and I can change the positions of the nodes by dragging them from the second program. They both work nicely. However, when I combined the two programs into one, the nodes can't be dragged anymore. What is wrong with the combined promgram? Please help. (* First program, nodes can be deleted by double-clicking on them *) DynamicModule[{rg }, rg = RandomGraph[{7, 10}]; edglst = EdgeList[rg]; vlst = VertexList[rg]; VPOS = VertexCoordinates /. AbsoluteOptions[rg, VertexCoordinates]; VPOS = Rescale[#, 1 + Through[{Min, Max}[VPOS]], {0, 1}] & /@ VPOS; Vnthlrs = MapThread[EventHandler[#, { "MouseDown" :> If[CurrentValue["MouseClickCount"] == 2, ( ep = First@Position[vlst, #]; vlst = Drop[vlst, ep ]; VPOS = Drop[VPOS, ep ]; edglst = Delete[edglst, Map[List, Position[edglst, #][[All, 1]]]]; Vnthlrs =

calculus and analysis - Multivariate series for approximating implicit system

I'm trying to approximate the solution of an implicit set of equations by means of a Taylor series. I have managed to do so for a solution expressed in terms of a single independent variable, by using the Dt function, solving for the required derivatives, and manually constructing the Taylor series (also for higher-order derivatives). Now, the complexity (for me) increases: I have three implicit equations and would like to approximate the solution of three unknowns in terms of two independent variables, using up to the fourth derivatives. For this problem size, I can probably still figure out the implicit differentiation and Taylor series by hand, but I would like Mathematica to help me with this, since I anticipate more complex problems in the future. Edit: an example of the equations I am dealing with: (*P defines a potential: *) P = -M Rz + (360 (L^2 Rz^2 - 3 L Rz Uy + 3 Uy^2) + (2 L^2 Rz^2 + 30 L Ux - 3 L Rz Uy + 18 Uy^2)^2)/(180 L^3) - Ux V + (1/( 180 L^3))(1/ 4 (L^

plotting - particle motion in 1D anharmonic well

I have set of data points but I want to draw the trajectory of particle moving inside this well either in phase space. How can I do this? I tried with VectorPlot but not come out with good and set of data point are as follows: mass of particle is 10^-24 kg and here in this data first column is position & second potential. I am very thankful to you if you can help me to do this. Thank you. x={2.*10^-6, 1.9*10^-6, 1.8*10^-6, 1.7*10^-6, 1.6*10^-6, 1.5*10^-6, 1.4*10^-6, 1.3*10^-6, 1.2*10^-6, 1.1*10^-6, 1.*10^-6, 9.*10^-7, 8.*10^-7, 7.*10^-7, 6.*10^-7, 5.*10^-7, 4.*10^-7, 3.*10^-7, 2.*10^-7, 1.*10^-7, 0, -1.*10^-7, -2.*10^-7, -3.*10^-7, -4.*10^-7, -5.*10^-7, \ -6.*10^-7, -7.*10^-7, -8.*10^-7, -9.*10^-7, -1.*10^-6, -1.1*10^-6, \ -1.2*10^-6, -1.3*10^-6, -1.4*10^-6, -1.5*10^-6, -1.6*10^-6, \ -1.7*10^-6, -1.8*10^-6, -1.9*10^-6, -2.*10^-6} Vx = {-2.39203*10^-19, -2.38026*10^-19, -2.37166*10^-19, -2.36809*10^-19, \ -2.37117*10^-19, -2.38208*10^-19, -2.40143*10^-

scoping - function fails to use local variable when it is called inside a Module

I have these two functions fun and microstep .Fun makes use of a Module construct within which I define the Array I need to store the values of magnetization for different temperatures (each case stored in a different row). microstep is the function that store the data at the correct position at each step of the Monte Carlo algorithm. The monte Carlo procedure doesn't matter really much now, what bothers me is that when I define the magnetization array inside fun, the function doesn't work properly: fun [numbofsets_, nsteps_] := Module [{confinit, magnetization, index}, index = MapIndexed[ { #2[[1]], # } &, numbofsets ]; (* {index, temp} tuple*) confinit = RandomChoice[{-1, 1}, {10, 10}]; (* initial random matrix *) magnetization = ConstantArray[ 0, {Length@numbofsets, nsteps}]; Table[ NestList[ microstep[ ##[[1]], ##[[2]], ##[[3]], ##[[4]] ] & \ , { index[[i, 1]], index[[i, 2]] , confinit,

color - Changing background colour of a Manipulate element

Please consider the following: Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}]; Now, I would like to change the background colour to yellow. I tried the following, but in this case the nice looking rounded corners of the manipulate element get lost: Panel[#, Background -> Yellow] &@ Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}, Paneled -> False] Maybe somebody has a better idea. EDIT The background colour of Manipulate is by default grey. In addition the graphical element in which the Manipulate is embedded has rounded corners which I would like to keep. Applying my approach will change the colour but I loose the rounded corners. Answer If you would like to change background of Manipulate function - this is a way. Note I'll show you most difficult case when you have to go from light to dark colors change - then you have to pay attention to styling of internal graphics too, so everything (like ticks) are visible. st = {FontColor -> GrayLevel

plotting - Triangle mapped on a sphere in $mathbb R^3$?

How can I map a triangle on a sphere? I want to visualize (plot or animate) it for my student in Non-Euclidean geometry. I have no restrictions on the triangle's kind or on the sphere in $\mathbb R^3$. Thanks for any hint. Answer In the comments J. M. linked to a Demonstration by Borut Levart. Here is code from that, with my own refactoring: eps = 10^-6; (* from spherical to cartesian coordinates *) sp[{ϕ_, θ_}] := {Sin[θ]*Cos[ϕ], Sin[θ]*Sin[ϕ], Cos[θ]} (* part of great circle between two sphere points *) ark[{r1_, r2_}, nt_] := Table[ RotationTransform[t VectorAngle[r1, r2], Cross[r1, r2]][r1], {t, 0, 1, 1/nt}] Manipulate[ If[p1 == p2, p1 = .99 p2]; If[p1 == p3, p1 = .99 p3]; If[p3 == p2, p3 = .98 p2]; Graphics3D[{ {Red, Opacity[.6], Sphere[{0, 0, 0}, .995]}, ark[#, 20] & /@ Subsets[sp /@ {p1, p2, p3}, {2}] // Line, PointSize[.015], Point[sp /@ {p1, p2, p3}] }, Boxed -> False, ImageSize -> {400, 400}, FaceGrids -> {{0, 0, -1}}, FaceGri

scoping - Issue with scope of variables

For the definitions, t = 1; f[x_, y_] := t (x + y); v[3] := {1, 1}; g[u_] := f[v[u][[1]], v[u][[2]]]; the following two expressions yield different results, despite the only difference being the name of the iterator. Table[g[s], {s, 3, 3}] Table[g[t], {t, 3, 3}] I believe this is related to how Table applies the value of its variables, as mentioned in https://mathematica.stackexchange.com/a/23533 . Are there other functions that behave similarly (albeit bizarrely)? Other than using a different variable name for the iterator, are there good ways to avoid this issue?

graphics - How to draw Fractal images of iteration functions on the Riemann sphere?

Prof. McClure , in the work "M. McClure, Newton's method for complex polynomials. A preprint version of a “Mathematical graphics” column from Mathematica in Education and Research , pp. 1–15 (2006)" , discusses how Mathematica can be applied to iteration functions for obtaining the basins of attraction (or their fractal images). Below, I provide his code for the fractal image of the polynomial $p(z)=z^3-1$: p[z_] := z^3 - 1; theRoots = z /. NSolve[p[z] == 0, z] cp = Compile[{{z, _Complex}}, Evaluate[p[z]]]; n = Compile[{{z, _Complex}}, Evaluate[Simplify[z - p[z]/p'[z]]]]; bail = 150; orbitData = Table[ NestWhileList[n, x + I y, Abs[cp[#]] > 0.01 &, 1, bail], {y, -1, 1, 0.01}, {x, -1, 1, 0.01} ]; numRoots = Length[Union[theRoots]]; sameRootFunc = Compile[{{z, _Complex}}, Evaluate[Abs[3 p[z]/p'[z]]]]; whichRoot[orbit_] := Module[{i, z}, z = Last[orbit]; i = 1; Scan[If[Abs[z - #] < sameRootFunc[z], Return[i], i++] &, theRoots]; If[i <