Message Boards Message Boards

0
|
3752 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Set options for Collect function in Wolfram Language?

Posted 7 years ago

Dear All,

I am working on the solution of an ordinary differential equation. Among others related to a given Ansatz I get a long set of sums I want to sort and order in dependency of terms like

((x/(-1 + x))^(expnt)

with the exponents "expnt"

1/4, 1/2, 3/4

to do this, I put something like this to my code

Collect[q, {((x/(-1 + x))^(1/4)), ((x/(-1 + x))^(1/
      2)), ((x/(-1 + x))^(3/4))}]    

the result provides summands of the type

const ((x/(-1 + x))^(expnt) x^n / (-1+x)^m

where n, m are integers.

Unfortunately there are 4 summands, which do not behave like this. They show exponents of order 19/4, 15/4 and 7/4

Obviously I have to tune the Collect code line.

My question to the experts:

Would you please give me a hint to tune my Collect code line to avoid the above mentioned exponents.

Additionally I added an nb-File to reproduce the problem and because of the large number of summands a PDF of my output showing the problem summands marked with a red box.

Regards,

drnie

Attachments:
POSTED BY: Guido Nierhauve
2 Replies

(edited)

My suggestion is to use the pattern matching to isolate terms of x^n/(x-1)^m. To do this you can pattern match the various forms of the term and replace it with another variable (in this case "g").

nq = (q/. (* match the term raised to a power *)
(x/(x-1))^(w_)-> g^w ) /. 
(* match the the numerator and denominator raised to the same power w is negative *)
        Times[Power[Plus[-1,x],w_],Power[x,v_]]/; Abs[w]==Abs[v]->g^v /. 
(* match the the denominator raised to a higher power *)
        Times[Power[Plus[-1,x],w_],Power[x,v_]]/; Abs[w]>Abs[v]->g^v *(x-1)^(w+v)/. 
(* match the the numerator raised to a higher power *)
        Times[Power[Plus[-1,x],w_],Power[x,v_]]/; Abs[w]<Abs[v]->g^Abs[w ]*x^(w+v) /.
(* match the term raised to no power *)
        x/(x-1)->g /. 
(* match the term raised to no power *)
        x/(x-1)^2->g /(x-1)

The result is a long expression in g. Now you can Collect in g. My first posting had a typo in the rules -- you should verify that they are mathematically correct)

Is this what you were looking for?

POSTED BY: Neil Singer

Dear Neil Singer,

thank you very much for this qualified reply. It was near to this I needed. To solve the ODE one has to break down the problem into one or more convenient ODEs. The way I want to go a way to eliminate the factors (x/(-1+x))^(1/4), (x/(-1+x))^(1/2) and (x/(-1+x))^(3/4) by collecting the terms related to these factors and to solve the resulting 4 differential equations. In a first step I want to see the set of terms collected under the above mentioned factors to get an impression of the Ansatz I have to select to solve the ODEs in a second step.

Your code snippet was really helpful. I took the code and modified it like this:

nq = (q /. (x^(19/4))/((-1 + x)^(11/
          4)) -> ((x^4)/((-1 + x)^2)) (x/(-1 + x))^(3/4) /. (x^(15/
         4))/((-1 + x)^(7/4)) -> ((x^3)/((-1 + x))) (x/(-1 + x))^(3/4))

"and do the Collect once again"
"now all summands are well collected to each of the factors \
(x/(-1+x))^(1/4) or  (x/(-1+x))^(1/2) or  (x/(-1+x))^(3/4) and the \
rest"
s = Collect[
  nq, {((x/(-1 + x))^(1/4)), ((x/(-1 + x))^(1/2)), ((x/(-1 + x))^(3/
       4))}]

Now all summands are collected as expected.

Regards,

drnie

Attachments:
POSTED BY: Guido Nierhauve
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract