collect and sort

lemelinm's picture

Hi all,


> x^2*(diff(y(x), x, x))+x*(diff(y(x), x))+(x^2-1/4)*y(x) = 0;

                 /  2      \                                   
               2 | d       |     / d      \   / 2   1\         
              x  |---- y(x)| + x |--- y(x)| + |x  - -| y(x) = 0
                 |   2     |     \ dx     /   \     4/         
                 \ dx      /                                   
> expand(1/x^2*(x^2*diff(diff(y(x), x),x)+x*(diff(y(x), x))+(x^2-1/4)*y(x) = 0));

                                 d                        
                  /  2      \   --- y(x)                  
                  | d       |    dx               y(x)    
                  |---- y(x)| + -------- + y(x) - ---- = 0
                  |   2     |      x                 2    
                  \ dx      /                     4 x     
> collect(diff(diff(y(x), x), x)+(diff(y(x), x))/x+y(x)-(1/4)*y(x)/x^2 = 0, y(x));

                                                  d          
                                   /  2      \   --- y(x)    
               /   1      \        | d       |    dx         
               |- ---- + 1| y(x) + |---- y(x)| + -------- = 0
               |     2    |        |   2     |      x        
               \  4 x     /        \ dx      /               
> sort((-(1/4)/x^2+1)*y(x)+diff(diff(y(x), x), x)+(diff(y(x), x))/x = 0);

                                                  d          
                                   /  2      \   --- y(x)    
               /   1      \        | d       |    dx         
               |- ---- + 1| y(x) + |---- y(x)| + -------- = 0
               |     2    |        |   2     |      x        
               \  4 x     /        \ dx      /               

of course, my goal is to order it starting with the second derivative.

Thanks for any help!

Mario

May be

something like this?:

d:= x^2*(diff(y(x), x, x))+x*(diff(y(x), x))+(x^2-1/4)*y(x);
map((u->collect(u,y),expand)@(u->u/x^2),d);
                             d
                / 2      \   -- y(x)
                |d       |   dx        /     1  \
                |--- y(x)| + ------- + |1 - ----| y(x)
                |  2     |      x      |       2|
                \dx      /             \    4 x /

lemelinm's picture

Thanks a lot

 All I  need to do is digest how it is working, since it's exactly what I wanted.

for easier digestion

The operands of the expression (of type `+`) are the terms of the sum, and 'map' applies the operation over each of them. This operation is the composition, via '@' of two operations: first divide by x^2, then collect for y(x) which applies in practice to the last term, expanding the coefficient to distribute the division by x^2 over each of its sumands.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}