Skip to main content

functions - Get leading series expansion term?


Given a function f[x], I would like to have a function leadingSeries that returns just the leading term in the series around x=0. For example:


leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)]


x



and


leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)]



-(1/(16 x^3))



Is there such a function in Mathematica? Or maybe one can implement it efficiently?


EDIT


I finally went with the following implementation, based on Carl Woll's answer:


lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal)

The advantage is, that this one also properly works with functions whose leading term is a constant:



lds[Exp[x],x]


1




Answer



Update 1


Updated to eliminate SeriesData and to not return additional terms


Perhaps you could use:


leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]]


Then for your examples:


leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x]
leadingSeries[Exp[x], x]
leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x), x] // TeXForm


x


1


$-\frac{1}{16 x^3}$




One more example:


leadingSeries[x^100 (1/x + 2 + (1 - 1/x^2)/4)/(4 + x), x] // TeXForm


$-\frac{x^{98}}{16}$



This last example shows that leadingSeries works even when the leading term has a very high order. Using something like Series[expr, {x, 0, 1}] will not get the leading order, although it does return something that would be useful as a stepping stone towards the answer.


Update 2


Updated to support arbitrary expansion points



Here is a version for arbitrary expansion points:


leadingSeries[expr_, {x_, x0_}] := Normal[
expr /.
x -> Series[x, {x, x0, 1}] /.
Verbatim[SeriesData][a__, {b_, ___}, c__] :> SeriesData[a, {b}, c]
]

For example:


leadingSeries[Gamma[x],{x,Infinity}]//TeXForm



$\sqrt{2 \pi } \sqrt{\frac{1}{x}} e^{x \left(-\log \left(\frac{1}{x}\right)-1\right)}$



Comments

Popular posts from this blog

plotting - Plot 4D data with color as 4th dimension

I have a list of 4D data (x position, y position, amplitude, wavelength). I want to plot x, y, and amplitude on a 3D plot and have the color of the points correspond to the wavelength. I have seen many examples using functions to define color but my wavelength cannot be expressed by an analytic function. Is there a simple way to do this? Answer Here a another possible way to visualize 4D data: data = Flatten[Table[{x, y, x^2 + y^2, Sin[x - y]}, {x, -Pi, Pi,Pi/10}, {y,-Pi,Pi, Pi/10}], 1]; You can use the function Point along with VertexColors . Now the points are places using the first three elements and the color is determined by the fourth. In this case I used Hue, but you can use whatever you prefer. Graphics3D[ Point[data[[All, 1 ;; 3]], VertexColors -> Hue /@ data[[All, 4]]], Axes -> True, BoxRatios -> {1, 1, 1/GoldenRatio}]

plotting - Mathematica: 3D plot based on combined 2D graphs

I have several sigmoidal fits to 3 different datasets, with mean fit predictions plus the 95% confidence limits (not symmetrical around the mean) and the actual data. I would now like to show these different 2D plots projected in 3D as in but then using proper perspective. In the link here they give some solutions to combine the plots using isometric perspective, but I would like to use proper 3 point perspective. Any thoughts? Also any way to show the mean points per time point for each series plus or minus the standard error on the mean would be cool too, either using points+vertical bars, or using spheres plus tubes. Below are some test data and the fit function I am using. Note that I am working on a logit(proportion) scale and that the final vertical scale is Log10(percentage). (* some test data *) data = Table[Null, {i, 4}]; data[[1]] = {{1, -5.8}, {2, -5.4}, {3, -0.8}, {4, -0.2}, {5, 4.6}, {1, -6.4}, {2, -5.6}, {3, -0.7}, {4, 0.04}, {5, 1.0}, {1, -6.8}, {2, -4.7}, {3, -1....