# Tag Info

0

As described by István this is an issue of evaluation order. There are several methods, Evaluate and With already illustrated. I often use a Function for this purpose as it is concise: paramToVary = a; paramValues = Range[0, 1, 1/5]; Table[{a, b}, {#, paramValues}] & @ paramToVary {{0, b}, {1/5, b}, {2/5, b}, {3/5, b}, {4/5, b}, {1, b}} There ...

3

Using With might do the trick too: ClearAll[a]; With[{paramToVary = a, paramValues = Range[0, 1, .2]}, Table[a, {paramToVary, paramValues}] ] {0., 0.2, 0.4, 0.6, 0.8, 1.}

4

Since Do (and Table) has attribute HoldAll, paramToVary won't be evaluated at the right time. Use Evaluate on the iterator specification to force the replacement of paramToVary -> a. ClearAll[a]; paramToVary = a; paramValues = Range[0, 1, .2]; Table[a, Evaluate@{paramToVary, paramValues}] {0., 0.2, 0.4, 0.6, 0.8, 1.}

4

Abort[] inside a scheduled task will abort the rest of the task expression at the given time, not any main evaluation. It will also repeate to evaluate the task (up till the Abort[]) if further time slots are scheduled. To show this, first start a scheduled task: RunScheduledTask[ Print[DateString[], " Scheduled task before Abort[]"]; Abort[]; ...

0

Try this and let me know if there are cases it misses: exprs = {f[_], f, _, Blank, f[0], f[_], g[f[0]]}; taken = {}; Do[ If[! MemberQ[taken, Verbatim[i]], Print[i]]; taken = Union[{Head[i]}, Level[i, {0, Infinity}], taken]; , {i, exprs}] (* Out: f[_] f[0] g[f[0]] *)

2

I have no idea what cached demon caused this behaviour, but restarting Mathematica in clean mode reset everything to defaults and now the two cells behave as for everyone else. The documentation states: mathematica.exe -clean: ignore stored caches and rebuild the front end preferences file (It also seems like from the documentation that this is a ...

4

Maybe TimeConstraint is helpful: y = Gamma[1 - x] Gamma[x] Sin[Pi x] + Gamma[x] Gamma[1 - x] Sin[Pi (1 - x)]; FullSimplify[y, TimeConstraint -> 0.000001] FullSimplify[y, TimeConstraint -> 0.0001] FullSimplify[y, TimeConstraint -> 0.01] Gamma[1 - x] Gamma[x] Sin[π (1 - x)] + Gamma[1 - x] Gamma[x] Sin[π x] 2 Gamma[1 - x] Gamma[x] Sin[π x] 2 π

4

The only method I can think of that will use the built-in simplification routines is to snoop on transformations using either TransformationFunctions or ComplexityFunction. Unfortunately neither of these will be restricted to the entire expression therefore what is produced may not be usable. Nevertheless as an example: FullSimplify[Gamma[1 - x] Gamma[x] ...

1

Use a numerical derivative: Clear[band, en, w, fermi, k, T, S, a] << NumericalCalculus k = 86*10^-6; T = 4000; band[en_, w_] := 10000 Exp[-en^2/2 w^2]; fermi[en_, ef_] := 1/(Exp[(en - ef)/(k T)] + 1); S[ef_?NumericQ] := -k NIntegrate[(band[en, w] fermi[en, ef] Log[fermi[en, ef]]) /. w -> 1, {en, -Infinity, Infinity}] ...

7

Updated This happens because your DynamicModule returns a dynamic object of which x is passed on to the front-end before the scheduled task starts, so the front-end-x cannot be modified anymore by any process (more details at the end). The problem can be further simplified. This works: RemoveScheduledTask@ScheduledTasks[]; DynamicModule[{x = 0}, ...

8

You can specify the evaluation of which construct should be stopped by Return by providing the second argument (undocumented?). For example, Scan[Function[x, Module[{}, Print[x]; Return[$Failed, Module]; Print[-x]]], {1, 2, 3}] or Scan[Function[x, Print[x]; Return[$Failed, CompoundExpression]; Print[-x]], {1, 2, 3}]

7

It's hard to reply without larger context, but if you are not restricted to use pure functions, then one option would be to use the pattern-defined overloaded function instead: ClearAll[fun]; fun[2] := Null; fun[x_] := ((*Do something useful*)Print[x]) Then, you just write: Scan[Function[x, Scan[fun, x]], {{1, 2, 3}, {4, 5, 6}}] In fact, you can as ...

2

I would use Catch and Throw if pressed to choose, without the 'exit' : Scan[Function[x, Scan[Function[y, Catch[If[y == 2, Throw[Null]]; (*Do something useful*) Print[y]] ], x]], {{1, 2, 3}, {4, 5, 6}}] or simply, Scan[Function[x, Scan[Function[y, If[y == 2, Null, (*Do something useful*) Print[y]] ], x]], {{1, 2, 3}, ...

1

You can't get an exact solution with Mathematica, but you may approximate it, for example with polynomials: s = NDSolve[{y'''[x] + y[x]^2 y''[x] - y'[x] == 0, y[0] == 0, y'[0] == 0, y''[1]== 1}, y, {x, 0, 1}]; data = Table[{x, y[x] /. s[[1]]}, {x, 0, 1, .01}]; Manipulate[ Column[{#, Show[ListPlot@data, Plot[#, {x, 0, 1}, PlotStyle -> {Thick, Red}], ...

3

Borrowing from an example of WhenEvent from the documentation in which a Button is used to stop the integration, I came up with this. ClearAll[ndsolveMemConstrained]; SetAttributes[ndsolveMemConstrained, HoldFirst]; ndsolveMemConstrained::mlim = "Memory used  exceeded limit ."; ndsolveMemConstrained[(nd_: NDSolve | NDSolveValue)[eqns_, rest___], bytes_] ...

0

Here is a method I found for a different problen which could probably be adapted to your problem. {fit, steps} = Reap[TimeConstrained[ FindFit[ztp, {convolutionModel, k > 1 && r0 > 0 && r1 > 0}, convolutionParameters, t, Method -> Automatic, StepMonitor :> Sow[{r0, r1, k}]], 10]]; You should be able to change ...

7

Thanks to Michael E2's comment, the following approach is successful. The method sets up a scheduled task that (at certain resolution res) monitors the elapsed $time and compares it to the dynamic$max. If $time is more than allowed by$max, it calls the front-end "EvaluatorAbort". Attributes[dynamicTimeConstrained] = {HoldAll}; ...

6

As Leonid has explained the problem is that the symbols are created and get their context at parse time, so if you need to avoid generating them in the current (usually "Global") context, using $PreRead as he explained is the only possibility. If you don't care that the symbols you use are created in the current context AND the context you want to evaluate ... 3 Since it was mr. Leonid Shifrin who provided a proper solution, I feel less guilty of my brute-force, very limited try: it adds the context to the first symbol in every Set and SetDelayed. a =.; b =.; c =. context2a =.; context2b =.; context2c =. InContextSetAndSetDelayed := Function[{context, code}, code /. SetDelayed -> f /. ... 9 This is possible in the interactive session with$PreRead. I will adopt my solution to the same problem posted in this Mathgroup thread. To quote my explanation from there, the essence of the present solution is to delay the parsing of the code (body) that must be executed inside a given context until run-time, that is, replace code ...

6

ClearAll clears all definitions associated with the symbol. However, the symbol remains in the symbol table, so all references to that symbol from other symbols (their definitions) remain fully valid. The symbol can then acquire new rules or other global properties associated with it. Remove removes the symbol from the symbol table. More precisely, it ...

5

Besides destroying the symbol itself, the main side effect of Remove that is not shared by ClearAll is what happens to expressions containing a removed symbol. a = {x, y}; ClearAll[x, y];a {x, y} Remove[y]; a {x, Removed[y]}

2

The problem is how to evaluate the sums without before a is set to 0. That can be done with With. If you put Dynamic around Plot, then only the Plot will be updated when the slider for a is moved. Manipulate[ With[{plots = Table[Sum[((a0 t)^k)/k! Exp[-a0 t], {k, 0, Infinity, n}], {n, 1, 5}]}, Dynamic @ Plot[Evaluate[plots /. a0 -> a], {t, 0, 5}, ...

3

With a few bells and whistles: Manipulate[ Module[{plts}, plts[a_, t_] = Table[Tooltip[ Sum[((a t)^k)/k! Exp[-a t],{k, 0, Infinity, n}] // Simplify, StringForm["n = `", n]], {n, 5}]; Plot[Evaluate[plts[a, t]], {t, 0, 5},PlotRange -> {0, 1}]], {{a, 1.5}, 0, 3, 0.05, Appearance -> "Labeled"}] Bob Hanlon

3

It can work with a=0 too, the problem is that a is applied before closed form of the sum is calculated. We can force this: DynamicModule[{t, k, tab, a}, Column[{ Dynamic@Plot[tab[a, t], {t, 0, 5}, ImageSize -> 400], Slider[Dynamic[a], {0, 11, 1}] }], Initialization :> {tab[a_, t_] = Table[Sum[((a t)^k)/k! Exp[-a t], {k, 0, Infinity, n}], ...

0

In linux Mathematica 9.0 I confirm that this problem is caused by Internet access. Go to Home>Ctrl+H :Shows hidden files Browse to ./.Mathematica/Paclets/Confiruration Open "managerData_9.0.0.0.pmd2" Change "AllowInternet" -> False" Hope that helps.

1

For this specific case (units in Quantity) a solution is relatively simple: if you use the "standard" unit name Mathematica won't need to use the internet to try to interpret ist. Here that means using "Meters" should avoid the slow evaluation in the first place (I think that is documented and was already discussed once on this site)> m = ...

3

Your equations don't seem to be consistent. y = E^-9.25 0.0000961117 c = 10.^-14 - y -0.0000961117 x = c y/5.7 10.^10 -16.2061 z = 276/x^2 1.05088 a = (x + c)/2 - z -9.15396 b = x + y - 2 z - a -9.15377 However, a b /z 79.7359 while your remaining equation states 9.8x10^-13 = [(b)(a)]/(z)

2

Here are the equations converted to Mathematica code, and 2 ways to solve them. However, since you have more equations than unknowns, I removed one equation. May be someone else can find how to solve them as is using optimiziation or other techniques. (since they are non-linear). Here it is eq1 = x + y == 2 z + a + b; eq2 = x + c == 2 (z + a); eq3 = 276 == ...

1

The reason that it works for Integrate and not for NIntegrate is that NIntegrate has the attribute HoldAll and Integrate does not. Attributes, if any, are listed at the end of the "Details and Options" section of the documentation page for a function. They may also be inspected with the Attributes command: Attributes@Integrate (* {Protected,ReadProtected} ...

Top 50 recent answers are included