# Tag Info

0

Replace your Return line (the final line in your code by fkz[z_?NumericQ] := NIntegrate[mInt, {k, 0, z}, WorkingPrecision -> wp]; fk[z_?NumericQ] := NIntegrate[mInt, {kz, 0, z}, WorkingPrecision -> wp]; Quiet[-NIntegrate[fkz[kz], {kz, 0, \[Infinity]}, WorkingPrecision -> wp] - NIntegrate[fk[k], {k, 0, \[Infinity]}, WorkingPrecision -> wp]]] ...

3

Consider also 'Sort' and 'First' > (your expression here...) // Sort // First Max also suffers poor performance on DateObjects that can remedied in similar form: > (your expression here...) //Sort // Last To comment on the OP situation: at this time (MMA 10.0.2) short lists also suffer unacceptable delays. For example, applying Min or Max to a ...

3

The problem you face here is that your function has several minima in the range you specified: If you want them all, you can use Reduce, but for this, you need the approach you learned in school: calculate the derivative of your function and calculate where it is zero. Then use the second derivative and check whether it is >0 to indicate that you want a ...

4

$Version "10.0 for Mac OS X x86 (64-bit) (December 4, 2014)" f[x_] = Sin[x]^6 + Cos[x]^6; sol = FullSimplify[Minimize[ {f[x], 0 <= x <= 2 Pi}, x]] {1/4, {x -> (7*Pi)/4}} However, this is just one of the four minima. To find all four: pts = {x, f[x]} /. Solve[ {f'[x] == 0, f''[x] > 0, 0 <= x <= 2 Pi}, x] // FullSimplify ... 1 Minimize returns a symbolic result as it is designed to do. It is working correctly. To force the return of a numeric result you must "encourage" Minimize to do so. This makes it call NMinimize instead. A simply way is to multiply any portion by 1. to make it floating point. The decimal point is important. Minimize[{1.Sin[x]^6 + Cos[x]^6, 0 <= x <= 2 ... 0 This function works exactly like MATLAB's linspace as it gives you n points (rather than n+1): linspace[x0_, x1_, n_] := Range[x0, x1, (x1 - x0)/(n - 1)]; 2 Perhaps something like this: allNumeric[vars_] := VectorQ[{vars}, NumericQ] (* define once, use many times *) f[x_, y_, z_, t_] /; allNumeric[x,y,z,t] := ... 7 You need the magic of "Pseudospectral": n = 35; g = 9.81; a = 1350; L = 3500; T = 30; h0 = 4; v0 = Sqrt[2 g h0]; R = 0.003; sol = NDSolve[ {D[h[x, t], x] - R v[x, t] Abs[v[x, t]] == D[v[x, t], t]/g, D[v[x, t], x] == g D[h[x, t], t]/a^2, v[x, 0] == v0, v[0, t] == v0 Exp[-(t^2/0.4)], h[L, t] == h0, h[x, 0] ... 3 Fixed in 10.0.2 v1 = Table[i, {i, 1, 100000}]; v2 = Table[i, {i, 1, 100001}]; s1 = BitShiftRight[v1]; s2 = BitShiftRight[v2]; s1[[1 ;; 10]] s2[[1 ;; 10]] v = Range[100001]; a = BitShiftRight[v[[;; 10]]]; b = BitShiftRight[v][[;; 10]]; a == b 5 With the option MaxStepSize -> 1., it seems to work. (A little bit magic) sol = NDSolve[{ D[h[x, t], x] - R*v[x, t]*Abs[v[x, t]] == 1/g D[v[x, t], t], D[v[x, t], x] == g/a^2*D[h[x, t], t], v[x, 0] == v0, v[0, t] == v0 Exp[-t^2/0.4], h[L, t] == h0, h[x, 0] == h0}, {h, v}, ... 0 You can also change the number of digits in the solution by setting smaller the criterion for convergence through SameTest, as in: FixedPointList[(# + 3/# )/2 &, 1`20, SameTest -> (Abs[#1 - #2] < 1*^-10 &)] {1.0000000000000000000, 2.0000000000000000000, 1.7500000000000000000, \ 1.7321428571428571429, 1.7320508100147275405, ... 5 The problem is not FixedPointList - the problem is that Mathematica by default doesn't display that many digits. Consider for example FixedPoint[newton3, 1.0] // InputForm which displays several more decimals. Another option is to increase PrintPrecision: SetOptions[InputNotebook[], PrintPrecision -> 10] This increases the number of decimals shown ... 0 Calculation of R involves general recursion that is not optimized in Mathematica. Try to use memoisation to avoid stack bloat when calculate R functions. R is defined recursively and recursive calls are not even in the tail position. Another advice - look at using Compile for your numeric functions. 0 Although @DaveStrider has answered the question above fully, I think it worth noting that these equations can be solved analytically. For instance, a = Exp[-x^2]; uo = Exp[-2 x^2]; d = u[t] /. DSolve[{u'[t] == 1 - a u[t], u[0] == uo}, u, t][[1]] with solution E^(-(t/E^x^2) - 2*x^2)*(1 - E^(3*x^2) + E^(t/E^x^2 + 3*x^2)) Interestingly, N[d /. {x -> ... 1 The problem is, that NDSolve always returns a list of solutions, in this case a list of length 1. You can see it here: d[1, 1] Out[58]= {0.942309} If you know there is only one solution, you can use d[x_, t_] := Evaluate[u[x, t] /. First@sol] to make d[1,1] evaluate to 0.942309 instead of {0.942309} . 2 Your data: data = {{0.067, 0.423}, {0.30, 0.408}, {0.60, 0.433}, {0.25, 0.3512}, {0.37, 0.4602}, {0.44, 0.413}, {0.60, 0.390}, {0.73, 0.437}, {0.8, 0.47}}; errors = {0.055, 0.0552, 0.0662, 0.0583, 0.0378, 0.080, 0.063, 0.072, 0.08}; ErrorListPlot[Transpose[{data, ErrorBar /@ errors}], PlotRange -> {0, 1}] Assume that the errors are distributed ... 7 The recursion limit error which you observe looks like a bug in N. Here is a shorter code to reproduce the issue: N[obj[args__]] := obj[args] N@obj[1, 2, 3] During evaluation of In[2]:=$RecursionLimit::reclim: Recursion depth of 1024 exceeded. >> obj[1, 2, 3] In the comments Oleksandr R. provided a workaround via combined usage of Verbatim ...

Top 50 recent answers are included