Tag Info

Hot answers tagged

13

Since EllipticTheta[] is a built-in function, and since the Eisenstein series $E_4(q)$ and $E_6(q)$ are expressible in terms of theta functions (I use the nome $q$ as the argument in this answer, but you can convert to your convention by using the relation with the period ratio $\tau$: $q=\exp(2\pi i \tau)$), and since the higher-order Eisenstein series ...


8

I think there's a bug in the internal function NDSolve`SPRKDump`CheckSeparability that leads NDSolve to conclude that the system is not separable. I think you should report it and see if WRI can verify it (they would probably appreciate a link to this Q&A). It's a fair amount of work to track it down, and there is a lot of nearly unreadable stuff to ...


7

Have you tried using NSum? In your question, it seems to me that you try to sum numeric values (instead of analytically evaluating a sum) and I think NSum is better for this. Simple example: f1[x_] := x; f2[x_] := Exp[x]; NSum[f1[x]/f2[x], {x, 1, Infinity}] (* 0.920674 *)


5

Erfc[-30. + 10^-1 I] used to return the result shown in the documentation through version 7.0.1. The implementation changed for version 8.0 and it started giving a machine precision answer (which is correct, more consistent and still demonstrates the same possible issue by being very close to 2). The (documentation) bug is that this example did not get ...


5

I think your problem is with the specification of the base case. You're basically trying to do the following, I think: f[n_] := f[n-1] + 1 f[5] /. f[0] -> 0 Of course, this fails because f[5] tries to evaluate completely before ReplaceAll even sees it. The solution is to specify a base case in the definition of the function: f[n_] := f[n-1] + 1 f[0] ...


5

Increase WorkingPrecision: NSolve[PDF[BinomialDistribution[80, p], 0] == 0.95`200 && 0 < p < 1, p, Reals, WorkingPrecision -> 50] PDF[BinomialDistribution[80, p], 0] /. % (* {{p -> 0.00064096067673218860969986162632491931947341012861}} {0.9500000000000000000000000000000000000000000000000} *)


4

As mentioned in the comments and as the error message says, FindMaximum only accepts integer domain constraints for linear optimization problems, while of course nx * wx is a non-linear term. For ILP problems, FindMaximum uses a specialized solver from the COIN-OR branch-and-cut (CBC) library. NMaximize is using a different approach.


4

As Daniel Lichtblau showed in his comment, use exact numbers (or Rationalize) for input values alpha = 639/100; beta = 369/100; a1 = (1 - alpha)/2; a2 = (2 - alpha)/2; a3 = (1 - beta)/2; a4 = (2 - beta)/2; a5 = 1; b1 = 0; b2 = 1/2; SNR = 0; SNR0 = 10^(SNR/10); z = 2*(SNR0/(alpha*beta))^2; p1 = 2^(alpha + beta - 3)/(Pi*Sqrt[Pi]*Gamma[alpha]*Gamma[beta]); ...


4

I believe this has to do with the fact that intervals "grow" just a bit on evaluation with machine numbers to ensure that values at the endpoint will be included in the interval. NestList[Interval @@ # &, Interval[{0., 1.}], 5] // InputForm (* {Interval[{-2.2250738585072014*^-308, 1.0000000000000002}], Interval[{-4.450147717014403*^-308, ...


4

Very recently, I learned a useful procedure due to J. P. Boyd (see also this and this) that involves expanding a function as a Chebyshev polynomial series, forming the so-called "colleague matrix", and then finding the eigenvalues of this matrix, which are often good approximations to the roots of the original function. I shall present how to do a barebones ...


4

Already answered in the comments by DumpsterDoofus and Daniel Lichtblau, to summarize: Machine floating point numbers such as 0.2 are not always exactly representable in binary (no terminating expansion in base 2). Thus floating point arithmetic is susceptible to roundoff error and other accuracy problems. For example, the following are not exactly equal to ...


4

You can find when $f_{2}(x) = 10^{-15}$, and then calculate the summation: f1[x_] := Exp[-x]; f2[x_] := 1/x; mybound = 10^-15; maxx = (x /. Solve[f2[x] == mybound, x])[[1]]; mysum = Sum[f1[x]/f2[x], {x, 0, maxx}] N[mysum, 10] (* 0.9206735942 *)


4

Using the formula given in the arXiv preprint Patrick linked to for the "carefree constant" gives: Exp[NSum[(-1)^k PrimeZetaP[k] (1 - LucasL[k])/k, {k, 2, ∞}, Compiled -> False, Method -> "AlternatingSigns", NSumTerms -> 20, WorkingPrecision -> 30]] 0.704442200999165592738713909247 Note that this agrees with the result in the OEIS ...


3

The answer to the second part of your question is that you need to abandon machine precision arithmetic. Perhaps the best way to proceed is use Mathematica's exact arithmetic. a = Rationalize @ {15., 15.01, 3., 3.01} Round[Abs[a - Mean[a]], 1/100] {6, 6, 6, 6} You could also use Mathematica's slower but more accurate arbitrary precision arithmetic. ...


3

FullForm seems to be working fine here. Here is what belisarius alluded to in his comment, using your definitions and either InputForm, or FullForm as he suggested: InputForm@Abs[a - Mean[a]] FullForm@Abs[a - Mean[a]] (* Out from InputForm: {5.995000000000001, 6.005000000000001, 6.004999999999999, 5.994999999999999} Out from FullForm: ...


3

As it turns out, one can exploit the behavior of Interval[] when applied to a machine-precision number to obtain the previous and next representable machine-precision numbers (thanks to Szabolcs for the fix): SetAttributes[nextafter, Listable]; nextafter[x_?MachineNumberQ, s_?NumericQ] /; s != 0 := First[Interval[x]][[ -Sign[s - x] ]] To obtain a ...


3

the NestWhile approach f1[x_] := Exp[-x]; f2[x_] := 1/x NestWhile[ {#[[1]] + f1[#[[2]]]/f2[#[[2]]] , #[[2]] + 1} & , {0, 1} , f2[#[[2]]] > 1/1000 & ] // First // N 0.920674 ( NSum is most certainly the better approach unless you have some peculiar functions )


3

Following Szabolcs advice, it seems that the Documentation page for EvaluationMonitor contains all what you need for Method -> "Newton": data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {6, 4}, {7, 5}}; Clear[evalCount]; evalCount[_] = 0; nlm = NonlinearModelFit[data, Log[a + b x^2], {a, b}, x, EvaluationMonitor :> ++evalCount["Function"], Gradient ...


2

The use of NumericQ as mentioned by MarcoB and Guess who it is. in the comments seems to be important. Also, estimating the integral using a Total[Table[]] as in the code I posted in the second revision of the question makes this method computational feasible enough to solve my problem.


2

i = 2; j = 2; FixedPoint[Plus[#, f1[i++]/f2[j++]] &, f1[1.]/f2[1]]


2

The error message is very descriptive: you haven't specified a boundary condition, but a condition on the middle of the region. If you amend the {x, 0, 2} to {x, 0, 1} it works correctly (but points out that your conditions are inconsistent, which they are). You should be able to impose conditions on the inside of the region by splitting the region in two, ...


2

So following @Szabolcs advice, {nl,ncounts}=Block[{c = 0}, {NonlinearModelFit[data, Log[a + b x^2], {a, b}, x, Method -> "Newton", EvaluationMonitor :> c++], c}] or (doing something slightly different) counting the number of Log Calls. Trace[nlm = NonlinearModelFit[data, Log[a + b x^2], {a, b}, x, Method-> ...


2

It's not independent. The following is the same as your code, just edited for taking fg as a parameter Clear[w, z, x, y, t, a, b, c, d, ope2h, fg] a = 0.5; b = 0.001; c = 0.7; d = 0.5; ope2h = ParametricNDSolve[{ w'[t] == 1/4 + x[t]/a - w[t]*(1/a + 1/b) + y[t] fg, x'[t] == 1/2 + w[t]/a - x[t]*(1/a + 1) + z[t] fg, y'[t] == w[t]/b - y[t]/c - y[t] ...


1

[Personally, I would be satisfied with SetAccuracy, at least in the use-cases in which I imagine I would need it. It just seems easier to me to learn how to work with the system instead of around it. Nonetheless, it seems to be possible....] Here's an idea of what I was talking about with $PreRead in a comment. On a syntax error, it might fail ...



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