1

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?

jjc385
  • 3,473
  • 1
  • 17
  • 29
  • 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? – march Aug 31 '17 at 19:03
  • @march I mean that I want it to collect expression with p^0,p^1,p^2. – sajad.sharhani Aug 31 '17 at 19:08
  • @march I don't want to give n a value because I need to get a general expression – sajad.sharhani Aug 31 '17 at 19:10
  • 1
    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. – march Aug 31 '17 at 20:05
  • @march Is it not surprising that the the input is returned unchanged? Aren't there plenty of powers of p outside of the (stuff)^(depends on n) expressions that should be collected? Compare to e.g. Collect[(q + p) (1 + p)^n, p], which (expectedly) returns p (1 + p)^n + (1 + p)^n q. Another weird thing: Collect[OPsExpression, p, foo] returns a result with foo absent. Compare to e.g. Collect[a + b, p, foo], which (expectedly) returns foo[a+b]. – jjc385 Sep 01 '17 at 03:27
  • 2
    @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. – jjc385 Sep 01 '17 at 19:49
  • @sajad Is n an integer? If so, you can probably apply the binomial theorem and come up with the coefficients of each power of p in terms of n and binomial coefficients. – jjc385 Sep 01 '17 at 20:31
  • @jjc385 unfortunately no. The value of n is between 0 and 1 – sajad.sharhani Sep 01 '17 at 20:35
  • @sajad I see. What kind of output are you seeking? – jjc385 Sep 01 '17 at 20:37
  • I think the best solution is to use series and then collect them – sajad.sharhani Sep 01 '17 at 20:37
  • 1
    @jjc385. I suspected something of that sort, although admittedly it is a little inconsistent. (It looks like OP needs Series anyway, though!) – march Sep 08 '17 at 23:08

0 Answers0