# Speed up this series expansion?

Posted 5 months ago
827 Views
|
10 Replies
|
1 Total Likes
|
 Hi, I wonder why the following commands: Fun1[s_] := (1 - BesselK[0, Sqrt[s + gam]]/BesselK[1, Sqrt[s + gam]])/(s*Sqrt[s + gam]); ser1 = Series[Fun1[s], {s, ?, 60}]; are still not completed after a day of calculations on a supercomputer? Is there any way to speed up the computations? Leslaw Answer
10 Replies
Sort By:
Posted 2 days ago
 nmax=5; coeffs = Array[F, nmax, 0]; F = (z^2 + z (1 + th))/(2 ((Sqrt[z + 1] + th)^2)); Do[ F[k] = Simplify[D[F[k - 1], z]], {k, 1, nmax}]; Do[ F[k] = F[k]/k!, {k, 0, nmax}]; Total@Factor[ReplaceRepeated[coeffs, {z -> 0}]] (* th/(8 (1 + th)^3) + 1/(2 (1 + th)) - (th (3 + th))/(16 (1 + th)^4) *) (Series[(1 + z + z th)/(2 z ((Sqrt[1 + z] + Sqrt[z] th)^2)), {z, Infinity, 4}] // Simplify) // Normal (*-((th (3 + th))/(16 (1 + th)^4 z^4)) + th/(8 (1 + th)^3 z^3) + 1/((2 + 2 th) z) *) Thanks, works for me now. Answer
Posted 2 days ago
 It does work for me, but the code is incomplete. Derivatives have to be evaluated at z=0 (which corresponds to z=infinity in the original problem). Hence one can add something like Factor[ReplaceRepeated[coeffs,{z->0}]] at the end, to obtain results maximally resembling those from the Series[] command (for small nmax). Lesław Answer
Posted 2 days ago
 Your code dosen't work for me ? Answer
Posted 3 days ago
 In the meantime I attempted to construct the series expansion "by hand" as follows (the replacement of variables, z->1/z is involved, and the final code includes further processing, but this is unimportant for the performance): nmax=41; coeffs=Array[F,nmax,0]; F=(z^2+z(1+th))/(2((Sqrt[z+1]+th)^2)); Do[F[k]=Simplify[D[F[k-1],z]],{k,1,nmax}];Do[F[k]=F[k]/k!,{k,0,nmax}]. This produces the requested expansion coefficients in a computing time of a few minutes! It is astonishing why the Series command cannot do the same thing within 3 days! Leslaw. Answer
Posted 3 days ago Answer
Posted 3 days ago
 Hi, I have again a similar problem. I need to obtain series expansions of several functions, and it seems that while obtaining a few terms (let's say up to 20) does not present a problem for MATHEMATICA, a request to produce merely 40 terms causes the program to work continuously for more than two days without a perspective to finish soon. The limit of time for a single job, available for me, is 72 hours, so I need to do SOMETHING to reduce this cost. One example is the series: F[z_]=(1+z+zth)/(2z((Sqrt[1+z]+Sqrt[z]th)^2)); Series[F[z],{z,∞,40}]; where "th" is a positive parameter. My question is: is there any way to split the calculation process into two or more runs? I presume this would require saving somehow the intermediate results generated by Series[] and read them in in the next run(s). Would this be possible? Or, is there any way of combining the Series[] command somehow with other commands like Simplify[] in such a way so that the intermediate results are simplified before they are subject to further processing? This might reduce the (supposedly exponential) growth of the intermediate results. Or, is there any other method of speeding the calculations that might be applied in this case? Or, as a last resort, is there any method to stop prematurely the execution of Series[] just before the time limit is exhaused, so that I can at least save the terms that were effectively obtained during the three days of calulations, instead of wasting these three days without obtaining anything? Leslaw Answer
Posted 4 months ago
 Maple result converted to Mathematica code with only 20 terms. Converting is extremely CPU and RAM intensive.See attached file.I send you tomorrow series with 30 terms.Regards M.I.EDITED: 2020-01-16I added file: Series only 30 terms.nb .You must change file extension to *.zip and extract file. Attachments: Answer
Posted 4 months ago
 If I choose the maximum order 5 instead of 60 in the series, it works more quickly and produces an answer, but the formulae are very complicated so that probably this is why the calculations become very slow for the 60 case. However, we had a discussion several months ago which showed that the Series commands has bugs and produces wrong answers to this or similar problems. I noticed that chosing a large maximum order at least makes the initial terms reproducible upon order variations. I need 20 correct terms, and for this requiring 60 seems necessary. I will try to replace g+s by a single variable. By the way, can you send me the Maple results? Leslaw Answer
Posted 4 months ago
 My first guess has to be with "s+g" that Mathematica doesn't know if it is two independent variables or a variable and a constant (noting you have separate J(x) - will s or g be constant or in which?). If J is designed for only one variable and tries to "solve" (rather than use table) with two - it could easily just end up in an infinite loop somewhere trying to perform it and waiting for a result it will not get.Is there a proof the series, using J0(s,g) as you suggest terminates? The book and page citing it? Fun1[s_] := (1 - BesselK[0, Sqrt[x]]/BesselK[1, Sqrt[x]])/(s*Sqrt[x]); In:= Series[Fun1[s], {s, \[Infinity], 60}] // Timing Out= {0.001181, SeriesData[ds, DirectedInfinity, { dv^Rational[-1, 2] (1 - BesselK[0, dv^Rational[1, 2]]/BesselK[ 1, dv^Rational[1, 2]])}, 1, 61, 1]} (Is there some reason you cannot, here, say %/.x->(g+s)) ?)I could ask questions like whether (s*Sqrt[g+s]) ends up being a solution to another besselK but have no time - but I understand such inputs to J are common after converting an ODE to a bessel form ODE by substitution.I wonder at times why Mathematica doesn't seem to use a larger "table of equations" solutions to produce what (doesn't need to be solved because it's in a table). on the other hand i know some sol'n by mm are by table - but the tables seem to be "brief" when working in certain areas (where try to constrain variables doesn't seem to find more applicable sol'n). Answer
Posted 4 months ago
 Only comment. Comparison with Maple 2019.2.1, takes only 251.297 second. Regards M.I. Answer