differential equations - how to simplify large expression with lots of special functions in it (BesselY, Hypergeometric, MeijerG etc...)
I saw this DE in Maple forum. When solving it using Mathematica 9.01, even though the result was correct (both solutions gave the same numerical answer for some random values), Mathematica's answer was much larger in size.
Using Simplify
or FullSimplify
did not help much (expression was still order of magnitude larger than Maple's result). I think special simplification rules might be needed?
I'd like to ask if there are other special simplifications to use, or commands I might be missing to reduce this result more. Below is the ODE and Maple and Mathematica results.
Mathematica:
ClearAll[y, x];
ode = y'''[x] + (1/x) y'[x] - (1/x^2) y[x] == 0;
ic = {y[1] == 1, y'[1] == 0, y''[1] == 1};
sol = y[x] /. First@DSolve[{ode, ic}, y[x], x];
Simplify[sol]
Result is too large fit in the margin of this answer, so I zoomed in
Maple:
ode:=diff(y(x),x$3)+(1/x)*diff(y(x),x)-y(x)/x^2=0;
dsolve({ode, y(1)= 1, D(y)(1)=0, (D@@2)(y)(1)=1});
simplify(%,wronskian);
y(x) = 2*x-(BesselY(0, 2)-2*BesselY(1, 2))*Pi*sqrt(x)*
BesselJ(1, 2*sqrt(x))+Pi*(-2*BesselJ(1, 2)+BesselJ(0, 2))
*sqrt(x)*BesselY(1, 2*sqrt(x))
Update
Here is Maple result written using Mathematica notation in case someone wants to use to help find simplification to Mathematica solution. Also tried Simplify[mma == maple]
suggested in the comments below.
ClearAll[y, x];
ode = y'''[x] + (1/x) y'[x] - (1/x^2) y[x] == 0;
ic = {y[1] == 1, y'[1] == 0, y''[1] == 1};
mma = y[x] /. First@DSolve[{ode, ic}, y[x], x];
maple = 2 x - (BesselY[0, 2] - 2 BesselY[1, 2]) Pi Sqrt[x] BesselJ[1,
2 Sqrt[x]] + Pi (-2 BesselJ[1, 2] + BesselJ[0, 2]) Sqrt[x] BesselY[1,
2 Sqrt[x]];
N[mma /. x -> 3]
(*3.33870606057436*)
N[maple /. x -> 3]
(*3.33870606057435*)
Simplify[mma == maple]
(* too large to post *)
Related question here
Answer
Using FunctionExpand
as suggested by Vladimir can improve the simplification, but for some inputs FunctionExpand
is very slow in this case MeijerG
is the one causing problems. By replacing all occurances of MeijerG
with a temporary symbol it is possible to get improved results quicker:
safeApply[f_, expr_, bad_List] := Module[{
badOnes = DeleteDuplicates@Cases[expr, Alternatives @@ bad, Infinity],
temp, cleanRules
},
(* Replace anything bad with temp[i], apply function and unreplace *)
cleanRules = MapThread[#1 -> temp[#2] &, {badOnes, Range[Length@badOnes]}];
f[expr /. cleanRules] /. Reverse[cleanRules, 2]
]
LeafCount[sol]
(* 5097 *)
LeafCount[Simplify[sol]]//AbsoluteTiming
(* 5.5s 1992 *)
LeafCount[res = Simplify@safeApply[FunctionExpand, sol, {_MeijerG}]]//AbsoluteTiming
(* 8.5s 434 *)
LeafCount[res2 = safeApply[
Simplify[#, TransformationFunctions -> {Automatic, FunctionExpand}] &,
res,
{_MeijerG}]] // AbsoluteTiming
(* 9.5s 380 *)
Still a bit to go to reach LeafCount
of 55 in the maple result.
Comments
Post a Comment