Hot answers tagged

5

Use the option Method -> "Queued": Button[Dynamic[x], x = 0; Table[Pause[0.1]; x++, {i, 1, 10}], Method -> "Queued"] Button >> Details and options


4

The approach suggested by yarchik can be accelerated by two orders of magnitude by performing the computations with machine precision numbers instead of exact numbers and then rounding, and by using ParallelDo: SetSharedVariable[s] s = {}; ParallelDo[If[IntegerQ[(1 + a*Round[Sqrt[1./(a*a) + 12. (a + 1)], 10^-10])/6], AppendTo[s, a]], {a, 1, 10^9}] // ...


3

For is generally avoided as inefficient. Using a pure Function with Map data = T1 /. Solve[# == -4.84*10^(-4) - 17.82*10^(-4)*T1 + 1.53*10^(-4)*T1*2.303*Log[T1], T1][[1]] & /@ Range[0, 5] // Quiet (* {158.54, 1329.7, 2164.72, 2915.71, 3619.49, 4291.32} *) Plotting the results ListLinePlot[data, DataRange -> {0, 5}, AxesLabel -> {...


3

You can replace Table with Do Do[If[IntegerQ[1/6 (1 + Sqrt[1 + 12 a^2 + 12 a^3])], Print[a]], {a, 1 + 10^(11), 10^4 + 10^(11)}] but it is still slow. Try to bring your diophantine equation to some known type.


2

Clear[a, pp, aa, n, P, Payoff] a = 15; P[n_] := (1/2)^n Payoff[n_] := 10 Exp[-n] pp = Table[{n, N[P[n]*Payoff[n]]}, {n, 1, a}]; aa = N[Accumulate[Table[P[n]*Payoff[n], {n, 1, a}]]]; TableForm[Flatten /@ Transpose[{pp, aa}], TableHeadings -> {None, {"n", "pp", "aa"}}]


2

Perhaps this is what you are looking for. It is the best I can do when trying to guess what you really want to compute. My goal here is show you how your For-loop can be fixed, rather than to instruct you in the better methods available to solve your problem. For[mu = 0, mu < 6, mu++, sol = Quiet @ NSolve[ mu == -4.84*10^(-4) - 17.82*10^(...


2

If you're before v10.3, then only the first syntax is correct. For more information check: Why does Table behave differently in Mathematica compared to WolframCloud? BTW this syntax change causes problem in certain cases: Unexpected behaviour from Table[]


1

For some values of a and b there is no solutions in the range 0<x<1, so solh[a_, b_] shows {x, x}, hence further errors. You can change this to: solh[a_, b_] := With[{sol = NSolve[{h[x, a, b] == 0, 0 < x < 1}, x][[;; , 1, 2]]}, If[sol != {}, MinMax[sol], {0.00011, 0.99989}]]; Now in case of no solutions due to restrictions on x the ...


1

Using NSolve for numerical solutions, filtering for Reals. Clear[roots] Do[roots[a] = NSolve[z^3 + 3 z^2 - z == a, z, Reals], {a, -15, 15, 0.1}] ListPlot[Table[Map[{a, #} &, z /. roots[a]], {a, -15, 15, 0.1}]] Evaluate InputForm[DownValues[roots]] to see the results. Note the floating point numbers, e.g. roots[2.400000000000002], which explains why ...


1

Can be done in a shorter way, no need for the Table Clear[roots] Do[roots[a] = z /. Solve[z^3 + 3 z^2 - z == a, z], {a, -15, 15, 0.1}] roots[-1.]


1

To take some comments and put them into an answer, the reason this happens is auto-compilation. It's been extensively discussed on the site, but basically Mathematica will try to compile any call into Table that's large enough and with a simple enough function directly down to C before evaluating. This means it's impervious to inspection by things like ...


Only top voted, non community-wiki answers of a minimum length are eligible