Re: importing data from Excel to Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg85723] Re: importing data from Excel to Mathematica
- From: "Steve Luttrell" <steve at _removemefirst_luttrell.org.uk>
- Date: Wed, 20 Feb 2008 06:55:43 -0500 (EST)
- References: <fpe06j$ser$1@smc.vnet.net>
I assume you can import your equation string into Mathematica in the form
"x1 = A x2 + B y1\ny1 = C y2 - D x1" where \n is the newline character.
In[1]:= s="x1 = A x2 + B y1\ny1 = C y2 - D x1"
Out[1]= x1 = A x2 + B y1
y1 = C y2 - D x1
The aim now is to manipulate this into the correct form for an algebraic
expression that Mathematica can work with.
Split the above single string into two separate strings.
In[2]:= s2=StringSplit[s,"\n"]
Out[2]= {x1 = A x2 + B y1,y1 = C y2 - D x1}
Replace = (i.e. Set) with == (i.e. Equal) to make the strings have the
correct Mathematica syntax for equations.
In[3]:= s3=StringReplace[s2,"="->"=="]
Out[3]= {x1 == A x2 + B y1,y1 == C y2 - D x1}
Convert the strings to algebraic expressions that Mathematica can manipulate
symbolically.
In[4]:= e=ToExpression[s3]
Out[4]= {x1==A x2+B y1,y1==-D x1+C y2}
Solve the equations.
In[5]:= Solve[e,{x1,y1}]
Out[5]= {{x1->-((-A x2-B C y2)/(1+B D)),y1->-((A D x2-C y2)/(1+B D))}}
Stephen Luttrell
West Malvern. UK
"Tugrul Temel" <temelt at xs4all.nl> wrote in message
news:fpe06j$ser$1 at smc.vnet.net...
> Dear All,
>
> I have an Excel database with strings of equations in the following form:
>
> x1 = A x2 + B y1
> y1 = C y2 - D x1
>
> I like to import these equations to Mathematica and solve for x1 and y1:
>
> Which format is the best for importing?
>
> Thanks
>
> Tugrul
>
>
>
>
>
>