From: Maria Davis on 18 Mar 2010 05:33 Hi; 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: source.outputP.TP==upstream.sourceR.TP upstream.destR.TP==producer.inputP.TP producer.outputP.TP==channel.sourceR.TP channel.destR.TP==consumer.inputP.TP consumer.outputP.TP==downstream.sourceR.TP downstream.destR.TP==sink.inputP.TP downstream.sourceR.TP==Min[{downstream.destR.TP,downstream.TP}] upstream.sourceR.TP==Min[{upstream.destR.TP,upstream.TP}] channel.sourceR.TP==Min[{channel.destR.TP,channel.TP}] sink.inputP.TP==Infinity consumer.inputP.TP==Min[{consumer.outputP.TP,consumer.TP}] producer.inputP.TP==Min[{producer.outputP.TP,producer.TP}] downstream.TP==Infinity upstream.TP==Infinity I have used an other file containing the variables which must be eliminate this file "variables.txt" contains: downstream.sourceR.TP downstream.destR.TP upstream.sourceR.TP upstream.destR.TP channel.sourceR.TP channel.destR.TP sink.inputP.TP consumer.inputP.TP consumer.outputP.TP producer.inputP.TP producer.outputP.TP upstream.TP downstream.TP 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]; dots1 = ReadList["C:\projet\equationTP.txt", Record, RecordSeparators -> {}] nodots1 = StringReplace[dots1[[1]], StringExpression[pre : LetterCharacter, ".", post1 : LetterCharacter, ".", post2 : LetterCharacter] :> StringJoin[pre, "\[Bullet]", post1, "\[Bullet]", post2]]; qq1 = ReadList[StringToStream[nodots1], Expression]; Eliminate[qq1, qq] Reduce[%, source.outputP.TP] But I noticed that there is a problem in the expression form " Min[{a, b}] " which designates the minimum between a and b. Can you please help me. Thanks.
From: Sjoerd C. de Vries on 19 Mar 2010 03:37 Hi Maria, You've got several problems here. Your starting idea of eliminating the periods is right. No variablle names are allowed with them. However, your replacement pattern is not fully correct: 1) The LetterCharacter part should be repeated (..) and 2) some of the variables have only two parts and not three as you assume in the pattern. Even so, the replacement can be written much simpler as nodots1 = StringReplace[dots1[[1]], "." -> "\[Bullet]"] and the conversion can be written easier using ToExpression. In all I would write: dots = ReadList[ "C:\\projet\\variablesTP.txt", Record, RecordSeparators -> {"\n"}]; nodots = StringReplace[#, "." -> "\[Bullet]"] & /@ dots; qq = ToExpression /@ nodots dots1 = ReadList[ "C:\\projet\\equationTP.txt", Record, RecordSeparators -> {"\n"}]; nodots1 = StringReplace[#, "." -> "\[Bullet]"] & /@ dots1; qq1 = ToExpression /@ nodots1 Note the RecordSeparators -> {"\n"} part. This yields me an array of strings on which I map the StringReplacement and the ToExpression. Note also that I changed the backslashes in the file path to a double backslash. The single backslash is treated as an escape code and it needs to escaped itself by preceeding it with an additional backslash. Your equations and following Eliminate don't make much sense to me. The Min of two unspecified variables cannot be reduced. Adding that one of them equals Infinity doesn't help. The other might be the same. Cheers -- Sjoerd On Mar 18, 11:33 am, Maria Davis <arbi...(a)gmail.com> wrote: > Hi; > > 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: > > source.outputP.TP==upstream.sourceR.TP > upstream.destR.TP==producer.inputP.TP > producer.outputP.TP==channel.sourceR.TP > channel.destR.TP==consumer.inputP.TP > consumer.outputP.TP==downstream.sourceR.TP > downstream.destR.TP==sink.inputP.TP > downstream.sourceR.TP==Min[{downstream.destR.TP,downstream.TP}] > upstream.sourceR.TP==Min[{upstream.destR.TP,upstream.TP}] > channel.sourceR.TP==Min[{channel.destR.TP,channel.TP}] > sink.inputP.TP==Infinity > consumer.inputP.TP==Min[{consumer.outputP.TP,consumer.TP}] > producer.inputP.TP==Min[{producer.outputP.TP,producer.TP}] > downstream.TP==Infinity > upstream.TP==Infinity > > I have used an other file containing the variables which must be > eliminate > this file "variables.txt" contains: > > downstream.sourceR.TP > downstream.destR.TP > upstream.sourceR.TP > upstream.destR.TP > channel.sourceR.TP > channel.destR.TP > sink.inputP.TP > consumer.inputP.TP > consumer.outputP.TP > producer.inputP.TP > producer.outputP.TP > upstream.TP > downstream.TP > > 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]; > > dots1 = ReadList["C:\projet\equationTP.txt", Record, > RecordSeparators -> {}] > nodots1 = > StringReplace[dots1[[1]], > StringExpression[pre : LetterCharacter, ".", > post1 : LetterCharacter, ".", post2 : LetterCharacter] :> > StringJoin[pre, "\[Bullet]", post1, "\[Bullet]", post2]]; > qq1 = ReadList[StringToStream[nodots1], Expression]; > > Eliminate[qq1, qq] > Reduce[%, source.outputP.TP] > > But I noticed that there is a problem in the expression form " > Min[{a, b}] " which designates > the minimum between a and b. > > Can you please help me. > Thanks.
From: Bill Rowe on 19 Mar 2010 03:38 On 3/18/10 at 4:33 AM, arbiadr(a)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(a)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(a)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.
From: Maria Davis on 22 Mar 2010 03:41 > Now after reading the files > > In[13]:= Reduce[eqns, vars] > > Out[13]= False > > which means there is no solution to the equations as written. Thank you very much for your help, the solution you have proposed is correct; But instead of using Reduce[eqns, vars], we have better use: Reduce[Eliminate[eqns, vars] , sourceZZoutputPZZTP] However, the code proposed gives the appropriate values if I omit equations containing Min and the term infinity .For example, if we replace the equations: downstream.sourceR.TP==Min(downstream.destR.TP,downstream.TP) downstream.TP==infinity by: downstream.sourceR.TP==downstream.destR.TP+downstream.TP downstream.TP==0 The proposed code gives the correct result. But I have to solve such expressions(containing Min anf infinity) by mathematica. Please can you help me. How can I change the source file for expressing the minimum of two variables, and the value "infinity"? Thank you in advance.
From: Maria Davis on 22 Mar 2010 03:46 > The Min of two unspecified variables cannot be reduced. Adding that > one of them equals Infinity doesn't help. The other might be the same. Hi Sjoerd; Thank you for your help. The equations presented in the file are the result of another software, I know that they contain much redunduncy, but I must resolve them. For example, the given equations are: a=Min(c, d) c=infinity I want mathematica to solve the system above and returns a=d I don't understand why "Min" can not be reduced, so, please, is there any solution? I have also noticed that the term infinity is not understood as a value but as a string. Please I need your help. Thank you.
|
Next
|
Last
Pages: 1 2 Prev: Possible bug: Integrate[(u - t)*BesselY[0, 2*t], {t, 0, u}] Next: Sorting nested lists |