Tag Info

Hot answers tagged

46

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 ...


29

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: ...


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, ...


6

I am not getting the same results in version 10. Also I see no problem with the results already indicated, and I'll say a bit about that as we proceed. Here is what I obtain in version 10. smatrix = {{1 - 2.96392/u2, 0.0000196744/u2}, {1. - 2.96392/u2, -2.11737*10^-10 + 0.0000196746/u2}}; det = Det[smatrix]; sols = Solve[det == 0, u2] During ...


5

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 ...


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, ...


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 ...


5

T[t_] := {(-Sin[t])/(Sqrt[1 + Cos[t/2]^2]), (Cos[t])/(Sqrt[1 + Cos[t/2]^2]), (Cos[t/2])/(Sqrt[1 + Cos[t/2]^2])} B[t_] := Rationalize@{(-0.5 Cos[t] Sin[t/2] + Cos[t/2] Sin[t]) Sqrt[1.625 + 0.375 Cos[t]], (-Cos[t/2] Cos[t] - 0.5 Sin[t/2] Sin[t])/Sqrt[1.625 + 0.375 Cos[t]], 1/Sqrt[1.625 + ...


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

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 ...


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 = ...


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


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 ...


2

@Kellen Myers comment is useful. Since your coefficients are reals you have an approximate solution Whenever a number carries a decimal point as your solution output, it is an approximate real. 0.//Head (* out *) Real As mentioned in documentation center for Real you may change an approximate real number in an exact rational number by ...


2

Guard against premature evaluation of the inside minimization by putting it inside a function which won't evaluate until a numeric argument is supplied: f[x_, y_] = 1 + x^2 - y^2; fminx[y_?NumericQ] := NMinValue[f[x, y], {x}]; FindMaximum[fminx[y], {y, 1.}] // AbsoluteTiming (* {0.515133, {1., {y -> -7.45058*10^-9}}} *) NMaximize[fminx[y], {y}] // ...


1

This is really totally normal. Your characteristic polynomial has coefficients ~10^(-10) and your solutions sometimes seem to evaluate to f(sol)= 10^(-20) instead of 0. The precision with which Mathematica will NSolve an equation may be different than the care it takes when you plug in various floating-point reals back into the function they might satisfy. ...


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)) ...


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 ...



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