Tag Info

New answers tagged

1

I'd argue you should reformulate your function to avoid the issue -- however if a straightforward quadrature scheme will work for you (ie. you don't need adaptive schemes etc ) you can do a direct evaluation: Simpsons rule for example: foo[x_?NumericQ] := ({x^2, x^3}); np = 99;(*assumed odd for simpsons rule*) a = 0; b = 1; wt = (b - a)/(3 (np - 1)) ...


6

The explanation was already delivered by Mr.Wizard, but I would like to add that there is a similar capability to the Indexed approach already built in to NDSolve or NDSolveValue. So we can leverage NDSolve instead of NIntegrate as follows: foo[x_?NumericQ] := {x^2, x^3}; NDSolveValue[{y'[x] == foo[x], y[0] == {0, 0}}, y, {x, 0, 1}][1] (* ==> {0.333333, ...


4

This seems like a bug, or at least a "glitch" in NIntegrate. I believe that it expects the evaluated structure of the integrand to match when given symbolic and numeric input. I imagine that it looks at the structure of the output of foo[x] and then sets up the rest of the computation based on that; when it then get a List output from e.g. foo[0] it fails ...


5

This blog is a good start: Using Mathematica to Simulate and Visualize Fluid Flow in a Box It fully solves 2D problem of one moving boundary and gets nice vertex flows: There are detailed descriptions of proper equations and numerical discretization. You can generalize to 3D. I would look also in latest V10 functionality to see if anything can be ...


4

You can use ParametricNDSolve to implement a shooting method. Define a finite version of "infinity". inf = 5; Define the differential equation and its initial conditions, parameterised by the initial gradient y'[0] == dy0. For simplicity, I set y[0] == 1. deqn = {y''[x] - x y[x] == 0, y[0] == 1, y'[0] == dy0}; Compute the numerical solution ...


3

Timing under 20 seconds on my computer now. Ok, your original program took about 60 seconds on my computer meaning that my computer is faster. The dramatical gain of time is due to halfing the MaxRecursion option value. The plot still shows no visible difference. I replaced Pi-Symbol by Pi for increasing readability in forum. I tested some scenarios, and ...


2

The answer is very nicely illustrated in following link at the topics "Round-Half-Even (Banker's Rounding)" and "Round-Half-Odd": Clive (Max) Maxfield and Alvin Brown, Rounding Algorithms 101 http://www.clivemaxfield.com/diycalculator/popup-m-round.shtml#A5


5

What have you tried so far? You can use Solve to solve for θ. Solve[a1 Sin[2θ] + a2 Sin[2ϕ] + a3 Cos[2θ] + a4 Cos[2ϕ] == a5, θ] /. _C -> 0 Since your equation have periods π, you can just let ϕ run between 0 and π, and add arbitrary multiples of π to the solutions. Another way You can plot it using ContourPlot. I used bounds 0 < θ < π and 0 ...


4

To compute $\nabla^nr$ for arbitrary integer $n$, you can use the built-in tensor derivative syntax. For example, you can compute the second-derivative $\nabla^2r$ using r = Sqrt[x^2 + y^2 + (z - a)^2]; X = {x, y, z}; D[r, {X, 2}] To get an answer in terms of $r$, you can sort of cheat your way to the correct answer via the following modification: r = ...


1

r[x_, y_, z_] = Sqrt[x^2 + y^2 + (z - a)^2]; D[r[x, y, z], #] & /@ {x, y, z} {x/Sqrt[x^2 + y^2 + (-a + z)^2], y/Sqrt[ x^2 + y^2 + (-a + z)^2], (-a + z)/Sqrt[x^2 + y^2 + (-a + z)^2]} or more simply, % == D[r[x, y, z], {{x, y, z}}] True %% == {x, y, z - a}/r[x, y, z] True EDITED to add higher order partial derivatives Second ...


2

First, you have t in the slot for δ -- that may be a mistake. Be that as it may, the the question about the warning FindRoot::lstol has an explanation. Second, you're getting complex solutions because the function evaluates to complex numbers: fumfa[2.0, 1.0, Ωs, 2.0, 3.5, t, 4] /. {t -> 0.1, Ωs -> 4.0} (* 1.02171 + 0. I *) Finally, the ...


2

There is a third argument for Solve but you can use NSolve to get a numerical solution in the Reals: NSolve[x^3 - 1 == x, x, Reals] {{x -> 1.32471796}} OR Solve for exact Root solutions Solve[x^3 - 1 == x, x, Reals] {{x -> Root[-1 - #1 + #1^3 &, 1]}} OR as Michael E2 noted in the comments, using ToRadicals will give you something ...


5

The commands FixedPoint and FixedPointList are rather specialized versions of Nest and NestList - both sets of commands perform functional iteration but the FixedPoint versions stop when the iterate stops changing. The *List versions return the whole computed sequence of iterates, while the non-List versions return just the last iterate. Thus, ...


45

OK, there is good news and there is bad news. In the current version 10 there is no way to do this directly. That's the bad news. The good news is that finite element framework used within NDSolve is exposed and documented; for maximum "hackability" convenience. Let's start with a region that @MarkMcClure would consider interesting. We load our favorite ...


28

I've encapsulated the code of the mysterious user21 into a helmholzSolve command. The code is at the end of this post. It adds very little to user21's code but it does allow us to examine multiple examples quite easily, though it has certainly not been tested extensively and could be improved quite a lot I'm sure. It should be called as follows: ...


13

Solution It appears this bug is the result of attempted parallelism gone wrong. I believe it is corrected in all cases by setting this System Option: SetSystemOptions[ "ParallelOptions" -> {"MachineFunctionParallelThreshold2" -> Infinity} ] This appears to be an out and out bug and I tagged the question accordingly. Original observations: ...


19

Taking the cube root on both sides fixes the problem, and then you don't need lots of PlotPoints any more. ContourPlot3D[(x^2 + 9/4 y^2 + z^2 - 1) == CubeRoot[x^2 z^3 + 9/80 y^2 z^3], {x, -6/5, 6/5}, {y, -6/5, 6/5}, {z, -6/5, 3/2}, Mesh -> None, Boxed -> False, AxesLabel -> {"x", "y", "z"}, Axes -> False, ContourStyle -> Directive[Red, ...



Top 50 recent answers are included