_id
stringlengths 1
5
| title
stringlengths 15
150
| text
stringlengths 43
28.9k
|
---|---|---|
35237 | Time constraints on KernelExecute commands or MenuItems? | I'm trying to use `Get` to load some pretty substantial packages from a custom menu in the _Mathematica_ toolbar (added via MenuSetup.tr). The problem is, the standard 5-second evaluation timeout seems to apply to commands executed with `KernelExecute`, so only a fraction of my `Get` is evaluated before the command times out. I'm wondering whether there's an option that can be passed to `KernelExecute` (or to `Item` / `MenuItem`) that will remove that time constraint so that my command can be executed completely. |
35543 | Syntax error for optional pattern, but only in debugger | This expression (explained here by Leonid) evaluates fine unless Evaluation->Debugger is enabled: h[x : (_Integer) : 1] := x > Syntax::sntxf: "x:" cannot be followed by "(_Integer):1". > Syntax::tsntxi: "(_Integer):1" is incomplete; more input is needed. > Syntax::sntxi: Incomplete expression; more input is needed . Strangely it works if the parentheses are removed: h[x : _Integer : 1] := x But both of these fail when debugging: h[x : (_Integer | None) : None] := x h[x : Alternatives[_Integer, None] : None] := x (* Workaround: *) ptn = _Integer | None; h[x : ptn : None] := x All this was with Mathematica 8.0.4 Linux What is the debugger up to? |
14789 | How to find all graph isomorphisms in FindGraphIsomorphism | I found the second definition of the function `FindGraphIsomorphism` not working. Here's the definition Mathematica 8 gives: > `FindGraphIsomorphism[g1,g2]` finds an isomorphism that maps the graph `g1` > to `g2` by renaming vertices. `FindGraphIsomorphism[g1,g2,n]` finds at most > n isomorphisms. I tried the following two tests. Define a simple graph by graph = AdjacencyGraph[{{1,0},{0,1}}]; Then running `FindGraphIsomorphism[graph,graph]` yields `{1->1, 2->2}`, this is good. but running FindGraphIsomorphism[graph,graph,2] makes the Mathematica kernel dead. So I tried another graph, graph = AdjacencyGraph[{{1,1},{1,1}}]; Running `FindGraphIsomorphism[graph,graph,2]` yielded error message: > FindGraphIsomorphism::nonopt: Options expected (instead of 2) beyond > position 2 in FindGraphIsomorphism[graph,graph,2]. An option must be a rule > or a list of rules. My conclusion is that `FindGraphIsomorphism[g1,g2,n]` is a bug. Or am I wrong somewhere? What should I do to obtain a result like: **Input:** `FindGraphIsomorphism[graph,graph,2]` **Output:** `{{1->1,2->2}, {1->2,2->1}}` * * * Update: It seems that the latest version of Mathematica does not support the third argument n in FindGraphIsomorphism. The form FindGraphIsomorphism[g1,g2,n] is no longer in the online documentation center. However, it exists in my older version 8.0.0, but fails to work. I still want to know if there is any way to make it work: FindGraphIsomorphism[g1,g2] gives one isomorphism, but how to get the list of more than one, or, all isomorphisms? |
32962 | Cartesian product of sets | I have two types of sets, one of them is a list of points of the form $\\{t_{k}\\}$ and the other one is an interval of the form $[a,b]$. And my custom set consists of these type of sets and I need to plot its Cartesian product. As an example, say my set is $A=[0,1]\cup\\{2,3,4,5\\}$, I need to plot $A\times A$. If I have only list of points, then I have no problem but when intervals come in to play, I don't have a very good idea. I need help at this point. |
35547 | Export complex number to excel or txt file | I'm doing some calculations on complex numbers in Mathematica. I can use Export to generate a file (*.CSV or *.dat, or anything else) of complex numbers. If I want to use excel, origin or Matlab to process the data, they cann't be treated properly. The easiest way to show these problem is like this: Export["dtList.dat", dtList = E^(-I*#) & /@ Range[10] // N] When the file,dtList.dat, is imported to Matlab, the data are treated as string, not complex numbers, (Look at the figure attached). I know this problem can be addressed if I export the Real part and Imaginary part of the complex numbers seperately, and combine them together in Matlab after import, but this is inconvenient and not elegant. Is there any clever solution? Thank you. ![enter image description here](http://i.stack.imgur.com/9M7gZ.png) |
11542 | Numerical comparisons of matrices | I have a matrix which should be equal to a null matrix. However due to the numerical precision, a brutal equality test with a matrix initialized with zeros does not work. How should I perform the numerical equality test (with a given threshold for the precision) ? |
28994 | Looking for equivalent of MinorTicks->None | I am looking for the _most general possible way_ to suppress the display of minor ticks in Mathematica plots.1 More specifically, I'm looking for _the equivalent_ (or _near-equivalent_ ) of a fictional `MinorTicks->None` option/setting (and its usual "partial variants", such as `MinorTicks->{None, Automatic}`, `MinorTicks->{Automatic, None}`, etc.). This fictional option/setting is one that could be passed to any Mathematica function that accepts a `Ticks` option, and would have the sole effect of ensuring that the results do not include minor ticks along the element(s) indicated through the options argument (but may still include the usual major ticks, of course). Note that I don't expect to get, literally, an implementation (somehow) of a `MinorTicks` option! I'm looking for something _equivalent, or nearly so_ , both in functionality and convenience. (If this description of the question is clear enough, the remainder of the post may be safely skipped.) * * * I can imagine at least three possible ways to answer this question. (But there may be other solutions I have not thought about!) The simplest one, of course, if such an option already existed (e.g. maybe some obscure/undocumented variant of `Tick`, or some trick with the existing options that would have the net effect of suppressing minor ticks), would be just to post this information. (This is the type of solution that strikes me as most likely, and, as it happens, for me also the most preferable.) The second one would be if there were some _freely downloadable_ package that implemented a similar functionality. The third one (which I realize is highly implausible) would be to post, or point me to, a modification of the source code for Mathematica's function for generating ticks (or for a sufficiently close mimic of it) in which all the parts where all the minor-tick-generating code have been disabled. (I realize that this may be too much work; it would suffice, however, just to point me to the source code of the function for producing the default ticks, and that I can use as the starting point for implementing a `noMinorTicks` function.) * * * 1 Just to be clear, I am interested only in solution that require only "standard" Mathematica (or possibly _freely available_ add-on packages). |
28997 | Opacity and overlapping multiple polygons | Let's say I have 100 polygons that are all different but most of them overlap. All I want to do is to draw/plot them in one single graphic with **linearly adding** gray values; i.e., a point with `n` overlapping polygons(or other graphics) should have a grayvalue of `n/100`. I wish Graphics[{Opacity[1/10], Table[Disk[{i/10, 0}], {i, 10}]}] would work, but `Opacity` doesn't add up linearly, and I don't find any easy way to do what I want. My current idea is to go via `Image[Graphics[...]]`, `ImageData` and `ArrayPlot`, but I might lose a lot of precision that way. |
32238 | Module Inside ToBoxes or MakeBoxes | Does someone mind explaining why Module doesn't seem to work while inside `ToBoxes` or `MakeBoxes`. SetAttributes[AutoInputField, HoldAllComplete]; AutoInputField /: MakeBoxes[AutoInputField[ list_: {}, displayNum_: 3, imageSize_: 100], form_] := ToBoxes@Module[{x = "default"}, x = "default"; Column[{ InputField[Dynamic@x, String, ContinuousAction -> True, ImageSize -> imageSize], Dynamic@x } ] ]; AutoInputField[] AutoInputField[] Ideally x should be set to `"default"`, but as of right now x isn't taking on any value. Surprisingly `Module` is successful at scoping the different value because the two `InputField`s values don't change interactively. I am looking for a way to modify/set the value of x inside the `Module`. |
28990 | Averaging multiple 2D data sets | I have multiple data sets, each of which is a 2D matrix. I want to construct a new 2D Matrix in which each element is the average of that element for all the original data sets. i.e NewMatrix[i][j] =1/N *(Matrix1[i][j] + Matrix2[i][j] + ... + MatrixN[i][j]) I can't quite figure out how to do it in _Mathematica_. Thanks |
11545 | Custom arrow shaft | Inspired by Sjoerd C. de Vries' nice answer to this question, and the desire to pimp a Graph I did with Mathematica recently I would like to know if there are ways to customize the arrow's shaft rather than its head (other than using `Tube` in `Graphics3D`). I am especially interested in arrows with non-uniform thickness along its length. Consider some examples grabbed from the web: ![enter image description here](http://i.stack.imgur.com/xR25d.jpg) Any chance to come up with a solution that allows to have Graphs like the following with automatically drawn/scaled arrow? ![enter image description here](http://i.stack.imgur.com/cIYRI.jpg) P.S.: This is a 2D question:). I understand that Line (and Tube) have the advantages to be easier to handle in 3D. |
28999 | Intersection & Complement operations for lists of Morphological Components? | I have an array of $M$ sets of morphological components corresponding to the same image, however computed in different ways. For example, we might have: M = Array[{} &, 4]; t1 = 0.1; t2 = 0.2; t3 = 0.5; M[[1]] = WatershedComponents[image,t1]; M[[2]] = MorphologicalComponents[CrossingDetect[image],t2, Method->"BoundingDisk"]; M[[3]] = MorphologicalComponents[image,t3, Method->"ConvexHull"]; M[[4]] = MorphologicalComponents[EdgeDetect[image],t1]; Is there a mechanism in Mathematica v9.0 that would allow me to create a function like: MorphologicalComponentNoIntersection[testComponentList,M] Which will return a set of morphological components in testComponentList that nowhere intersect / overlap any of the components in the array of component lists $M$? Or, in the opposite manner, perhaps a list of components in testComponentList that intersect / overlap with each at least one component in each list of components in $M$? |
28998 | Why does list assignment with a packed array result in unpacked values? | This is another question on the design choices in _Mathematica_. I understand that without direct reply from the developers it may not be possible to give a definitive and exhaustive answer to "why" questions but such topics have often been fruitful. * * * Why does list assignment of the form `{a, b, c} = tensor` where `tensor` is packed result in _unpacked_ values for `a`, `b`, and `c`? To illustrate: packedQ = Developer`PackedArrayQ; tensor = RandomReal[99, {3, 5, 7}]; tensor // packedQ > True {a, b, c} = tensor; packedQ /@ {a, b, c} > {False, False, False} It is possible to make the assignments without unpacking the sub-arrays of `tensor` by manually unpacking the outer list using `Apply`: {a, b, c} = List @@ tensor; packedQ /@ {a, b, c} > {True, True, True} ### Why doesn't `Set` operate like this by default? That is, why doesn't `Set` only unpack the right-hand-side as far as necessary, to the level of the left-hand-side? |
39326 | Simple way to plot a complex valued function of one real variable | How can I plot a complex valued function of one real variable, $f(t)$, as $$x=-\Re f(t),\ z=\Im\ f(t),\ y=t \space?$$ My aim is a 3-dimensional path, treating the complex valued function as if it was a two real components vector valued function. For example $e^{it}$ can be visualized as a helix in $\mathbb R^3$, in which, for example, the "east-west" axis ($y$) represents the single real variable: $t$, the "north-south" axis ($x$) represents $-\Re f(t)$, and the "top-down" axis ($z$) represents $\Im\ f(t)$. |
7871 | How do you round numbers so that it affects computation? | I'm trying to make a demonstration of how rounding to different numbers of digits affects things but I can't find a way to round numbers to a specified number of digits. The `Round`function only round to the nearest whole integer, and that is not what I always want. Other ways seems to only change the way the numbers are displayed, not how they are internally stored. I want to throw away precision, but it seems Mathematica doesn't want to allow me to do this. As an example: I would like to round 3.4647 to just 3.5 or 3.46. There must be some way to do this, but I can't for the life of me find it. |
32597 | Rounding to the nearest decimal | If I have a bunch of numbers in a list `{1.435243523432,2434.2321321412,5.8239897,...}`, without multiplying everything by some power of ten and then dividing by that power later, is there an argument I can supply to `Round` that will round each number at the $k$th decimal place (or do nothing if the number isn't defined to that precision)? For example, if we set $k = 3$ we'd like something like: DecimalRound[{1.435243523432,2434.2321321412,5.8239897,...},3] = {1.435,2434.232,5.824,...} |
5989 | "A number in base b" and pure functions: why doesn't b^^# & work? | Why do the following not work (in Mathematica 7)? 2^^ # & /@ {1000, 1101} and 2^^ # & @ 1101 This does work: 2^^1101 giving, as expected: (*13*) (This also works: BaseForm[#, 2] & /@ {13, 14} ) See here for further information ("Digits in numbers") |
55296 | How to transform frame ticks from 1, 2, 3, ... to x, 2 x, 3 x, ...? | I want to replace the numbers on a framed plot's axes with that number multiplied by a variable, call it `x`. (The idea is that I'm plotting things which depend on some scale, and I want to show that on the axes, i.e. that I'm plotting these functions with `x` divided out.) Here's a minimal example that I've written up: Plot[a, {a, 0, 1}, Frame -> True, FrameTicks -> {{Partition[Riffle[Range[0, 1, 0.2], (Range[0, 1, 1/5] /. x_Rational :> N[x]) x], 2], None}, {Automatic, None}}] It does the trick, but the problem is that I need to adjust it each time I change the plot range. What I do is plot the function without the `FrameTicks`, see which numbers are plotted on the y-axis, and adjust the range accordingly. Is there a way to automate that process? |
56341 | Faster Alternative to DeleteDuplicates for deleting elements in list | I have a list in this style data={{a1,b1,c1,d1,e1,f1}, {a2,b2,c2,d2,e2,f2}} I need to delete all elements in which `b1` is equal to `b2` and so on. I only have to test b. The list I use have more than 15000 elements. I used `DeleteDuplicates`: DeleteDuplicates[data, {_, #1, _, _, _, _} == {_, #2, _, _, _, _} &] I know this method gives a correct result because I tested it on a small amount of data. But in a list with more than 15,000 elements after 20 minutes of running without success. Is there a more efficient method? |
7525 | Pattern matching deletion of list items | > **Possible Duplicate:** > How can I remove B -> A from a list if A -> B is in the list? I'm working toward building a graph and use some code to construct my rules which results in a form as follows: g = {1 -> 2, 1 -> 3, 2 -> 1, 2 -> 3, 2 -> 4, 3 -> 2, 3 -> 4, 3 -> 1, 4 -> 3, 4 -> 2} I would like to delete all reverse duplicate entries form the list, i.e. both `1->2` and `2->1` appear in the list. I would like to get rid of one of them and do this for all reverse duplicates in the list `g`. |
7676 | Operations on sets of sets | > **Possible Duplicate:** > How can I remove B -> A from a list if A -> B is in the list? > Delete duplicate elements from list > Pattern matching deletion of list items How do I delete the duplicates of a set who's elements are themselves sets? Here is an example: Deleting the duplicates from {{x,y},{y,x}} should give {{x,y}} (or {{y,x}}, both answers are equivalent). I am particularly interested in the case when x and y are lists, but a solution that works for x and y of any type would be better. |
1302 | How can I remove B -> A from a list if A -> B is in the list? | I have a list of transformations like this: list = {"A" -> "B", "B" -> "A", "C" -> "D"} As this is used to plot an undirected graph with `GraphPlot`, I don't want to have an Edge between the vertices A-B _and_ B-A. I just want one of them. How do I remove either `A -> B` or `B -> A` from this list? In the end, I want the list to look like this: {"A" -> "B", "C" -> "D"} I've tried using `DeleteDuplicates`, but I don't think I understand the testing part of that function (I should add that I'm a Mathematica beginner ... ) I made a function that can compare two transformations: CmpTrans[x_,y_] := (x[[1]]/.x) == y[[1]] It returns `True` for `CmpTrans[A->B, B->A]`, but I can't seem to use this is the testing part of `DeleteDuplicates`. |
2419 | Delete duplicate elements from a list | If a list contains duplicate elements, for example list = {a, 1, 5, 3, 5, x^2, x^2}, how can the duplicate elements be removed? The result would be uniqueElements = {a, 1, 5, 3, x^2} |
51268 | NIntegrate: integrand has evaluated to non numerical values | I have pasted a code that has been giving me some trouble and errors when I try to compute. > ERROR: "The integrand 1435.1232 E^(-6.4703566*10^6 s^2) deEntrance[s,phi]^2 > has evaluated to non-numerical values for all sampling points in the region > with boundaries " I tried implementing the `?NumericQ` function to ensure the functions are evaluated numerically with no issues but have no success. I've been at it for days, so if anyone can be of any help I would greatly appreciate it! e = 1.60217657*10^-19; rcgs = 2.8179403267*10^-13; gamma = 1600/0.511; n = (10^-10)/e; lm = 0.549267; theta = 0.07; r = lm/theta; sigmaSbeg = 2.759026*10^-004; sigmaSend = 2.779847*10^-004; eta1[phi_] := -(phi^2/(2 r)) eta1prime[phi_] := -((phi*theta)/lm) sL[phi_?NumericQ] := (r*phi^3)/24 lambdaBeg[z_] := 1/(sigmaSbeg*Sqrt[2 Pi]) Exp[-(z^2/(2*sigmaSbeg^2))] lambdaEnd[z_] := 1/(sigmaSend*Sqrt[2 Pi]) Exp[-(z^2/(2*sigmaSend^2))] lambdaCompress[z_, phi_] := 1/((((sigmaSend - sigmaSbeg)/theta)*phi + sigmaSbeg)*Sqrt[2 Pi]) Exp[-(z^2/(2*(((sigmaSend - sigmaSbeg)/theta)*phi + sigmaSbeg)^2))] deEntrance[s_, phi_?NumericQ] := With[{sL = sL[phi]}, (-((2*n*rcgs*gamma^-1)/(3^(1/3) r^(2/3))))*((lambdaCompress[s - sL, phi] - lambdaBeg[s - 4 sL])/sL^(1/3) + NIntegrate[ (1/(s - sprime)^(1/3)*D[lambdaCompress[sprime, phi], sprime]),{sprime, s - sL, s}])] deEntranceRMS[x_, phi_] := Sqrt[ NIntegrate[lambdaEnd[s]*(deEntrance[s, phi])^2, {s, -x*sigmaSend, x*sigmaSend}] - (NIntegrate[lambdaEnd[s]*(deEntrance[s, phi]), {s,-x*sigmaSend, x*sigmaSend}])^2] kick1 = NIntegrate[(eta1[phi])*deEntranceRMS[3, phi], {phi, 0.0, lm}] kick1prime = NIntegrate[(eta1prime[phi])*deEntranceRMS[3, phi], {phi, 0.0, lm}] |
54551 | NIntegrate Trapezoid rule with even subdivision producing poor results | NIntegrate[x^2, {x, 5, 9}, Method -> {"TrapezoidalRule", "Points" -> 2, "RombergQuadrature" -> False}, MaxRecursion -> 1] returns the value `190` while the correct trapezoid estimate is `5^2/2+6^2+7^2+8^2+9^2/2 = 202`. The correct trapezoid weights for a width 4 interval are `1/2, 1, 1, 1, 1/2`. I believe that the incorrect weights of `1, 1, 1/2, 1, 1/2` are being used instead. Similar errors are made for `TrapezoidRule` with any even number of points. For example, NIntegrate[x^2, {x, 5, 9}, Method -> {"TrapezoidalRule", "Points" -> 22}] returns warning messages about slow convergence. I reported this to Wolfram several months ago and expected to see a fix in 10.0. However, the same results appear in 10.0. So now what I'm asking is if others can verify that this really is an error in the implementation of NIntegrate or if I'm making some mistake in my analysis. |
51266 | What is the 'Mathematica-way' to test a variable transform? | Hello Mathematica experts. I would like to play around with a simple variable transformation, to test some claims about it. I wonder if there is a _Mathematica_ -like way to do this. The specific case I have is a transformation: $$x\mapsto x' \equiv \begin{cases}x; \qquad x\ge 0\\\x+\pi;\, x<0\end{cases}$$ where $x\in[-\pi,\pi]$ gets moved over to $x'\in[0,\pi]$. So far I have found two equivalent ways of representing this: XPrimed[x_] := If[x < 0, x + π, x] AnotherXPrimed[x_] := x*HeavisideTheta[x] + (HeavisideTheta[-x]*(x + π)) Which both seem reasonable. Plot[XPrimed[phi], {phi, -π, π}, AxesLabel -> {"original variable, x", "transformed variable, x'"}, PlotRange -> {{-π, π}, {0, π}}] ![Plot of the transformation... works as expected](http://i.stack.imgur.com/618u4.png) So how do I make plots of things like: Plot[Cos[XPrimed[x]], {x,-π, π}, AxesLabel -> {"original variable, x", "Cos(x')"}] ![Plot of the transformed variable](http://i.stack.imgur.com/KYY6P.png) ..but over the **transformed** domain, i.e. $\cos(x')$ with $x'$ on the x-axis? I suspect there is a smart way to do this in _Mathematica_ specifying domains or variable maps or a coordinate transformation or the like, I can't seem to find anything. |
19395 | Feedback on Functional Programming: Propagation of uncertainty | Lately I've been trying to use functional prgramming and tried to implement the gaussian propagation of uncertainty (without correlation) in an elegant way, here is the outcome: Norm /@ (#2 Outer[(Derivative @@ #2)@f @@ #1 &, #1, IdentityMatrix@Last@Dimensions@#1, 1] /. f -> #3) &[data, error, f] `data` and `error` are assumed to be two dimensional lists (lists of data points), and `f` is a function. What bothers me a bit is the `ReplaceAll` (`/.`) rule for f, because I couldn't figure out how to create a function `g` in a way that `Outer[g &, ...]&` takes f as an argument to return a new function `g[f]&`, which again takes two arguments (here a partial derivative of f respect to the variable specified by the first argument, evaluated at a point specified by the second argument). What I ask for basically is some feedback. What could be done better? Any suggestions are appreciated, merci. |
19394 | Export data from remote kernel onto a local machine | I can not access the directory on my remote kernel these days. Therefore, I want to export the output of the computations to my local machine. Some details: * My remote kernel is on a Tyan TX46 with 4 Opteron 2.2Ghz cpus and 32GB of ram and my local machine has a Intel(R)Core(TM)2CPU 6600 @2.40 GHz processor and 4gb ram. * I don't use parallel remote kernels. * I installed my remote kernel by some settings on Evaluation>Kernel Configuration Options. Is there a way to do that? |
5986 | Why does LogLinearPlot sample its argument outside the specified domain? | I experience a weird bug in the function `LogLinearPlot`. If the input is an interpolation function, such as the one created like this, int = NDSolve[{x'[t] == 1, x[0] == 0}, x, {t, 0, 100}] then when plotting it I get an error message (but the plot works fine) LogLinearPlot[x[t] /. int, {t, 0.1, 100}] InterpolatingFunction::dmval: "Input value {-2.30244} lies outside the range of data in the interpolating function. Extrapolation will be used" You will not be surprised to know that `log(0.1)=-2.302`. It seems that `LogLinearPlot` tries to plug in the wrong values in the function, but the plot does look good. **Update: This is working correctly in version 9.** |
2619 | Conditional numerical integration boundaries | I have a multidimensional integration of the form: somefunc[t] = NIntegrate[ otherfunc[x, y, z, t ], {z, z1[t], z2[t]}, {y, y1[t, z], y2[t, z]}, {x, x1[t, z, y], x2[t, z, y]}]; This needs to be evaluated only when $z2 > z1$, $y2 > y1$ and $x2 > x1$. However mathematica still evaluates the integrand backwards even if $y2 < y1$. My question is how to tell `NIntegrate` to simply give 0 in such cases and move on the next integration step. I tried to modify the upper integration boundary as follows: y2p[t, z] = Max[y1[t, z], y2[t, z]] But this is not accepted by Mathematica as an integration boundary. How can I fix this? |
47994 | How to see source code of a demonstration in notebook | I downloaded this demonstration The source code can be previewed here However, when I download the NB file, I cannot get access to this said code. All I can see is the output. I'm obviously missing something. Thanks for enlightening me about this |
24245 | Viewing Mathematica Demonstrations Project Code | I hope I am going insane and the I'm not seeing the snake about to bite me... How does one view the code in the demonstration projects that one can download from wolfram.com? It seems like all of them come down as an 'Authoring Notebook' and I cannot always get the notebook to show a view of the code the author used. Some of the notebooks have the cells 'docked' and you can view the code by double clicking the cell. Others, do not show the icon on the cell brackets to open their content, but the demonstration still functions. It appears the code is definitely available by looking at the plain text of the file. Are authors encouraged to obfuscate the code in their demonstrations? If not please direct me to the snake... |
5985 | Estimating progress on plots | When plotting a slow function, it would be nice to know how much of the work has already be done. However due to the refinement algorithm, simply monitoring the integration variable doesn't give an useful estimate unless `MaxRecursion` is set to 0 (and it's clear that the best I can hope for is an estimate). For example, consider Monitor[Plot[Pause[0.01];Sin[x],{x,0,100}],x] This goes through the interval dozens of times, although the number of points in each iteration goes down. Therefore my question: Is there any way to get a reasonable estimate of how much of a plot is already done? |
22261 | Is there something wrong with VertexConnectivity | As I noticed in the documentation `VertexConnectivity` is defined as the following > The vertex connectivity of a graph $g$ is the smallest number of vertices > whose deletion from $g$ disconnects $g$. Now for a `CycleGraph` I expect one needs to delete at least **two vertices** to make the resulting graph disconnected. Please correct me if I am driven by a wrong intuition here. opt = {VertexLabels -> "Name", ImagePadding -> 10}; graph1 = CycleGraph[8, opt]; graph2 = UndirectedGraph[Graph[{1 -> 3, 1 -> 7, 1 -> 10, 2 -> 5, 2 -> 6, 3 -> 6, 3 -> 10,4 -> 7, 4 -> 8, 4 -> 9, 5 -> 9, 6 -> 10, 7 -> 8, 8 -> 9}],opt]; Row[{graph1, graph2}] ![enter image description here](http://i.stack.imgur.com/2oFzG.png) ## **Strange!** Now Mathematica is returning this _not so intuitive_ values for the `graph1` and `graph2`. VertexConnectivity /@ {graph1, graph2} > {1,1} How can one make any of these above graphs disconnected by deleting just **one vertex**? Can someone shade some light on this issue? `EdgeConnectivity` though gives understandable output for both the graphs. |
19713 | How to change an expression to Fortran90 form? | I have a large expression produced by _Mathematica_. To use this expression in my Fortran program I need to change it to a Fortran90 form. I am not satisfied with the `FortranForm` command. The output of the _Mathematica_ expression is like this, -48*Sqrt[6]*E^((-2*S[1, x]^2)/bx - (S[1, y]^2)/bx - (S[1, z]^2)/ bz - (S[2, x]^2)/bx - (S[2, y]^2)/bx - (S[2, z]^2)/ bz - (Sp[1, x]^2)/bx - (Sp[1, y]^2)/bx - (Sp[1, z]^2)/bz) + 3*Sqrt[5*v] I hope I can get this expression like this, -48.q0*sqrt(6.q0)*Exp((-(2.0*s1x**2/bx)-s1y**2/bx-s1z**2/bz & -s2x**2/bx-s2y**2/bx - s2z**2/bz - sp1x**2/bx - sp1y**2/bx & - sp1z**2/bz)+ 3.q0*Sqrt[5.q0*v] Notice that: 1. The width should be fixed and there is a "&" at the end of the line. It is better the single line space can be fully occupied. 2. Some integers should be changed to reals. For example, `6` -> `6.q0` or `6.d0`; 3. It is better for `E^` to be changed to `Exp()` form. How can I change `S[a,b]` to `Sab` easily? This is not a big problem. I could replace it in _Mathematica_. Anyway, I want to change my _Mathematica_ expression into a Fortran90 expression automaticly. Is it possible? |
48899 | How to draw guide lines spanning between two panels or graphs? | ![](http://i.stack.imgur.com/2T6Pt.png) I would like to draw the blue guide lines as shown spanning between the top and bottom graphs. Any help is appreciated. Thanks! |
41536 | NDSolve with different function lengths over time | I'm working on a cops & robbers game, and there is one single event that is very very important, the event of _catching_ someone. I'm trying to do when any robber is catched, delete it from the robbers array. I think it must be done with `WhenEvent` A cop catches are robber if the circles that define them are touching. A visual representation can be seen here. There is an array showing the initial positions of all (let's say _cops=5 and robbers=3_ ) the cops & robbers The arrays are like this (the 0 is the time): cops = 5; robbers = 3; Array[c[#][0] &, cops] Array[r[#][0] &, robbers] The `NDSolve` looks like this: NDSolve[ Join[ Table[ r[i]'[t] == v[r[i][t], b[r[i][t]]~Join~Array[c[#][t] &, cops], 2], {i, robbers} ], Table[ c[i]'[t] == -v[c[i][t], Array[r[#][t] &, robbers], 4], {i, cops} ], (*initial positions*) Thread[ Array[r[#][0] &, robbers] == {{1,2},{3,4},{5,6}} ], Thread[ Array[c[#][0] &, cops] == {{6,5},{4,3},{2,1}} ] ], Array[c, cops]~Join~Array[r, robbers], {t, 0, 10}, FilterRules[{opts}, Options[NDSolve]], Method -> {"EquationSimplification" -> "Solve"} ] I'm guessing to put something like: Table[ WhenEvent[ catched[i]==True, Array[r[#][t] &, robbers]-> Cases[ Array[r[#][t] &, robbers], Except[ r[i][t] ] ] ], {i,robbers} ] But doesn't work, I'm guessing because NDSolve can't calculate with this method lists of functions that vary with time. |
55345 | Binarizing a matrix | I have an image with a few bright pixels with the remaining ones very dark. The difference is in orders of magnitude. I want to binarize this matrix (corresponding to the image) making all values zero besides the few bright ones. The function Binarize does what I want but it accepts only an image as an input. So indeed I can use the plot of the matrix as input but that messes up things because the image includes the axis, labels etc... How can I do this? Any help will be appreciated. |
22269 | Solving derivative of cumulative normal distribution log likelihood | I am a newbie and I'm trying to use Mathematica to obtain the symbolic Maximum Likelihood Estimation for a cumulative normal distribution. So far I have reached the step where I have the derivative of the log likelihood for both $\mu$ and $\sigma%$ ie $ \text{score}=\left\\{\frac{\partial \text{logL}}{\partial \mu },\frac{\partial \text{logL}}{\partial \sigma }\right\\} $ $$ \left\\{\sum _{i=1}^n -\frac{\sqrt{\frac{2}{\pi }} e^{-\frac{\left(\mu -x_i\right){}^2}{2 \sigma ^2}}}{\sigma \text{erfc}\left(\frac{\mu -x_i}{\sqrt{2} \sigma }\right)},\sum _{i=1}^n \frac{\sqrt{\frac{2}{\pi }} \left(\mu -x_i\right) e^{-\frac{\left(\mu -x_i\right){}^2}{2 \sigma ^2}}}{\sigma ^2 \text{erfc}\left(\frac{\mu -x_i}{\sqrt{2} \sigma }\right)}\right\\} $$ The problem is that when I try to solve these expressions for 0; Solve[score == {0, 0} && \[Sigma] > 0, {\[Mu], \[Sigma]}] Mathematica tells me that it can't solve it (Solve::nsmet: This system cannot be solved with the methods available to Solve). Is this really such a hard problem or am I missing something |
22268 | Workbench error message: LinkObject::linkv: Argument Null in Null is not a valid LinkObject | From time to time I get this error message when I save my .m file in Wolfram Workbench: _LinkObject::linkv: Argument Null in Null is not a valid LinkObject_ I can't really figure out what causes this message exactly, maybe when I save my file after deleting or adding a lot of characters but I'm not sure. I'm not calling Java at all from my program so maybe that comes from Workbench itself? It happens that Workbench freezes and closes from time to time without warnings at all, so there might be something broken in there... And now just after Workbench freezes one more time, I relaunch it and get the message: _"Could not open the editor: The editor class could not be instantiated. This usually indicates a missing no-arg constructor or that the editor's class name was mistyped in plugin.xml."_ |
48890 | How to remove a gap between the chart labels and the frame in a BoxWhiskersPlot | When making a nested `BoxWhiskersPlot` with chart labels, the labels are nicely spaced below the bottom frame when using labels for all nested data data = {{{61.5, 60.5, 59.5}, {65.5, 60.5, 58.5}}, {{60.5, 57, 62}, {66.5, 60.5, 56.5}}} BoxWhiskerChart[data, ChartLabels -> {{1, 3}, {"Group1", "Group2"}}] ![Nicely spaced chartlabels](http://i.stack.imgur.com/Epply.jpg) However, I decided to put the labeling of the groups into `ChartLegends` and to remove the chart labels for the groups, BoxWhiskerChart[data, ChartLabels -> {{1, 3}, None}, ChartLegends -> {"Group1", "Group2"}] ![enter image description here](http://i.stack.imgur.com/T5UL6.jpg) but this leaves an annoying gap between the frame and the chart labels, the numbers 1 and 3 in my example. How can I remove it? Also, I actually would like to place the legends inside the frame at the lower left corner in order to save space, but `Placed` in the `BoxWhiskersPlot` does not allow it -- how can I work around that? Any help is much appreciated! |
48218 | ReplaceAll in an expression including large InterpolatingFunction | I have a large `InterpolatingFunction` that I'm transforming to another basis with a few simple multiplications and additions by (symbolic) constants. The transformation is quick to compute. However, when I later want to replace the symbolic constants with real numbers for plotting purposes, a call to `ReplaceAll` grinds for an exceptionally long time on the expression. Why? Is there a way to avoid this without replacing in the transformation itself (an alternative I'd like to avoid for procedural reasons). I would provide code, but I don't know a short snippet that can generate a large interpolating function. Perhaps someone can provide a good example. |
48897 | find cycle in directed graph | Given a digraph `G` in the form of a list of edges, is there implemented some command that returns a directed cycle in `G` of shortest length? The combinatorica package does this with `GG=ToCombinatoricaGraph[G]; FindCycle[GG]`, but converting a graph as a set of edges into a combinatorica graph messes things up. For example, Combinatorica renames the vertices, so I don't know what the original vertices of the returned cycle are. Also, I'm not sure the returned cycle is shortest in the graph. And drawing Combinatorica graphs via ShowGraph[GG] is uglier that using `GraphPlot[G]`. More concretely, G={{2,2}->{1},{1,2,1}->{2,2},{2,1,1}->{2,2},{1,1,1,1}->{1,1,2},{1,1,1,1}->{1,2,1}, {1,1,1,1}->{2,1,1},{1,2,2,2}->{1,1,2},{1,2,2,2}->{1,2,1},{2,1,2,2}->{1,1,2},{2,1,2,2}-> {2,1,1},{2,2,1,2}->{1,1,2},{2,2,1,2}->{1,2,1},{2,2,2,1}->{1,2,1},{2,2,2,1}->{2,1,1}, {1,1,1,2,2}->{1,1,1,1},{1,1,1,2,2}->{1,2,2,2},{1,1,2,2,1}->{1,1,1,1},{1,1,2,2,1}-> {2,1,2,2},{1,2,1,2,1}->{2,2,1,2},{1,2,2,1,1}->{1,1,1,1},{1,2,2,1,1}->{1,2,2,2}, {1,2,2,1,1}->{2,2,2,1},{2,1,1,1,2}->{1,1,1,1},{2,1,1,1,2}->{2,1,2,2},{2,1,1,1,2}-> {2,2,1,2},{2,1,1,2,1}->{2,2,2,1},{2,1,2,1,1}->{2,1,2,2},{2,2,1,1,1}->{1,1,1,1}, {2,2,1,1,1}->{2,2,1,2},{2,2,1,1,1}->{2,2,2,1},{2,2,2,2,2}->{1,2,2,2},{2,2,2,2,2}-> {2,1,2,2},{2,2,2,2,2}->{2,2,1,2},{2,2,2,2,2}->{2,2,2,1},{1,1,1,1,1,2}->{1,1,1,2,2}, {1,1,1,1,1,2}->{1,1,2,1,2},{1,1,1,1,1,2}->{1,2,1,1,2},{1,1,1,1,2,1}->{1,1,2,2,1}, {1,1,1,1,2,1}->{1,2,1,2,1},{1,1,1,1,2,1}->{2,1,1,1,2},{1,1,1,2,1,1}->{1,1,1,2,2}, {1,1,1,2,1,1}->{1,2,2,1,1},{1,1,1,2,1,1}->{2,1,1,2,1},{1,1,2,1,1,1}->{1,1,2,1,2}, {1,1,2,1,1,1}->{1,1,2,2,1},{1,1,2,1,1,1}->{2,1,2,1,1},{1,1,2,2,2,2}->{1,1,1,2,2}, {1,1,2,2,2,2}->{1,1,2,1,2},{1,1,2,2,2,2}->{1,1,2,2,1},{1,2,1,1,1,1}->{1,2,1,1,2}, {1,2,1,1,1,1}->{1,2,1,2,1},{1,2,1,1,1,1}->{2,2,1,1,1},{1,2,1,2,2,2}->{1,2,1,1,2}, {1,2,1,2,2,2}->{1,2,1,2,1},{1,2,2,1,2,2}->{1,1,1,2,2},{1,2,2,1,2,2}->{1,2,2,1,1}, {1,2,2,2,1,2}->{1,1,2,1,2},{1,2,2,2,1,2}->{1,2,1,1,2},{1,2,2,2,2,1}->{1,1,2,2,1}, {1,2,2,2,2,1}->{1,2,1,2,1},{1,2,2,2,2,1}->{1,2,2,1,1},{1,2,2,2,2,1}->{2,2,2,2,2}, {2,1,1,1,1,1}->{2,1,1,1,2},{2,1,1,1,1,1}->{2,1,1,2,1},{2,1,1,1,1,1}->{2,1,2,1,1}, {2,1,1,1,1,1}->{2,2,1,1,1},{2,1,1,2,2,2}->{1,1,1,2,2},{2,1,1,2,2,2}->{2,1,1,1,2}, {2,1,1,2,2,2}->{2,1,1,2,1},{2,1,1,2,2,2}->{2,2,2,2,2},{2,1,2,1,2,2}->{1,1,2,1,2}, {2,1,2,1,2,2}->{2,1,2,1,1},{2,1,2,2,1,2}->{1,1,2,2,1},{2,1,2,2,1,2}->{2,1,1,1,2}, {2,1,2,2,2,1}->{2,1,1,2,1},{2,1,2,2,2,1}->{2,1,2,1,1},{2,2,1,1,2,2}->{1,1,1,2,2}, {2,2,1,1,2,2}->{1,2,1,1,2},{2,2,1,1,2,2}->{2,2,1,1,1},{2,2,1,1,2,2}->{2,2,2,2,2}, {2,2,1,2,1,2}->{1,1,2,1,2},{2,2,1,2,1,2}->{1,2,1,2,1},{2,2,1,2,2,1}->{1,1,2,2,1}, {2,2,1,2,2,1}->{2,2,1,1,1},{2,2,2,1,1,2}->{1,2,1,1,2},{2,2,2,1,1,2}->{1,2,2,1,1}, {2,2,2,1,1,2}->{2,1,1,1,2},{2,2,2,1,1,2}->{2,2,2,2,2},{2,2,2,1,2,1}->{1,2,1,2,1}, {2,2,2,1,2,1}->{2,1,1,2,1},{2,2,2,2,1,1}->{1,2,2,1,1},{2,2,2,2,1,1}->{2,1,2,1,1}, {2,2,2,2,1,1}->{2,2,1,1,1},{2,2,2,2,1,1}->{2,2,2,2,2},{2,2}->{1,1,2},{2,1,2,2}-> {1,1,1,2,2},{2,2,1,2}->{1,1,2,1,2},{2,2,2,1}->{1,1,2,2,1},{1,2,2,2}->{1,2,1,1,2}, {2,1,1,1,2}->{1,1,1,1,1,2},{2,1,1,2,1}->{1,1,1,1,2,1},{2,1,2,1,1}->{1,1,1,2,1,1}, {2,2,1,1,1}->{1,1,2,1,1,1},{2,2,2,2,2}->{1,1,2,2,2,2},{1,2,2,1,1}->{1,2,1,1,1,1}}; G0=Join@@Table[Tuples[{1,2},k], {k, 6}]; GraphPlot[G, VertexLabeling->True, EdgeLabeling->False, DirectedEdges->True, VertexCoordinateRules->((#->{Length[#],Automatic}) & /@ G0)] Needs["Combinatorica`", "GraphUtilities`"] GG=ToCombinatoricaGraph[G]; FindCycle[GG] returns `{24, 14, 27, 18, 25, 17, 24}`. ![enter image description here](http://i.stack.imgur.com/i9oFG.jpg) My digraph represents a chain complex of modules (homological algebra), hence the desire to draw it in such a way. |
48894 | Partial zeta curlicues | I asked a question at MSE and Raymond Manzoni provided an excellent answer that included these visuals: ![enter image description here](http://i.stack.imgur.com/hLJyA.gif) ![enter image description here](http://i.stack.imgur.com/0bIpk.gif) I made a very basic attempt at recreation with y = 10000; ListLinePlot[Table[{Im[E^(-I y Log[k])/Sqrt[k]], Re[E^(-I y Log[k])/Sqrt[k]]}, {k, 1, Round[Sqrt[10000]]}]] but a very messy plot resulted. I tried various parametric plots, but was equally disappointed with the results. Could someone please point me in the right direction to achieve the curlicues (that were apparently applet- generated) in the answer listed? |
48895 | position of element in a list using a function | How can I find in a list `l` the positions of all elements satisfying a boolean function `f`. For example, how can I pick in `{1, 1, 1, 3, 2, 4, 1, 4, 1, 1, 2, 1}` the first element that does not equal `1`? A minimized version of an aswer (short code) is welcome. |
25060 | find where 3 inequalities are simultaneously greater than zero | I have 3 functions: `f11[l]`, `f12[l]` and `f13[l]`, and I would like to know for which values of `l` these 3 functions are greater than zero. How do I do it analytically or numerically or graphically in _Mathematica_? For some of the functions I want to consider only the real part. Example: f11[l] = Root[ 54 + 9 Sqrt[6] l + (-108 - 15 Sqrt[6] l) #1 + (72 + 7 Sqrt[6] l) #1^2 + (-20 - Sqrt[6] l) #1^3 + 2 #1^4 &, 1]; f12[l] = Root[ 54 + 9 Sqrt[6] l + (-108 - 15 Sqrt[6] l) #1 + (72 + 7 Sqrt[6] l) #1^2 + (-20 - Sqrt[6] l) #1^3 + 2 #1^4 &, 2]; f13[l] = Root[ 54 + 9 Sqrt[6] l + (-108 - 15 Sqrt[6] l) #1 + (72 + 7 Sqrt[6] l) #1^2 + (-20 - Sqrt[6] l) #1^3 + 2 #1^4 &, 3]; |
21227 | Making Axes logarithmic in 3d plots | I've been trying to get loglog plots in 3D, but to no avail. My initial approach was to take the logarithm inside the plot i.e Plot3D[Log[10,function[a, b]],{a, 1, 100000},{b, 1, 1000000}] but now I'm looking for a way to logarithm-ise the axes as well. Any help would be greatly appreciated! |
43878 | is there a way to construct a pattern that would trigger when an expression is used as a held/unevaluated in some form? | For example, consider the following code f[x_] := (Print["evaluated f"]; workWith[x]); We use it, then f evaluates: f[x] (* evaluated f, workWith[x] *) When we use f in the assignment, f does not evaluate: f[x] = 1 (* 1 *) Is it possible to construct a pattern that will detect cases when f[x] is used unevaluated like in the Set command? For example, one could do f /: Set[f[x_], rhs___] := somework when f is not evaluated but that would only work specifically for the Set command. Is there a way to make it more generic?, for example like this HeldExpression[f[x_]] := somework when f is not evaluated would be great but, of course, HeldExpression does not exist. I realized that f /: HoldPattern[_[___,f[x_],___]] := work with f when used actually triggers even if f is used in the context of the Set command, but it does not discriminate between to be evaluated (y=f[x];) and not to be evaluated (f[x]=1;) scenarios. Regards Zoran |
41614 | Shuffle product of two lists | I want to do the following: I have two lists `{a_1,...a_n}, {b_1,...,b_n}` and I would like to build now all shuffles out of this. This means all unions of these lists while still keeping the individual order of the parent lists. Example {a,b}, {c,d} > > {{a,b,c,d},{a,c,b,d},{c,a,b,d},{c,a,b,d},{a,c,d,b},{c,d,a,b}} > Is there any easy way to do this? |
25065 | rotating 3d text | Is it possible to create a 3d rotating text like this: ![enter image description here](http://i.stack.imgur.com/JwlMN.jpg) animation here. Here is my try so far: text = Style["Mathematica Mathematica ", 128]; g = ParametricPlot3D[{Cos[theta], Sin[theta], rho}, {theta, -Pi, Pi}, {rho, 0, 1}, PlotStyle -> Texture[text], Lighting -> "Neutral", Mesh -> None, PlotRange -> All, TextureCoordinateScaling -> True, Boxed -> False, Axes -> False, SphericalRegion -> True]; Animate[Show[g, ViewPoint -> {2 Cos[x], 2 Sin[x], 0}], {x, 0, 2 \[Pi]}] ![enter image description here](http://i.stack.imgur.com/RvxDE.gif) The problem is that the text is a texture and one can't look through it. We can use Simon Woods's nice `filledCurveToPolygons3D` function at here to change the the text into polygons, but wrap the polygon to a cylinder seems require non-geometric transformation, which I don't know how to do. ![enter image description here](http://i.stack.imgur.com/k5qIb.jpg) possible related questions: * How can I create a 3D FilledCurve object? * Character edge finding * Non-geometric transformation of Graphics3D primitives * How can I wrap text around a circle? |
56750 | Is there something wrong with this piece of code involving Manipulate? | I am playing around with the `Manipulate` sentence. I think the following code is right, and actually Mathematica 9.0 doesn't return any error message, but I am observing something strange: * when I execute the `Manipulate` sentence, the fan of my laptop starts _overworking_ (I do not know if this expression is right) making lot of noise, which usually means that there is a heavy process running, and if I delete the result of the code, the fan returns to its normal state; and * the vertical line at the right of the result of the code is highlighted in black and slightly _twinkling_. This is the code: Manipulate[f[x_] := Sin[x]; {Plot[f[x], {x, 0, a}], f[a]}, {a, 1, 50}] And this is the image of what I get, where you can see the black vertical line: ![Manipulate causing computer strange behaviour](http://i.stack.imgur.com/3QfQX.png) So, my question is: do you get the same computer behaviour, or is it just me? And, is there something wrong with this piece of code? |
1450 | Suppress Mathematica Kernel taskbar tab when using .NETLink | Is there a possibility to suppress the Mathematica Kernel taskbar tab when accessing it through .NETLink on Windows? |
48025 | Financial Derivative european call option | When estimating financial derivatives like a european call option there is a parameter named: dividend paid per time unit. What does this mean, I have not been able to find any more information about dividend per time unit, and what it means. Could someone give me an example of how this work, does it mean dividend par share or? Example: 0.50 in dividend payed twice, once in two months, and once in 5 months. current price 40 strike 40 vol 30% annual interest 9% annual time to maturity is six months. If i discount and sum the dividend and subtract it from the share price I get 40 - 0.9741 as new share price. This give the option price 3.67. Which is the same result as my text book. However if I use dividend as in the function I am not able to get the correct answer? Here is the code: Input: FinancialDerivative[{"European", "Call"}, {"StrikePrice" -> 40, "Expiration" -> 0.5}, {"InterestRate" -> 0.09, "Volatility" -> 0.3, "CurrentPrice" -> 39.0259`}] Output: 3.67126 This is how new share price is calculated and output is correct according to tekstbook. `40 - ((0.5 E^(-0.09*2/12)) + (0.5 E^(-0.09*5/12)))` However, the function provides an option for dividend in its output but I am not able to use it to get same result: FinancialDerivative[{"European", "Call"}, {"StrikePrice" -> 40, "Expiration" -> 0.5}, {"InterestRate" -> 0.09, "Volatility" -> 0.3, "CurrentPrice" -> 40, "Dividend" -> 0.9741531786619422`}] Output 0.0437682 Clearly it is because dividend put in is in the wrong format, however thats why I wonder how dividend payed per time unit means and how to get the correct price using Dividend in function. I have to say, I have looked through two well known option pricing books and no were does it say per time unit so It would have been nice if they could provide a bit more info in the documentation. |
32236 | Export list as a .csv file, but not seeing the commas | My goal is to export a list of numbers into a file, with a comma between each value. Executing the following commands seems to produce a file with a new line between each entry. v = {1.1, 2.2, 3.3}; SetDirectory@NotebookDirectory[]; Export["v.csv", v, "csv"]; When I open the file with notepad, what I see is 1.1 2.2 3.3 What I would like to see is comma separated values, like the following: 1.1, 2.2, 3.3 Recommendations? Thanks. |
32485 | Order of evaluation in nested expression | I am trying to make a function that works as follows: Integrate 1 for all t in the interval $ [0,1] $ such that the first element of function `vstar` is positive. `vstar` is a function that outputs a pair of real numbers. Unfortunately the test `vstar[t, a1, a2, f1, f2, σ]][[1]] > 0` does not work as expected (this is waht I've tried): `D1[f1_, a1_, f2_, a2_,σ_] := NIntegrate [If[vstar[t, a1, a2, f1, f2,σ][[1]] > 0, 1, 0] f[t], {t, 0, tup}, AccuracyGoal -> 8];` The way it is, Mathematica tests if the first slot of `vstar` is greater than zero (that is $ t>0 $) rather than testing if the first part of the **output** of `vstar` is greater than zero. `vstar` is defined so that it evaluates only for numerical values. I think I need to evaluate the function `vstar` before the test is performed, I just don't know how to do it - could someone explain how? p.s. For further reference, here's the code of `vstar`: vstar[tt_?NumericQ, aa1_?NumericQ, aa2_?NumericQ, ff1_?NumericQ, ff2_?NumericQ, σσ_?NumericQ] := Module[{list}, list = {objm, objs1, objs2} /. {t -> tt, a1 -> aa1, a2 -> aa2, f1 -> ff1, f2 -> ff2, σ -> σσ}; If[list[[1]] < 0 && list[[2]] < 0 && list[[3]] < 0, {0, 0}, Which[Ordering[list , -1] == {1}, {v1, v2} /. vm, Ordering[list , -1] == {2}, {v1 /. v1s, 0}, Ordering[list, -1] == {3}, {0, v2 /. v2s}] /. {t ->tt, a1 -> aa1, a2 -> aa2, f1 -> ff1, f2 -> ff2, σ -> σσ}]] |
47279 | Problem with SquareWave in NDSolve | I would like to have a triangulare signal drive a ODE system, using SquareWave[]. Something seems to go wrong though during integration. `Uext'[t]` and `rate SquareWave[rate/(4 umax) t` evaluate to different graphs. What is the problem here? Thanks! rate = 0.06; umax = 0.9; sol2 = Flatten[ Evaluate[{Uext[t], Uext'[t], rate SquareWave[rate/(4 umax) t]} /. NDSolve[ { Uext'[t] == rate SquareWave[rate/(4 umax) t], Uext[0] == -umax }, {Uext}, {t, 0, 400}]]]; Show[ Plot[Evaluate[{sol2[[2]], sol2[[3]]}], {t, 0, 400}], AspectRatio -> 1, PlotRange -> Automatic, Frame -> True, ImageSize -> {500, 500}] |
37733 | Finding common roots of a specific system of polynomials | Some of my colleges are interested in finding common zeros of the following four polynomials: {-1 + 12*t^4 + 24*t^2*w^2 + 12*w^4 + 4*x^4 + 12*y^4 + 24*y^2*z^2 + 12*z^4, -1 + 8*t^2 - 16*t^4 + 8*w^2 - 32*t^2*w^2 - 16*w^4 + 16*t^2*w*x + 16*w^3*x + 16*w*y + 64*w^2*x*y + 8*y^2 - 24*t^2*y^2 + 40*w^2*y^2 + 64*w*x*y^2 + 16*x*y^3 - 16*y^4 - 16*t*z + 96*t^3*z + 96*t*w^2*z + 64*t*w*x*z + 128*t*w*y*z + 64*t*x*y*z + 96*t*y^2*z + 8*z^2 + 40*t^2*z^2 - 24*w^2*z^2 + 16*x*y*z^2 - 32*y^2*z^2 + 96*t*z^3 - 16*z^4, -2 + 3*t^2 + 3*w^2 + x^2 + 3*y^2 + 3*z^2, -(t^3*x) - t*w^2*x + t*y - 2*t^3*y - 2*t*w^2*y - 4*t*w*x*y + 4*t*x*y^2 - 4*t*y^3 + w*z - 4*t^2*w*z - 4*w^3*z + 4*w^2*x*z - 4*w*x*y*z - 2*w*y^2*z - x*y^2*z - 4*t*y*z^2 - 2*w*z^3 - x*z^3} which are of degree $4$, in the five variables $x$, $y$, $z$, $w$, and $t$. I have tried `GroebnerBasis`, (also in `Macaulay2`), to simplify this a bit, before feeding it to `Reduce`, but no luck, it takes all the memory of my computer and never finishes. I am looking for a simpler way to represent the ideal generated by the four polynomials above. So, if anyone have some special trick to attack very specific systems like this, I would appreciate it. EDIT: I am not so familiar with the details, but this is a simplification of a system of the form $p1=p2=p4=p4=1/4$ for four homogeneous degree-4 polynomials, so this I think could help. |
18036 | How do I replace a variable with the answer from a solve function in the form k-> number + variables? | > **Possible Duplicate:** > Using the result of Solve in subsequent calculations > extract values from replacement list I am trying to define a variable (`k1`) as the expression that is given as one of the possible solutions from the `Solve` function so that when I have "`k1`" further in the program, it will use the solution from the `Solve` function. Here is the code in question, simplified: Solve[Eq4==0,k1] (* {{k1-> 4.3*(2.4+1.4*c2+Sqrt[4.6*c2^2+2.02*c2^4]},{k1->4.3*(2.4+1.4*c2-Sqrt [4.6*c2^2+2.02*c2^4]} *) So then I have been typing `k1:=` on the next line and copy-pasting this part in to get: k1:=4.3*(2.4+1.4*c2+Sqrt[4.6*c2^2+2.02*c2^4 So that I can use it in: Eq3:=m1*k3+m3*k1+c1*c3-c2^2 Solve[Eq3==0,c2] To get a value for `c2`. Surely there is a way to avoid copy-pasting? I feel like the . is supposed to come into play, but I don't understand the syntax for it and can't figure out what to search for to use it! Thanks! Kaitlin |
6794 | How to extract and compute on the diagonal entities of a sparse matrix very fast? | As could be seen in the following code: AbsoluteTiming[ n = 100000; A = SparseArray[{ Band[{1, 120}] -> -2., Band[{950, 1}] -> -1., Band[{1, 1}] -> 20., Band[{1, 100}] -> 2., Band[{6, 800}] -> 1.1}, {n, n}, 0.]; b = SparseArray[Table[1., {i, n}]]; DA = Diagonal[A]; (* I think constructing B is time-consuming. My ParallelTable[] does not work or show any improvement herein! *) B = SparseArray[Table[(1/DA[[i]]), {i, 1, n}]]; V = DiagonalMatrix[SparseArray[B]]; ] I'm trying to extract the diagonal entries of a very large sparse matrix and to compute $1/a_{ii}$ to make my new large sparse diagonal matrix $V$. This process takes around 18 seconds, and I would like to accelerate this process. |
27375 | How to integrate a function over a 3D planar polygon? | I am trying to integrate a function over a planar polygon in 3D. In 2D, this is fairly straightforward, using either answer from this question (I use the second answer). If we use an equilateral triangle centered at the origin as our polygon: f[pos_List] := 1 basetri={{1/2,- (1/6) Sqrt[3],0},{0,1/3 Sqrt[3],0},{-(1/2),- (1/6) Sqrt[3],0}} inPolyQ[poly_,pt_]:=2.π==Total[VectorAngle@@@Transpose@{#,RotateRight[#]}]&@(#-pt&/@poly) we can integrate our function `f` (in this case, this function will return the area of the triangle): NIntegrate[ f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,Min@basetri[[;;,1]],Max@basetri[[;;,1]]}, {y,Min@basetri[[;;,2]],Max@basetri[[;;,2]]} ] (* Out[]:= 0.43265 *) which is pretty close to the exact value of `Sqrt[3]/4` (`~0.433013`). (Yes, the are a bunch of errors thrown.) This can also be done over infinite bounds (see this answer): NIntegrate[f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,-Infinity,Infinity},{y,-Infinity,Infinity} ] (* Out[]:= 0.433321 *) which is also pretty close to the exact value. (I'll leave alone for now the question of which bounds should give better results...) The problem arises when doing this in 3D: NIntegrate[ f[{x,y,z}] Boole[inPolyQ[basetri, {x, y, z}]], {x, -Infinity,Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity} ] (* Out[]:= 0 *) It gives this error: > NIntegrate::izero: Integral and error estimates are 0 on all integration > subregions. Try increasing the value of the MinRecursion option. Increasing `MinRecursion` doesn't help. I suspect that because this is a planar polygon, it has trouble figuring out exactly where that infinitesimally-thin plane is that satisfies the inequality actually is. So, **how can I integrate a function over an arbitrarily-oriented planar polygon in 3D?** For what it's worth, at the very least it would be an acceptable answer for my current problem if it just works with a triangular region (in 3D), but I figured I'd leave the question more general if there's a way to do it. |
6790 | Trying to extract information from an MDB file. Import is too slow | I am running a Linux box and as usual the documentation for this type of box is not great. I am trying to open up and extract and possibly include later on information from a "mdb" file. The file size is not big, but bigger than 100 MB. Unfortunately, the `Import` function does not work at all for certain requests. It takes too long and then the Kernel breaks down/quits while trying to process the import request. Is there any other way ? I understand there is some sort of way to do things using OBDC. Unfortunately, the documentation is written for windows machines and I have little experience in handling database connectivity with OBDC under Linux. Ideas greatly appreciated. |
46138 | How to work with Interpolating Function? | I'm starting using Mathematica. I have two coupled differential equations and after using NDSolve the output is in the form of a Interpolating Function. I want to Plot the square modulus of one of the two solutions, but after several trials the plot is still empty. I want to know how to work with this function. sol = NDSolve[{a1'[t] == -I*V12*Exp[-I*w21*t]*a2[t], a2'[t] == -I*V21*Exp[I*w21*t]*a2[t], a1[0] == 1, a2[0] == 0}, {a1, a2}, {t, 40}] (* {{a1->InterpolatingFunction[{{0.,40.}},"<>"], a2->InterpolatingFunction[{{0.,40.}},"<>"]}} *) f1=a1->InterpolatingFunction[{{0.,40.}},"<>"] f2 = Conjugate[fun] // ComplexExpand f3 = fun*gun Plot[f3, {t, 0, 40}] Where `fun` is `f1` and `gun` is `f2`. |
43581 | Why does Simplify[b-a] give -a+b and not b-a? | `Simplify[b - a]` results in `-a + b`. I prefer `b - a`, which is a bit simpler (3 symbols instead of 4). Can I make _Mathematica_ to think the same way? I believe one needs to redefine the `ComplexityFunction`. |
45094 | How to prevent expressions like b-a from being transformed to -a+b? | When I enter some expression like `a-b`, it is shown as I want, i.e. as I entered it. But in some cases the variables aren't sorted alphabetically, and entering e.g. `b-a` I get `-a+b` as output. This makes it harder to read more complex expressions, so I'd like to avoid it. This also includes differences inside the expressions. How can I prevent placing negatives before positives? Maybe a good idea would be to somehow tell Mathematica to prefer such sorting of variables which minimizes length of the expression. |
43907 | How to change the order of the variables in an output? | I have this output: > > a(b + c)d + 3 > But I want it to become like this: > > ad(b + c) + 3 > How can I do that? Is there a way without using `HoldForm` to do that? |
28560 | Place plot markers in front of error bars with ErrorListPlot | I'm making an `ErrorListPlot` where the error bars are a different color then the markers and it works, however, the error bars are drawn in front of the markers and it looks funny. See the following example data = {{#1, #2}, ErrorBar[#3]} & @@@ RandomReal[1, {10, 3}]; Needs["ErrorBarPlots`"] ErrorListPlot[ data, PlotRange -> All, BaseStyle -> AbsoluteThickness[2], PlotStyle -> RGBColor[159/255, 158/255, 204/255], PlotMarkers -> {{Graphics@{Opacity[1], Darker@Blue, Disk[]}, 0.01 5}} ] ![enter image description here](http://i.stack.imgur.com/rEdpp.png) See how the error bars are drawn over the markers. I want them to be behind. I tried to use `Epilog` to redraw the markers but they don't have a uniform aspect ratio. `Epilog -> ({Opacity[1], Darker@Blue, Disk[#, 0.025]} & /@ data[[All, 1]])` ![enter image description here](http://i.stack.imgur.com/F9DlD.png) |
46134 | DynamicModule with Plots and EventHandler | I am making a little animation in _Mathematica_ , along the lines of some of the Wolfram demo projects. I'd like to animate a simulated trajectory of a random process (say a Poisson process), and while it is running, change the parameters using `"MouseDown"`. Here's a trajectory animated in the front end: Framed @ DynamicModule[{t = 0.001}, trajnormal = RandomFunction[PoissonProcess[1], {0, 100}]["PathFunction"]; step = .05; Column[{ Dynamic[t = If[trajnormal[t] <= 50, t + step, t] ] , Dynamic[Plot[trajnormal[x], {x, 0.001, t}, PlotRange -> {{0, 60}, {0, 60}}, PlotPoints -> 1000, ImageSize -> 500] ] }] ] And here's my failed attempt at using `EventHandler` to change the simulated function with a mouse click: Framed @ DynamicModule[{t = 0.001, i = 1}, s = 0; step = .05; trajnormal = RandomFunction[PoissonProcess[1], {0, 100}]["PathFunction"]; trajdiscount = RandomFunction[PoissonProcess[5], {0, 100}]["PathFunction"]; (* show[1] is trajectory of Poisson[1] process *) show[1] = Dynamic[Plot[50 - trajnormal[x], {x, 0.001, t}, PlotPoints -> 1000, PlotRange -> {{0, 70}, {0, 55}}, ImageSize -> 500] ]; (* show[2] is trajectory of Poisson[1] with Poisson[5] added at time of click = s *) show[2] = Dynamic[Plot[50 - trajnormal[x] - trajdiscount[Max[x - s, 0]], {x, 0, t}, PlotRange -> {{0, 70}, {0, 55}}, ImageSize -> 500, PlotPoints -> 1000] ]; EventHandler[ EventHandler[ Column[{ Dynamic[t = If[trajnormal[t] <= 50, t + step, t] ] , Dynamic[s], Dynamic[ show[i] ] }], "MouseDown" :> (i = 2)], "MouseDown" :> (s = t), PassEventsUp -> True ] ] The mouse click changes the function from `show[1]` to `show[2]`, but the plots are not displayed. I'd appreciate any corrections or help. |
54545 | Is it possible to define new PlotTheme? | In version 10 one can define, say, $PlotTheme = "Scientific" Which changes the appearance of all plots. This is fantastic because on the one hand, I can have nice plots very easily and globally (i.e. No need to tune every option in `Plot[...]`), and on the other hand, when I exchange code with my collaborators, they may not have Mathematica 10 and defining `$PlotTheme` is harmless for previous versions. However, none of the provided plot themes fit my need and I would need to combine some options (for example, the lines should on the one hand have colors, and on the other hand, has solid/dashed/dotted styles). Thus I wonder if it is possible to define a plot theme myself, combining a few builtin themes and specify it globally using $PlotTheme = "myStyle" Note: This is related to Specifying non-conflicting PlotTheme options (which focuses on changing and tuning plot theme as `PlotStyle`, etc.), and @kguler has already provided a great answer. |
148 | Get a "step by step" evaluation in Mathematica | Is it possible in Mathematica to get a step-by-step evaluation of some functions; that's to say, outputting not only the result but all the stages that have led to it? **Example :** Let's say I want to know the steps to get the derivative of $\cos x\times\exp x$; it should first tell me that it's equal to $\frac{d}{dt}(\exp x)\times\cos x+\exp x \times \frac{d}{dt}(\cos x)$ and then render the result to say $\exp{x}\times(\cos x-\sin x)$. |
18114 | Interested in knowing what substitutions were made to perform an Integrate[]? | > **Possible Duplicate:** > How does Mathematica integrate? Mathematica can perform the following integral with apparent ease (returning _very_ fast with the result) Integrate[(1 - a Tan[b x]^2)^(-1/2), x] The answer happens to be (ArcTan[(Sqrt[2] Sqrt[1 + a] Sin[b x])/Sqrt[ 1 - a + (1 + a) Cos[2 b x]]] Sqrt[1 - a + (1 + a) Cos[2 b x]] Sec[b x])/(Sqrt[2] Sqrt[1 + a] b Sqrt[1 - a Tan[b x]^2]) Is there a way to have Mathematica show what sort of substitutions it made along the way? |
29435 | Is it possible for Mathematica to give the step by step process of Reduce command? | Input: Reduce[3 x^2 - 2 a x + a^2 - 1 >= 0 && x > a, x] // TraditionalForm Output: (a<=-Sqrt[(3/2)]\[And]x>a) \[Or](-Sqrt[(3/2)]<a<-(1/Sqrt[2])\[And](a<x<=a/3-1/3 Sqrt[3-2 a^2]\[Or]x>=1/3 Sqrt[3-2 a^2]+a/3)) \[Or](-(1/Sqrt[2])<=a<1/Sqrt[2]\[And]x>=1/3 Sqrt[3-2 a^2]+a/3)\[Or](a>=1/Sqrt[2]\[And]x>a) My Solution by hand: ![My Solution by hand:](http://i.stack.imgur.com/KuKZj.jpg) |
18798 | How to display detailed output in Mathematica | > **Possible Duplicate:** > Get a “step by step” evaluation in Mathematica > How does Mathematica integrate? I want to display more detailed output from a calculation. The default command for calculation that I know is Shift + Enter. Is there another command to display detailed output. UPDATE ![enter image description here](http://i.stack.imgur.com/NsDbG.png) |
56687 | Step by step solution of an equation | How I solve this system of equations STEP BY STEP in mahematica. \begin{align} (x + 1)^2 [(p - l)^2 + (q - m)^2] &= (a - l)^2 + (b - m)^2 \\\ (x + 1)^2 [(p - a)^2 + (q - b)^2] &= x^2[(a - l)^2 + (b - m)^2]\end{align} For $p$ and $q$ in terms of $x, l, m, a, b$. |
2239 | is there an equivalent of "show" steps? | > **Possible Duplicate:** > Get a "step by step" evaluation in Mathematica In wolfram alpha, when preforming for complicated integrals there's a 'show steps' option that explains how the integral was computed. Is there any way to do that using mathematica? |
21433 | Showing steps Mathematica uses for Resolve[ForAll[...]] | I have a quite complicated function of 2 variables: f[n_, dj_] = (6*(2 - n + dj*(5 + 2*n))*(7 + n + dj*(5 + 2*n))*(-965 + 2*dj^4*(5 + 2*n)^4 + dj^3*(5 + 2*n)^3*(35 + 2*n) - 9*dj^2*(5 + 2*n)^2*(-19 + n + 2*n^2) + dj*(-1 + 2*n)*(5 + 2*n)*(-73 + n*(-26 + 11*n)) - n*(473 + n*(111 + n*(-37 + 8*n)))))/((5 - n + dj*(5 + 2*n))*(1 - 5*n + dj*(33 + 6*n + 4*dj*(5 + 2*n)))* Sqrt[(5 + 2*n)^2*(5 - n + dj*(5 + 2*n))*(1 - 5*n + dj*(33 + 6*n + 4*dj*(5 + 2*n)))*(2477 + 12*dj^4*(5 + 2*n)^4 + 4*dj^3*(5 + 2*n)^3*(59 + 2*n) - dj^2*(5 + 2*n)^2*(-1573 + 4*n*(1 + 5*n)) + n*(-2230 + n*(-411 + 4*n*(29 + 8*n))) - 2*dj*(5 + 2*n)*(-1937 + n*(435 + 2*n*(87 + 8*n))))]) I want to show that this function is always less than 1 for $n \geq d_j \geq 1$. Indeed when I do Resolve[ForAll[{n, dj}, n >= dj >= 1, f[n, dj] < 1]] I get `True`. I'm just wondering if there's a way I could show this more rigorously (i.e. "by hand," or ask _Mathematica_ to show steps it used to get `True`), since I need to put this in a paper. |
6811 | How does Mathematica integrate? | Basically, this question can be considered to be an extenstion to my other question. What I wanted to do was this integral as homework (it is indefinite BTW so no approximations using Simpson's Rule or Boole's Rule) $$\int(x^{3m}+x^{2m}+x^{m})(2x^{2m}+3x^{m}+6)^{\frac1{m}}dx$$ So using Mathematica's `Integrate` function the answer was ![Answer](http://i.stack.imgur.com/BnYHD.png) Apparently, after rigorous substitutions and transformations the answer was found to be correct. What I wanted to know was how Mathematica integrates these functions that require a human tons of intuition to compute, within seconds, and often in the most simple way and also presents them in the most humanly computable form. (Even differentiation for that matter) |
29362 | The underlying process of Integrate[] | Integrate[x^4 E^-x^2, {x, 0, +∞}] Output: > > (3 Sqrt[π])/8 > Can someone explain to me the specific calculation process ? |
51121 | Showing Steps of Calculations | I'm solving a a differential equation in Mathematica and was wondering how to show the steps, like how Wolfram|Alpha does it, in the program. Any ideas? |
13905 | Reducing a statement with Mathematica, step by step | > **Possible Duplicate:** > Get a “step by step” evaluation in Mathematica I have a list of inequalities combined with quantifiers. And _Mathematica_ is able to reduce to simple statement with the `Reduce[]` command , is it possible to see how it comes up with it. Reduce[Exists[{p, \[Eta], \[Theta]}, \[Eta] (p - 1) < 1/ 2 && \[Lambda] p < 2 && (1 - \[Lambda]) p/(p - 1) < e && \[Theta] (1 - \[Lambda]) p/(p - 1) < 1/2 + \[Eta] && 0 < \[Lambda] < 1 && 1 < p && e > 0 && \[Theta] > 0 && ((1/2 - \[Eta]) (1 + 1/(e - (1 - \[Lambda]) p/(p - 1))) < 1 || (1/2 - \[Eta]) (1 + 1/(e - (1 - \[Lambda]) p/(p - 1))) < \[Theta] e)], {\[Lambda], e}, Reals] Thanks! |
45208 | How to find out how Mathematica performed an integration? | In terms of integration, I usually utilize Mathematica 9 to compute scattering amplitudes in quantum field theory. Recently, I employed it to compute a particularly difficult integral, and it outputted a lengthy combination of hypergeometric Appell functions. Is there any way I can determine how Mathematica actually 'evaluated' the integral, or more appropriately, 'manipulated' the integral into the form required to equate it to a bunch of Appell functions. What I'm looking for is essentially what Wolfram Alpha does when you click 'step by step solution,' but for Mathematica. |
56121 | How do I solve for one variable in terms of other variables in Mathematica? | I'm fairly new to Mathematica, and I'm trying to solve a complicated equation with multiple variables. I've tried the following... Reduce[-2 (m^2/36 + n^2/4)^(1/4) Sin[1/2 ArcTan[n/2, -(m/6)]] == y, {n}] Where I would like to have n on one side of the equation, defined by m and y. Is this the correct notation and I just need to wait longer for the equation to solve? Or am I making a mistake somewhere? |
56120 | Elements in `Reap` and `Sow` | Can someone help explain it to me: 1. How does here `e` come out? Why `b` disappears? Reap[Sow[a]; b; Sow[c]; Sow[d]; e] ![enter image description here](http://i.stack.imgur.com/FQYYz.jpg) 1. How does here `4` come out? Reap[Sow[1, x]; Sow[2, y]; Sow[3, x]; Sow[4, y], x] ![enter image description here](http://i.stack.imgur.com/3NmNF.jpg) Thanks a lot! |
54596 | How to increase significant digits in Mathematica | How can I increase the number of significant digits in Mathematica? When I import a matrix, an element like 112.5276 is rounded to 112.528. I would like to increase the number of significant digits globally. |
56125 | How to automatically plot asymptotes? | I'm a newbie to Mathematica and I'm reading through "The Student's Introduction to Mathematica, Second Edition" and am on the "Using Mathematica’s Plot Options" section of chapter 3. The examples for using the Exclusions option for plotting asymptotes uses both specific x-values: h[x_] := ((x - 3) (x - 4))/((x - 2) (x - 5)); Plot[h[x], {x, 0, 7}, Exclusions -> {x == 2, x == 5}, ExclusionsStyle -> Dashed] ![enter image description here](http://i.stack.imgur.com/EBClV.png) as well as using a function to automatically determine the vertical asymptotes: Plot[Tan[x], {x, 0, 4 \[Pi]}, Exclusions -> {Cos[x] == 0}, ExclusionsStyle -> Directive[Gray, Dashed], Ticks -> {Range[0, 4 \[Pi], \[Pi]/2], Automatic}] ![enter image description here](http://i.stack.imgur.com/Mmgib.png) Using an Exclusions function for the first equation instead of the specific x-values works as expected: Plot[h[x], {x, 0, 7}, Exclusions -> {h[x] == 0}, ExclusionsStyle -> Dashed] I attempted to use a function from earlier in the book in the same way and it did not give me the asymptote as expected: f[x_] := (x^5 - 4 x^2 + 1)/(x - 1/2); Plot[f[x], {x, -1, 2}, Exclusions -> {f[x] == 0}, ExclusionsStyle -> Dashed] ![enter image description here](http://i.stack.imgur.com/1AhPB.png) even though specifying the x-value did work: Plot[f[x], {x, -1, 2}, Exclusions -> {x == 1/2}, ExclusionsStyle -> Dashed] ![enter image description here](http://i.stack.imgur.com/GQ9FK.png) My attempts to test for something other than 0 (i.e. Undetermined, Infinity, ComplexInfinity etc.) didn't work either. What am I missing here? Also, I haven't seen anything yet regarding plotting horizontal or oblique asymptotes and I don't know if they're covered in this book so any references/tips etc. on those topics would help immensely. Any help is greatly appreciated. Gary |
56126 | Is it possible to plot a second-order curve by its non-canonical equation? | I have this second-order polynom: $$ 6xy+8y^2-12x-26y+11=0 $$ And I need to reduce it to a canonical form of a second-order curve. I solved this, but is it possible to draw a plot of the original equation to check whether my solution is correct? Something like Plot[6 x*y + 8 y^2 - 12 x - 26 y + 11, {x, -20, 20}, PlotRange -> {-20, 20}] Now this draws an empty plot. Thank you. |
56129 | Minimum and maximum values under conditions | Let's create some sample data n = 10; data = Table[{RandomReal[], RandomReal[], RandomReal[], RandomReal[], RandomInteger[{-1, 2}], RandomInteger[{0, 15000}]}, {i, 1, n}] Now, I want to find the minimum and the maximum value of the last column (#6) only when the fifth one has an integer value 1 or 2, thus excluding the -1 and 0. Any suggestions? |
56128 | Need help in understanding code | I am just beginning with _Mathematica_. I have received this code to study. I am not able to follow this particular section. I have tried looking it up on many forums, with no answer. Can you help? Clear[CSfunc]; CSfunc::usage="CSfunc[n_] returns {Cn,Sn} up to degree n >= 0"; CSfunc[n_] := Module[{cn,sn}, sn = Table[Sin[k*x*Pi/2], {k, n}]; (* anti-symmetric in x *) cn = Table[Cos[k*x*Pi/2], {k, n}]; (* symmetric in x *) cn = Join[{1/Sqrt[2]}, cn]; {cn, sn}]; << JavaGraphics`; doplot = False; doplot = True; If[True, (* check classic orthogonality: 2 on [-2,2], not yet on [-1,1] ... *) ntest = 6; xmax = 2; csn = CSfunc[ntest]; If[False && ntest < 5 && doplot, Plot[Flatten[csn], {x, -1, 1}, Axes->True, Frame->True]]; In the above portion of the program, I see `If[True etc.. If[False etc..]`, but no flag variable associated with it. So what condition is it checking? |
57293 | Generate a dynamic interface with sliders out of a list of rules | I would like to generate a function which takes a list of rules as input and generates sliders which are altering the values of the list. Then I would like to use this function in an dynamic module as input. This can be used as a dynamic way to generate a user interface for a model which is constantly evolving and I don't won't to hardcode the GUI and change it every time. So here is a minimal example: input: ruleslist = {"valu1" -> 1, "value2" -> 2}; rangelist = {"valu1" -> {0, 2}, "value" -> {0, 5}}; ruleslist2 = {"valu3" -> 10, "value4" -> 20}; rangelist2 = {"valu4" -> {0, 20}, "value4" -> {0, 50}}; the function rulestoinput[ruleslist_, ranges_, output_] := DynamicModule[{values, numInputFields, sliderlistn, names, origvalues, rangeslist}, origvalues = ruleslist[[All, 2]]; numInputFields = Length@ruleslist; names = ruleslist[[All, 1]]; rangeslist = ranges[[All, 2]]; Do[values[i] = ruleslist[[i, 2]], {i, numInputFields}]; Panel@Column@ Flatten@{Column@{names[[#]], Dynamic[values[#]], Slider[Dynamic[values[#]], rangeslist[[#]]]} & /@ Range[numInputFields], Button["save settings", output = Flatten@Table[{names[[i]] -> values[i]}, {i, numInputFields}]]} ] the dynamic module which uses the "rulestoinput" function and uses their results to Run something. DynamicModule[{output1, output2, result}, Panel@Column@{rulestoinput[ruleslist, rangelist, output1], Dynamic@output1, rulestoinput[ruleslist2, rangelist2, output2], Dynamic@output2, Button["Run", result = Flatten@{output1, output2}], Dynamic@result } ] The interface looks like this ![how it looks](http://i.stack.imgur.com/V9hqB.png) It works like this, but I don't want to press the "save settings" before "Run". It would be good if just by clicking the Run button that the output1 and output2 would be updated from the sliders. I guess I am doing something wrong with the dynamic module. I searched for how to pass results from one Dynamic module to another, without success. Of a slightly different approach. Here the results are not yet passed from the rulestoinput2 function to the "Run" button. rulestoinput2[ruleslist_, rangelist_] := DynamicModule[{x = Table[ruleslist[[i, 2]], {i, Length@ruleslist}]}, Column[{Row[ Table[With[{i = i}, Slider[Dynamic[x[[i]]], rangelist[[i, 2]]]], {i, 1, Length@ruleslist}]], Dynamic@Thread[ruleslist[[All, 1]] -> x]}]] DynamicModule[{result}, Panel@Column@{ rulestoinput2[ruleslist, rangelist], rulestoinput2[ruleslist2, rangelist2], Button["Run", result = Flatten@{"new ruleslist 1", "new ruleslist 2"}], Dynamic@result } ] |
57294 | Breaking out of a NestList | I'm trying to use NestList to calculate a continued function. It works great, except when there is an overflow or an indeterminate value, which might happen for some initial values. How can I use an equivalent of Break[] to exit a NestList before it finishes? I'd like the working equivalent of (say) this: NestList[Check[f[# z],Break[]]&, z, 1000] which does not work because NestList is not treated like a For, a While or a Do. If I use another expression instead of Break[] (say the string "err"), the computation of NestList continues and produces a complete list of `... f[z f[z f[z err]]]` which has to be handled afterwards. EDIT: I found a simple solution, many thanks to paw! NestWhileList[f[# z]&, z, NumericQ, 1, 1000] |
57295 | Edit built in symbol | I would like to add new attributes to built in symbols (e.g. `ElementData` or `PolyhedraData`) so that I can still call the symbol in the same way (e.g. `ElementData["name","property"]`) but now with a new, user-added property. Is that possible? |
25288 | How can I substitute something using only map? | For example, I have the equation x^2 + y^2 == x*y and I want to apply the rule y -> s*x I can do it easily by x^2 + y^2 == x*y //. y -> s*x But it seems to me it would be possible to use only `Map` to change everything. How can I do it that way? In other words, I think `Replace` is just a kind of syntactic sugar, and want to know how to express `Replace` by `Map`. |
25289 | Problem with simplifying Sinc function | $Assumptions = x ∈ Reals && y ∈ Reals && a ∈ Reals && b ∈ Reals; These work: Cos[x/2] Sinc[x/2] == Sinc[x] // FullSimplify (* True *) Cos[y/2] Sinc[y/2] == Sinc[y] // FullSimplify (* True *) but these don't: Cos[x/2] Sinc[x/2] + Cos[y/2] Sinc[y/2] == Sinc[x] + Sinc[y] // FullSimplify (* Cos[x/2] Sinc[x/2] + Cos[y/2] Sinc[y/2] == Sinc[x] + Sinc[y] *) Cos[a + b] Sinc[a + b] == Sinc[2 (a + b)] // FullSimplify (* Cos[a + b] Sinc[a + b] == Sinc[2 (a + b)] *) Why this strange behavior? |
57299 | Dynamically transform one Graphics to another | I would like to have two `Graphics` objects displayed side by side such that: * they are mirror images of each other * if I change the left-hand one interactively using _Drawing Tools_ , the other one is updated automatically. I can't seem to convince `Dynamic`, `Manipulate` and friends to do this for me. How can I do it? A more basic question would be: how do I create a variable which holds a `Graphics` object and such that its value can be changed interactively using _Drawing Tools_? |
3044 | Partition a set into subsets of size $k$ | Given a set $\\{a_1,a_2,\dots,a_{lk}\\}$ and a positive integer $l$, how can I find all the partitions which includes subsets of size $l$ in Mathematica? For instance, given `{1,2,3,4}` and `l=2`, the output should be: $$\text{Partition 1: }\\{1,2\\},\\{3,4\\}$$ $$\text{Partition 2: }\\{1,3\\},\\{2,4\\}$$ $$\text{Partition 3: }\\{1,4\\},\\{2,3\\}$$ In Mathematica notation: { {{1,2},{3,4}}, {{1,3},{2,4}}, {{1,4},{2,3}} } Edit: Another example for `l=3`, and `{1,2,3,4,5,6}`: { {{1, 2, 3}, {4, 5, 6}}, {{1, 2, 4}, {3, 5, 6}}, {{1, 2, 5}, {3, 4, 6}}, {{1, 2, 6}, {3, 4, 5}}, {{1, 3, 4}, {2, 5, 6}}, {{1, 3, 5}, {2, 4, 6}}, {{1, 3, 6}, {2, 4, 5}}, {{1, 4, 5}, {2, 3, 6}}, {{1, 4, 6}, {2, 3, 5}}, {{1, 5, 6}, {2, 3, 4}} } |
27050 | How can I revise my program to avoid "No more memory available"? | I have a program for calculating a type of list. ff[num_Integer] := Union[ Select[Subsets[Tuples[Range[2 num], {2}], {num}], Sort @ Flatten @ # == Sort @ Range[2 num] &], SameTest -> (Sort[Sort /@ #1] == Sort[Sort /@ #2] &)]; Now, the problem is that `ff[num_]` doesn't work on my computer when `num >= 5`. I would really like to get `ff[8]`, even `ff[10]`. How can I change this program to use a better method for producing these types of list? |
26978 | 3D plot changes it's size while rotating | When I am rotating drawn 3D plot by mouse it rotates Ok until mouse release. After that it slightly changes it's size instantly. Probably it tries to accommodate document layout or something. Is it possible to disable this feature? May plot remain exactly I left it after rotation? |
19973 | Download Mathematica 8 Trial | My school uses mathematica 8 on several of their computers. I would like to download a trail version for my home computer. I would like the same version. Is there a place I can download mathematica 8? |
15637 | Plotting an Argand Diagram | I have the function: $F(\omega) = \frac{5\; - \;i\;\omega}{5^2\; +\; \omega^2}$ When $\omega$ has the values : $\\{ -7, -2,\; 0,\; 2,\; 7\\}$ How would I plot the Argand diagram in Mathematica? Or should I just treat it as a normal plot? The graph should look like a circle with radius $\frac{1}{10}$ passing through the points specified. |
43363 | How to plot data of complex numers | Here I have some output calculated for different values of some parameter. I want to plot these points in complex plane Re, Im and present them with ListLinePLot. How can I do that, I tried many times but nothing. out={{{K0 -> 240.09573909159692881611894479598255552782741102371 - 7.27635432239591082054495645853781783511810812523 I}}, {{K0 -> 250.77439852422565327207328256124461190469681314589 - 31.26451978875377785592466121797901152332973976660 I}}, {{K0 -> 253.48532269665683199525493735826312930548236644336 - 61.24310141078654112760472487520741696623955208560 I}}, {{K0 -> 249.18937492291801812641504201171420536673203251135 - 92.38827531035059634782269285091956945472964743190 I}}, {{K0 -> 239.10541928516975728266518199423978996138742725557 - 122.79360060036155629292367320357542795679835792710 I}}, {{K0 -> 224.13192736090708008710607149524981720297486848225 - 151.51085317916968975506128715270875157179902970334 I}}, {{K0 -> 204.92235646608943262261629178639026362615765825785 - 177.96564990038879131356133303872228920923576227697 I}}, {{K0 -> 181.96606373954652948373275976518520695312671935521 - 201.74316490057697153557914766713663939352731214231 I}}, {{K0 -> 155.64091078592068971330671363671101734468083989542 - 222.49208124514099845175336661804180693875258747941 I}}, {{K0 -> 126.24620602094244454267170422247369897873670911676 - 239.87157975283261958986520821933642550993546879398 I}}, {{K0 -> \ -4743.5781179728666287431504651689229585059692376219 - 43.6738915748400328628460613215871721452209766204 I}}}; |
30870 | Plotting region $f(S)$ for given complex function $f$ and $S \subseteq \mathbb{C}$ | I have a function $f: \mathbb{C} \rightarrow \mathbb{C}$ and I want to be able to see the effect of $f$ on any particular region of $\mathbb{C}$ e.g. what happens to the unit disk under this transformation. I know how to plot particular _regions_ in the complex plane using RegionPlot e.g. RegionPlot[ Evaluate@ComplexExpand[ Abs[z]<1 /. z -> x + I y], {x, -2, 2}, {y, -2, 2}, AxesLabel -> Automatic]; shades the interior of the unit disk in light purple color. Is it possible to modify this code snippet to see the effect of $f(z)$ on the above unit disk for any given $f$? |