MathGroup Archive 2002

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

Search the Archive

RE: solving vector equations in mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34379] RE: [mg34356] solving vector equations in mathematica
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 17 May 2002 06:31:07 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hal,

I would say, from the general tenor of your question, that you might save
some time in the long run if you worked through as much of Part I of The
Mathematica Book as seems relevant. It is difficult to attack specific
problems without a knowledge of how Mathematica represents various objects.

When you take a Part of an expression, such as w[[3]] say, then w must be a
expression that has a 3'rd part. That means you have to make an assignment
for w. So you could write:

w = {w1, w2, w3, w4, w5};
eqn = Sum[w[[i]], {i, 1, 5}] == 0;
sol = Solve[eqn, w[[2]]]
{{w2 -> -w1 - w3 - w4 - w5}}

This is the standard form of output when Mathematica solves equations. It is
a replacement rule, which says that w2 is replaced by the right hand side.
It is in brackets because you might be solving for more than one variable,
and there might be multiple solutions. The rule is better than an equation
because you can use it to make substitutions in expressions. For example,
you can check the solution in the equation.

eqn /. sol
{True}

Another, and maybe better, method might be not to use Parts. Just use w[i].

Clear[w];
Solve[Sum[w[i], {i, 1, 5}] == 0, w[2]]
{{w[2] -> -w[1] - w[3] - w[4] - w[5]}}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/





> -----Original Message-----
> From: Hal Daume III [mailto:hdaume at isi.edu]
To: mathgroup at smc.vnet.net
> Sent: Thursday, May 16, 2002 5:09 AM
> Subject: [mg34379] [mg34356] solving vector equations in mathematica
>
>
> Hi All,
>
> I'm somewhat new to mathematica, at least in the world of vectors, and
> I'm having trouble getting it to solve an equation for me.
>
> I basically want to solve:
>
> \sum_{i=1}^n x_i = 0
>
> for x_k
>
> I tried:
>
> Solve[Sum[x[[i]],{i,1,5}] == 0, x[[2]]]
>
> as an example, but mathematica complains:
>
> In[118]:= Solve[Sum[w[[i]],{i=1,5}] == 0, w[[1]]]
>
> Sum::write: Tag Set in i = 1 is Protected.
>
> Part::partd: Part specification w[[1]] is longer than depth of object.
>
> Part::partd: Part specification w[[1]] is longer than depth of object.
>
> Part::partd: Part specification w[[1]] is longer than depth of object.
>
> General::stop: Further output of Part::partd
>      will be suppressed during this calculation.
>
> Out[118]= {{w[[1]] -> 0}}
>
> I'm not exactly sure what this means.
>
> I could write it out:
>
> In[119]:= Solve[w1+w2+w3+w4+w5==0, w1]
>
> Out[119]= {{w1 -> -w2 - w3 - w4 - w5}}
>
> But this isn't very helpful in my situation (my equations are huge*), and
> doesn't reflect the vector quality of the situation.
>
> If such a thing is possible, I'd appreciate some pointers (I read the
> mathematica docs on the wolfram site, but couldn't find anything talking
> about this).
>
> Thanks!
>
>  - Hal
>
> * the equation i'm working with is something like:
>
> sum_{C,x,y,y'} (wx . wy) (wx . wy') (|wx * wy'| (wx . wy) - |wx * wy| (wx
> . wy')) / (|wx|^4 |wy|^2 |wy'|^2) == 0
>
> where
>
>   .   is dot product
>   *   is cross product
>   |x| is magnitude of x
> and
>   for vectors w=<w1,w2,...,wn>, x=<x1,x2,...,xn>,
>   wx = <w1*x1,w2*x2,...,wn*xn>
>
> Thanks again.
>
> --
> Hal Daume III
>
>  "Computer science is no more about computers    | hdaume at isi.edu
>   than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
>
>



  • Prev by Date: RE: Geometry- transformations
  • Next by Date: Re: Assigning to superscripted variables
  • Previous by thread: Re: solving vector equations in mathematica
  • Next by thread: Plot Random Walk!