Tag Info

Hot answers tagged

29

The primary difference between Refine and the two *Simplify functions is that Refine only evaluates the expression according to the assumptions given. It might so happen to be the simplest form when evaluated, but it does not check to see if it is indeed the simplest possible form. You should use Refine when your goal is not to simplify the expression but to ...


26

(I had been meaning to write a blog entry about this myself, but since this question has come up, I suppose I'll just write about it here instead...) In demonstrating how the quincuncial projection works, consider first the following complex mapping: With[{ω = N[EllipticK[1/2], 20]}, ParametricPlot[{Re[InverseJacobiCN[Tan[φ/2] Exp[I θ], 1/2]], ...


24

Edit: I added more explanations below, because this visualization method is quite different from conventional vector plots For just this purpose I had at some point invented the following visualization technique. I'll reproduce your definition first. It defines a complex vector field on the surface of a unit sphere. Clear[\[Epsilon]];(*Polarization ...


18

Following the advice in comments, I've made a test library for BesselJ[1, #] & function to evaluate via GSL. I still consider it a workaround, so if you find a way to use Mathematica built-in functions with good performance, please do make a new answer. Needs["CCompilerDriver`"] besselJ1src = " #include \"WolframLibrary.h\" DLLEXPORT mint ...


17

Borrowing almost verbatim from a recent response about finding extrema, here is a method that is useful when your function is differentiable and hence can be "tracked" by NDSolve. f[x_] := BesselJ[1, x]^2 + BesselK[1, x]^2 - Sin[Sin[x]] In[191]:= zeros = Reap[soln = y[x] /. First[ NDSolve[{y'[x] == Evaluate[D[f[x], x]], y[10] == (f[10])}, ...


17

It is Kampé de Fériet function, introduced in Joseph Kampé de Fériet, "La fonction hypergéométrique.", Mémorial des sciences mathématiques, Paris, Gauthier-Villars. Its definition is given on Notations page: and, in an alternative form, in Wikipedia: $${}^{p+q}f_{r+s}\left( \begin{matrix} a_1,\cdots,a_p\colon b_1,b_1{}';\cdots;b_q,b_q{}'; \\ ...


17

Short story $$ \vartheta(x) = \arg \left[(\operatorname{Bi}x+i \operatorname{Ai}x)e^{-\frac{2}{3} i (-x)^{3/2}}\right]+\frac{2}{3} \operatorname{Re}\left[(-x)^{3/2}\right] $$ Update: I see that you want use only real functions, so you can expand this as $$ \vartheta(x) = \begin{cases} \arctan\frac{\cos \left(\frac{2}{3} (-x)^{3/2}\right) ...


16

The built-in function ContinuedFractionK can be used to generate an approximation to R[q] good enough for plotting purposes. r[q_, n_] = q^(1/5) ContinuedFractionK[q^i, 1, {i, 0, n}]; r[q, 4] A very reasonable plot can be made with Plot[r[q, 20], {q, 0, 3}]


15

Here is a shameless plug for my HTML parser posted here. The code is a bit long to reproduce here, the only change to it I'd do is to replace the function processPosList with this code: processPosList::unmatched = "Unmatched lists `1` enountered!"; processPosList[{openlist_List, closelist_List}] := Module[{opengroup, closegroup, poslist}, {opengroup, ...


15

You need to add ColorFunctionScaling -> False as an option to SphericalPlot3D. That should do the trick color[Θ_, Φ_] := RGBColor[(Sign[Re[SphericalHarmonicY[2, 1, Θ, Φ]]] + 1)/ 2, 0, (-Sign[Re[SphericalHarmonicY[2, 1, Θ, Φ]]] + 1)/ 2]; SphericalPlot3D[ Re[SphericalHarmonicY[2, 1, Θ, Φ]], {Θ, 0, π}, {Φ, 0, 2 π}, ColorFunction -> ...


14

This question is not trivial as it would seem and a detailed discussion could help to understand the issue, especially when we deal with roots of special functions, however to do the task as simply as possible this would be the best way : f[x_] := LegendreP[6, x] Reduce[f[x] == 0, x, Reals] == Reduce[f[x] == 0, x] True Reduce[f[x] == 0, x, Reals] ...


14

An experimental internal function Integrate`InverseIntegrate helps here, although it's intended more for integrands involving logs. This is what it returns in the development version: Integrate`InverseIntegrate[Exp[-x Cosh[t]], {t, 0, Infinity}, Assumptions -> Re[x] > 0] (* BesselK[0, x] *)


14

I might as well elaborate on my comment. Here is a modification of Stan Wagon's FindAllCrossings[] function (from his book Mathematica in Action, second edition) that uses Plot[] to generate the initial approximations to be subsequently polished by FindRoot[]: Options[FindAllCrossings] = Sort[Join[Options[FindRoot], {MaxRecursion -> Automatic, ...


14

One can use Solve as well, e.g. s = Solve[ BesselJ[1, x]^2 + BesselK[1, x]^2 - Sin[ Sin[x]] == 0 && 0 < x < 10, x] Solve::incs: Warning: Solve was unable to prove that the solution set found is complete. >> {{x -> Root[{BesselJ[1, #1]^2 + BesselK[1, #1]^2 - Sin[Sin[#1]] &, 0.886604635313462076794393681674}]}, {x -> ...


14

Here's the exact answer: i1 = Integrate[x^n Exp[-(x - a)^2], {x, 0, Infinity}, Assumptions -> n > 0] /. n -> 1/2 (* 1/2 E^-a^2 (Gamma[3/4] Hypergeometric1F1[3/4, 1/2, a^2] + 1/2 a Gamma[1/4] Hypergeometric1F1[5/4, 3/2, a^2]) *) i1 /. a -> 0.3 (* 0.907605 *)


13

To implement what you intended to do, I suggest to take a look at this approach : hermite[0, x_] := 1 hermite[1, x_] := 2 x hermite[n_Integer /; n >= 2, x_] := hermite[n, x] = Expand[2 x*hermite[n - 1, x] - 2 (n - 1) hermite[n - 2, x]] Now you shouldn't have problems anymore. Recalling that there are in Mathematica the Hermite polynomials ...


13

Refine vs Simplify Mathematica is a term rewriting system, whenever we enter an expression, then it is evaluated by term rewriting using (built-in or user-defined) rewrite rules (see e.g. Evaluation) , so by default it "simplifies" some expressions, e.g. : a + b - a b So this makes an impression, that Refine performs some simplifications, although ...


13

For numerical evaluation, there is the rapidly-converging continued fraction (due to Jones and Thron): $$\exp(x^2)\mathrm{erfc}(x)=\frac{2x}{\sqrt \pi}\cfrac{1}{2x^2+1-\cfrac{1\cdot2}{2x^2+5-\cfrac{3\cdot4}{2x^2+9-\cdots}}},\qquad x > 0$$ One can use the built-in function ContinuedFractionK[] with a suitable cut-off: With[{x = N[30000], n = 10}, -2 x ...


13

I've had to work with that kind of function (relying on cancellation of large terms) before, and the most practical workaround I could figure out to be able to evaluate the function numerically is to use its power expansion near the point of trouble (here, $+\infty$). So, get a good look at the series expansion and find out how it works (or derive it on ...


13

If you have an analytic formula for f[x_] := Erfc[x]*Exp[x^2] not using Erfc[x] you could do what you expect. However it is somewhat problematic to do in this form because Erfc[x] < $MinNumber for x == 27300. $MinNumber 1.887662394852454*10^-323228468 N[Erfc[27280.], 20] 5.680044213569341*10^-323201264 Edit A very good approximation of ...


12

The answer is simply that integrating with the assumption that a variable comes from the class of integers is really difficult. What Integrate does with Assumptions -> Element[m, Integers] is try to generically integrate without the assumption and then apply the assumption to the result to try and simplify it. I've asked around about this before and there ...


12

The site is not terribly conducive to scraping as the HTML is "noisy" and looks like WRI might change the format at the drop of a hat. Throwing caution to the wind... scrapeWolframFunction[id_] := Import["http://functions.wolfram.com/" ~~ id, "XMLObject"] // Cases[ # , XMLElement["p", {___, "class" -> "CitationInfo", ___}, body_] :> body ...


12

There are many ways of coloring functions, to visualize spatial dependence of spherical harmonics one can take advantage of a useful function Rescale, so here is a bit different coloring using also imaginary part of the function : col[θ_, φ_] := RGBColor @ Rescale[{ Re @ #, 0, -Im @ #}]& @ SphericalHarmonicY[2, 1, θ, φ] SphericalPlot3D[ Re[ ...


11

First, this is a single equation in two unknowns so we'd expect infinitely many solutions. So, let's try to solve for one variable in terms of the other: Solve[\[Beta]^-a Gamma[a] Sin[a \[Pi]] + E^\[Beta] \[Beta]^(2 a - 1) Gamma[1 - a] Sin[a \[Pi]] == 0, \[Beta]] That message and the appearance of the ProductLog indicates that we simply might not ...


11

Following this question you can define: invmollweide[{x_, y_}] := With[{theta = ArcSin[y]}, {Pi (x)/(2 Cos[theta]), ArcSin[(2 theta + Sin[2 theta])/Pi]}]; fc[phi_] := Block[{theta}, If[Abs[phi] == Pi/2, phi, theta /. FindRoot[2 theta + Sin[2 theta] == Pi Sin[phi], {theta, phi}]]]; cart[{lambda_, phi_}] := With[{theta = fc[phi]}, {2/Pi*lambda ...


11

If you want a different 3D visualization, maybe try field lines. Usually, one should be suspicious of field line plots for time-dependent electromagnetic waves (because causality casts doubts on the meaning of plotting a spatially extended field line for a globally fixed time), but there have been recent high-profile papers that show such plots. Purely as ...


10

A bit of cheating: DifferenceRootReduce[(-1)^n BesselJ[n, z] - BesselJ[-n, z], n] 0 I must admit I'm not sure why FullSimplify[] fails on this, tho.


10

Solving symbolically transcendental equations one should appropriately use Solve or Reduce with adequate logical combinations of equations, inequalities, domain specifications, etc. to get desired results. There are limitations for certain types of equations involving transcendental functions, see e.g. Transcendental Roots. Here is an example which doesn't ...


10

In Mathematica, Gamma[a, z] refers to the upper incomplete Gamma function, given by $$\Gamma(a,z)=\int_z^\infty t^{a-1}e^{-t}\,dt$$ whereas in MATLAB, gammainc(z, a) refers to the regularized lower incomplete Gamma function $$P(a,z)=\frac{1}{\Gamma(a)}\int_0^z t^{a-1}e^{-t}\, dt$$ Obviously, they give different results. To get MATLAB's result in ...


10

I present in this answer a compiled implementation of one of the simpler algorithms for numerically evaluating a Bessel function of (modestly-sized) integer order and (small to medium-sized) real argument. This uses Miller's algorithm: bessj = With[{bjl = N[Log[1*^16]]}, Compile[{{n, _Integer}, {x, _Real}}, Module[{h, hb, ...



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