MathGroup Archive 2010

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

Search the Archive

Re: solving equations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108468] Re: solving equations
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 19 Mar 2010 02:47:23 -0500 (EST)

On 3/18/10 at 4:33 AM, arbiadr at gmail.com (Maria Davis) wrote:

>I want to solve an equation system saved in the file named
>"equations.txt". My aim is to obtain the expression of
>source.outputP.TP in terms of the variables: channel.TP, consumer.TP
>and producer.TP

>This file "equations.txt" contains the following equations:

<contents snipped>

>I have used an other file containing the variables which must be
>eliminate this file "variables.txt" contains:

<contents snipped>

>The code I have used for solving this problem is:

>dots = ReadList["C:\projet\variablesTP.txt", Record,
>RecordSeparators -> {}] nodots = StringReplace[dots[[1]],
>StringExpression[pre : LetterCharacter, ".", post1 :
>LetterCharacter, ".", post2 : LetterCharacter] :> StringJoin[pre,
>"\[Bullet]", post1, "\[Bullet]", post2]];
>qq = ReadList[StringToStream[nodots], Expression];

I assume your intent here was to take variables such as
source.outputP and convert them into something Mathematica
accepts as a variable. If so, the code above doesn't do this and
is overly complex.

If you execute the code above then do

In[4]:= Head[qq[[1, 1]]]

Out[4]= Dot

you will see what you have created for source.outputP is not a
symbol (at least this is the result I get using Mathematica
version 7.0 on Mac OS 10.6.2). Since something with head Dot is
a dot product from Mathematica's perspective there is an obvious problem.

Similarly, after running your code to read the file containing
the variables

In[8]:= Head[First@qq1]

Out[8]= Dot

The file of equations can be read into Mathematica as equations
by doing the following:

In[9]:= eqns = ToExpression[StringReplace[#, "." -> "ZZ"]] & /@
    ReadList["C:\projet\variablesTP.txt", Record];

In[10]:= Head[eqns[[1, 1]]]

Out[10]= Symbol

similarly the file of variables can be read into Mathematica as
variables by doing:

In[11]:= vars = ToExpression[StringReplace[#, "." -> "ZZ"]] & /@
    ReadList["C:\projet\equationTP.txt", Record];

In[12]:= Head[First@vars]

Out[12]= Symbol

verifying both the list of equations and variables are as they
need to be for Mathematica.

Here, I've replaced all of the dots which cause a problem with
"ZZ". Since this particular string doesn't appear in any of your
variables, the end result could be converted back to a string
and the ZZ replaced with a "." restoring your naming scheme. But ...

Now after reading the files

In[13]:= Reduce[eqns, vars]

Out[13]= False

which means there is no solution to the equations as written.



  • Prev by Date: Function construction and also symmetric matrices
  • Next by Date: Re: Rule
  • Previous by thread: Function construction and also symmetric matrices
  • Next by thread: Re: solving equations