MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: I am having some problem manipulating mathematica expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91796] Re: I am having some problem manipulating mathematica expressions
  • From: dh <dh at metrohm.ch>
  • Date: Mon, 8 Sep 2008 05:02:32 -0400 (EDT)
  • References: <g9qidd$4b0$1@smc.vnet.net>

Hi,

an expression like expr= t1+t2+.. has the internal form: Plus[x1,x2,..]. 

To convert this into a list, all we need tzo do is to change the Head of 

"Plus" to "List" like:

List @@ expr

this will give a list with the terms.

hope this helps, Daniel



pratip wrote:

> Hallo everybody,

> 

> I am having a small problem while dealing with the parts of a Mathematica expression. Here I give an example.

> take the LHS of a  system of equations

> {a*Sin[y*x]*x^2-x^3+Cos[b*(y/Exp[c*x])]==0,

> c*x^2+Log[d*(x*y)]==0}

> Hence the expression is

> {

> a*Sin[y*x]*x^2-x^3+Cos[Tan[x+y]+b*(y/Exp[c*x])],

> c*x^2+Log[d*(x*y)]

> }

> Now take the first expression

> There we can see the three first level terms

> {

> a*Sin[y*x]*x^2,

> x^3,

> Cos[Tan[x+y]+b*(y/Exp[c*x])

> }

> separated with {+,-,+}

> Now how to Count how many such parts exists in general?

> Because I want to get every single term multiplied with different symbols. Here we have three terms in the first expression so we must get

> {p$1*(a*Sin[y*x]*x^2)-p$2*(x^3)+p$3*(Cos[Tan[x+y]+b*(y/Exp[c*x])]}

> Hence I am trying to write a function that is defined like this

> 

> MyFunction[x_List]:={List[y],List[p]}

> and works like this

> Input:

> {

> a*Sin[y*x]*x^2-x^3+Cos[Tan[x+y]+b*(y/Exp[c*x])],

> c*x^2+Log[d*(x*y)]

> }

> Output:

> {

> {p$11*(a*Sin[y*x]*x^2)-p$12*(x^3)+p$13*(Cos[Tan[x+y]+b*(y/Exp[c*x])]),p$21*(c*x^2)+p$22*(Log[d*(x*y)])},

> {p$11,p$12,p$13,p$21,p$22}

> }

> I don't think it is too difficult for people of your skills. But I don't know a very nice way to do it when the starting equation system can have any number of equations and LHS of every equation can have any number of first level terms combined with "+" or "-". It might also occur that some equations will have just a single term LHS e.g "x^2==0".

> 

> So that was the primary problem. It will be even better (actually that is the real thing I am looking for) if it is possible to extend this operation on every higher part level recursively. That means to multiply part of a part with symbols like before. For example if we have the following equation

> Cos[Tan[x+y]+b*(y/Exp[c*x])]==0 we have

> 

> Input:

> {Cos[Tan[x+y]+b*(y/Exp[c*(x+Sin[x+y])])]}

> 

> Output:

> {

> {p$1$1$1*(Cos[Tan[p$1$2$1*x+p$1$2$2*y])+p$1$1$2*(b*(y/Exp[p$1$2$3*c*(x+Sin[p$1$3$1*x+p$1$3$2*y])]))])},

> {{p$1$1$1,p$1$1$2},

> {p$1$2$1,p$1$2$2,p$1$2$3},

> {p$1$3$1,p$1$3$2}}

> }

> 

> Down is the explanation of this above notation

> 

> *****What is i*****

> The meaning of the symbol p$i$j$k is as follows

> "i" denotes the number of main expression p occurs. Here we had only one expression so all i is equal to one. If we had two expressions some p will be like "p$2$j$k".

> 

> *****What is j*****

> "j" denotes the level in the expression where p is getting multiplied. In the above example there are three parameter that occurs in the second level namely {p$1$2$1,p$1$2$2,p$1$2$3}.

> 

> *****What is k*****

> "k" is meant for counting the p that occurs in a fixed level in a fixed expression.

> 

> I finally re grate that my message may seem too long for many of you though the question in it is not that much challenging at least mathematically. But I hope some of you might have a nice answer. My skill in Mathematica seems to be not enough to deal with this problem.I am feeling kind of hopeless.

> 

> Pratip

> 





-- 



Daniel Huber

Metrohm Ltd.

Oberdorfstr. 68

CH-9100 Herisau

Tel. +41 71 353 8585, Fax +41 71 353 8907

E-Mail:<mailto:dh at metrohm.com>

Internet:<http://www.metrohm.com>




  • Prev by Date: Re: Help on Collecting Integers
  • Next by Date: Re: Rearrangement of expression
  • Previous by thread: Re: use vim to edit mathematica file
  • Next by thread: how to convert output file to compatible format