1
$\begingroup$

I am using homotopy perturbation method to solve nonlinear ODE.

The first step is to introduce P parameter and collect different order of P.

The code is like this:

Collect[(1 - 
 p) ((((1 + 
       De^2 (Derivative[1][u0] + p Derivative[1][u1] + 
          p^2 Derivative[1][u2] + p^3 Derivative[1][u3])^2)^(
     1/2 (-3 + n)) (1 + 
       De^2 n (Derivative[1][u0] + p Derivative[1][u1] + 
          p^2 Derivative[1][u2] + 
          p^3 Derivative[1][u3])^2) (Derivative[2][u0] + 
       p Derivative[2][u1] + p^2 Derivative[2][u2] + 
       p^3 Derivative[2][u3])) (Derivative[1][u0] + 
     p Derivative[1][u1] + p^2 Derivative[1][u2] + 
     p^3 Derivative[1][u3])) + (1 + 
    De^2 ((Derivative[1][u0] + p Derivative[1][u1] + 
        p^2 Derivative[1][u2] + p^3 Derivative[1][u3]))^2)^((
   n - 1)/2) (Derivative[1][u0] + p Derivative[1][u1] + 
    p^2 Derivative[1][u2] + 
    p^3 Derivative[1][u3]) (Derivative[2][u0] + 
    p Derivative[2][u1] + p^2 Derivative[2][u2] + 
    p^3 Derivative[2][u3])) + 
  p (-Ha^2 (u0 + p u1 + p^2 u2 + 
    p^3 u3) + (((1 + 
       De^2 (Derivative[1][u0] + p Derivative[1][u1] + 
          p^2 Derivative[1][u2] + p^3 Derivative[1][u3])^2)^(
     1/2 (-3 + n)) (1 + 

       De^2 n (Derivative[1][u0] + p Derivative[1][u1] + 
          p^2 Derivative[1][u2] + 
          p^3 Derivative[1][u3])^2) (Derivative[2][u0] + 
       p Derivative[2][u1] + p^2 Derivative[2][u2] + 
       p^3 Derivative[2][u3])) (Derivative[1][u0] + 
     p Derivative[1][u1] + p^2 Derivative[1][u2] + 
     p^3 Derivative[1][u3])) + (1 + 
    De^2 ((Derivative[1][u0] + p Derivative[1][u1] + 
        p^2 Derivative[1][u2] + p^3 Derivative[1][u3]))^2)^((
   n - 1)/2) (Derivative[1][u0] + p Derivative[1][u1] + 
    p^2 Derivative[1][u2] + 
    p^3 Derivative[1][u3]) (Derivative[2][u0] + 
    p Derivative[2][u1] + p^2 Derivative[2][u2] + 
    p^3 Derivative[2][u3])), p]

The problem is that don't get anything back

What do you think?

$\endgroup$
11
  • $\begingroup$ What do you mean by "The problem is that don't get anything back"? I get an output when I run your code. What are you expecting? There are p's still inside brackets because Mathematica can't expand ( stuff )^((n-1)/2) unless you supply an actual integer value for n. Is that the issue? $\endgroup$
    – march
    Aug 31, 2017 at 19:03
  • $\begingroup$ @march I mean that I want it to collect expression with p^0,p^1,p^2. $\endgroup$ Aug 31, 2017 at 19:08
  • 1
    $\begingroup$ Mathematica won't do that for you, even if you specify that n is an integer (which I assume it is?). Either do this for different actual values of n or use Series to have Mathematica compute a power series in p before collecting. This will result in pretty large expressions though. $\endgroup$
    – march
    Aug 31, 2017 at 20:05
  • 2
    $\begingroup$ @march Ah, I finally found the problem. Collect[expr ,p] appears to return expr unchanged when expr contains a rational function of p (other than p^n_). E.g., Collect[(q + p) (1 + p)^(n - 1), p, foo] returns its input unchanged. IMHO, this seems somewhat inconsistent (it carries non-rational functions along, like in Collect[(1+p) f[p], p], and even carries along expressions which will be rational for certain values of the power, like in Collect[(1+p)(p+q)^n, p]), but I suppose some choice had to be made. $\endgroup$
    – jjc385
    Sep 1, 2017 at 19:49
  • 1
    $\begingroup$ @jjc385. I suspected something of that sort, although admittedly it is a little inconsistent. (It looks like OP needs Series anyway, though!) $\endgroup$
    – march
    Sep 8, 2017 at 23:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.