Tag Info

Hot answers tagged

15

Integrate the zero-order interpolation of the data: f[x_] = Integrate[Interpolation[dat, InterpolationOrder -> 0][x], x]; Plot[f[x], {x, 0, 110}, AspectRatio -> Automatic, GridLines -> {{18, 70, 90}, None}] It can efficiently plot piecewise functions with thousands of transition points in milliseconds: dat = {Accumulate@RandomReal[{0, 1}, ...


13

In some settings the integers, fractions, rational numbers, reals, and complexes are five distinct systems. Further, for reals and complexes, there are the standard reals and complexes as well as nonstandard systems. There are mappings from some to others, so that a subset of the reals in an isomorphic image of the integers (as rings), and so on for ${\bf ...


12

For readers who didn't read all the comments, the slowdown is due to a lack of packing of tb, whereas RandomReal returns packed arrays when more than 250 elements are generated. The reason why packing tb fails is because some elements have different precision than others, and (I think?) ToPackedArray requires arrays to be of homogeneous type. To fix this, ...


10

As noted in post, responses and comments, Real is a Mathematica head and, as such, is distinct from Integer and Rational and Complex. All of these are regarded as "atomic" (notwitstanding that Rational has two Integer "parts", and Complex is comprised of any mix of the other three types). These atomic types are in a sense distinct from the domains one ...


8

My original answer (below) is wrong. Arbitrary precision does not fix this problem, I only fooled myself (and others) into thinking that it does. Now please consider: Power[-1`5, 2`5] 1.0000 + 0.*10^-5 I This agrees with the output of the effective computation that Daniel described in a comment: power[base_, pow_] := Exp[pow*Log[base]] power[-1`5, ...


4

My guess is that when you write 1. and 2. as opposed to 1 and 2 you are telling Mathematica that the numbers you are using are not integers but that they are rather real numbers whose best decimal representation is, as far as you know or within your accuracy criteria, 1.0 and 2.0. Thus, numerical methods are legitimate and you can expect numerical errors. ...


4

You can find the family of parameters with Reduce. For example f[x_] := x^5 + a x^4 + b N@Reduce[f[x] == x && f'[x] == 1 && 0 < a < 1, {x, a, b}, Reals] Here x acts as an arbitrary parameter with certain restrictions.


3

This appears to be a precision issue. Increase the precision. S[i_, j_] = 8 Sqrt[1.7^(3 i + 3 j - 6)]/ (1.7^(i - 1) + 1.7^(j - 1))^3 // Rationalize // Simplify; H[i_, j_] = -8 Sqrt[1.7^(3 i + 3 j - 6)]/ (1.7^(i - 1) + 1.7^(j - 1))^3* (0.01*(1.7^(i - 1) + 1.7^(j - 1)) - 0.01^2*1.7^(i + j - 2)) // Rationalize // Simplify; ...


3

Although I like DumpsterDoofus's answer a lot more, now that I am properly awake I realize this works: dat = {{0, 0}, {18, 1}, {70, 1/4}, {90, -1}, {110, 2}}; g[{x_, y_}, {X_, Y_}] := {X, y + (X - x) Y} f2 = Interpolation[FoldList[g, dat], InterpolationOrder -> 1]; Plot[f2[x], {x, 0, 110}, AspectRatio -> Automatic, GridLines -> {{18, 70, 90}, ...


3

funny I just worked this up for this answer here : http://mathematica.stackexchange.com/a/71427/2079 dat = {{0, 0}, {18, 1}, {70, 1/4}, {90, -1}, {110, 2}}; xmap[x_] = Piecewise[ Fold[Append[#, {(#[[-1, 1]] /. x -> (Last@Last@Last@#)) + #2[[2]] (x - (Last@Last@Last@#)), x < #2[[1]]}] &, {{x dat[[2, 2]], x < ...


3

Couple of additional or summary points. This is a great question for the 21st century. Since the question regards mathematical definitions, "domain" isn't defined (at least by itself, unlike say "integral domain"). Instead should refer to specific categories like Set. Be especially careful with fields, eg non-Archimedean ones. IEEE 754 floating point was ...


3

The given integral can be integrated exactly and quickly. Integrate[fermitotal[beta, k, mu, delta] k^2, {k, 0, 20}] // AbsoluteTiming N@Last[%] (* {0.006876, 8000/3} 2666.67 *) But since, presumably, the OP's actual use-case is not, I'll comment on the set up and the relation of OP's choices to speed. Remarks on the OP's option settings Since it's a ...


3

Although Implicit Euler is described in the documentation, it may not be an implemented Method. In fact, the Wolfram discussion of the Lotka–Volterra Equation actually defines Backward or Implicit Euler, suggesting that it is not an implemented Method: BackwardEuler = {"FixedStep", Method -> {"ImplicitRungeKutta", "Coefficients" -> ...


2

It seems to be a performance problem (bug?) in version 9.0.1. Version 7.0.1 is also slow, but perhaps is not capable of this calculation. However, version 8.0.4 can produce the correct result quickly, so there seems to be no good reason why 9.0.1 should take so long. I didn't try 9.0.0. The interesting thing, is that 9.0.1 has no problem with the purely ...


2

This is a typical Finite Difference Method. x = dat[[;; , 1]]; y={#}~Join~(# + Accumulate[Differences[x] dat[[2 ;;, 2]]]) &@dat[[1, 2]]; Now f = Interpolation[Transpose[{x, y}], InterpolationOrder -> 1]; Plot[f[x], {x, 0, 110}, AspectRatio -> Automatic,GridLines -> {x, None}]


2

lets make a fair fortran test... raise a complex typed number 1 to the power: write(*,*)(-1.d0,0.d0)**2.,(-1.d0,0.d0)**2 (1.00000000000,-2.449212707...E-16 ) , ( 1.0000000000,0.000000000 ) also note in fortran the real power can not yield a complex result, that is -1.**.5 throws an error or yields NaN depending on the compiler so you see -1.**2. ...


2

Primary fixes: Adding First to fidelPhase and adding t to Subscript[u, i, j][t]. Making an objective function obj that is not evaluated until a and b are numeric may or may not be important. I won't have time to check it out (I've lost track of the original optimizer). The following works and it's not crucial to be so precise in one's fixes. ...


1

I propose a silly workaround, instead of a workable explanation: Get["tb.dat"]; xls = Range[-500, 500, 1000/(1000 - 1)] // N; test[tb_] := (Re[Conjugate[#].(xls*#)] & /@ tb;) // AbsoluteTiming; test[RandomComplex[{0., 1. + I}, Dimensions[tb]]] (* {0.002002, Null} *) test[tb] (* {0.040038, Null} *) test[tb + ConstantArray[0. + 0. I, Dimensions@tb]] (* ...


1

You can solve for the reciprocal of res: capacitance =.; Solve[i[250*10^-6, res] == 10^-6 /. res -> 1/reciprocal, reciprocal, Reals] Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. >> {{reciprocal -> ...


1

Here is the "code" of your question with unspecified blanks filled in and errors fixed: F[u_] := Log[u] - Cos[u^2] Exp[-u]; Umax[x_, y_] := x + y; W[x_?NumericQ, y_?NumericQ] := NIntegrate[F[u], {u, 0, Umax[x, y]}]; g[x_?NumericQ, y_?NumericQ] := x^2/y^2; Alpha[x_?NumericQ] := Tanh[x]; myFunction[x_?NumericQ] := NIntegrate[g[x, y]*W[x, y], {y, ...


1

ListPointPlot3D[data, PlotStyle -> Directive[PointSize[0.02], Thickness[0.01]]] /. Point[x_] -> Through[{Point, Line}[x]]


1

d = data /. {x_Real, y_Real, z_Real} -> {{x, y}, z}; dat = Flatten[d, 1]; int = Interpolation[dat]; Plot3D[int[x, y], {x, 0, 1.6}, {y, 0.1, 10}, Mesh -> {data[[All, 1]][[All, 1]], data[[1, All]][[All, 2]]}, PlotStyle -> Opacity[0.5], MeshStyle -> {Red, Blue}] The idea is to use Mesh option for drowing lines on surface obtained from ...


1

I'm afraid that this is a bit puzzling indeed. If I use your example and run the NIntegrate without all the fancy options I get {0.006944, 2666.67}. So I assume it has something to do with your options. Leaving out the method, but leaving everything else in place, slows down things dramatically, but it is still doable: {0.561119, 2666.666666667}, ...


1

Use the substitution rule as follows: myExpression /. Sqrt[x___] -> x^0.5 Example: myExpression = Cos[t] + Sin[y] + Sqrt[a y + Tanh[z] + u^3] Cos[t] + Sin[y] + (u^3 + a y + Tanh[z])^0.5


1

Using Picard iterations I get this series solution: First we convert it to standard form $x'=f(x(t),t)$ and apply Picard: Problem: Solve $x^{\prime\prime}\left( t\right) +x\left( t\right) -10\left( 1-x\left( t\right) ^{2}\right) x^{\prime}\left( t\right) =0$ with $x\left( 0\right) =2,x^{\prime}\left( 0\right) =0$ Let ...



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