Message Boards Message Boards

0
|
6700 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Split an expression according to parameter type

Posted 8 years ago

I have a term f[p] that is composed of unknown parameters U = {U1, U2...}and known parameters K={K1,K2...} and functions related to this so

f[p] = fu[U]*fk[K] 

Thee two functions are assumed to all be constituted by factors multiplied by each other, for instance like this

 f[p]= U1^3*Cos[ U1+U2]*Sin[K2]*K3^2 *sqrt[K4 +tan[K5] ]

Inner functions taking both unknown and known parameters are forbidden, so for instance Cos[U1+K2] should generate an error.

What I want is a function that is fed with the info {U,K} and then automatically splits f(p) into the two functions f[U] and fk[K].

So far I used FactorList[] to get all the constitutents of f[p].

factors = FactorList[f[p]] ={ {U1,3},{Cos[ U1+U2],1}, etc}

My idea is to analyse each factor in this list and see if it's a function of either known or unknown parameters. After each analysis each element is then put aside fo form

 f[U] =U1^3*Cos[ U1+U2]
 f[K]= K1*Sin[K2]*K3^2 *sqrt[K4 +tan[K5] ]

I guess Cases[] can be used somehow. If any element in factor contains either an element from U or K it should be put aside. This is where I need help, how to do this? :)

POSTED BY: Martin P
Posted 8 years ago

Hi Martin,

here is a solution

fact[f_, Ul_List] := 
  Times @@ Power @@@ 
    Cases[FactorList[f], 
     x_ /; Or @@ Map[MemberQ[x, #, Infinity] &, Ul]];

For example

g = U1^3*Cos[U1 + U2]*Sin[K2]*K3^2*Sqrt[K4 + Tan[K5]];
U = {U1, U2, U3};
fact[g, U]

gives U1^3 Cos[U1 + U2]

Regards

POSTED BY: Till Luc Lange
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