Re: Solving on mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg88521] Re: Solving on mathematica
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 7 May 2008 07:08:47 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <fvpctc$mkh$1@smc.vnet.net>
Chris wrote: > How would i go about solving this equaiton on mathematica > > (Xi -Ux)^2 + (Yi - Uy)^2 + (Zi - Uz) = (Ri - Cb) > i = 1,2,3,4 > > where we need to find Ux, Uy, Uz, Cb tried a few things and they dont work. > > NSolve[ (Xi - U)^2 + (Yi - V)^2 + (Zi - W)^2 == (Ri - B)^2, {U, V, W, > B}, { i = 1, 2, 3, 4} ] > > any ideas? Below, we assume that the Xi, Yi, etc., are some kind of indexed variables or arrays that hold some values. (* First, we generate some random data. *) Do[{X[i], Y[i], Z[i], R[i]} = RandomInteger[{-5, 5}, 4], {i, 4}] (* Then, we build the system of equations. *) eqns = Table[(X[i] - U)^2 + (Y[i] - V)^2 + (Z[i] - W)^2 == (R[i] - B)^2, {i, 1, 4}] (* Now we solve it. *) sols = NSolve[eqns, {U, V, W, B}] (* Finally, we check the results. *) eqns /. sols Out[139]= {(3 - U)^2 + (2 - V)^2 + (-3 - W)^2 == (-4 - B)^2, (5 - U)^2 + (1 - V)^2 + (-5 - W)^2 == (-2 - B)^2, (5 - U)^2 + (5 - V)^2 + (4 - W)^2 == (-3 - B)^2, (4 - U)^2 + (-2 - V)^2 + (1 - W)^2 == (-3 - B)^2} Out[140]= {{U -> 41.8099, V -> -1.64395, W -> -2.60076, B -> 34.9827}, {U -> 4.23504, V -> 2.48516, W -> 0.289612, B -> -7.54715}} Out[141]= {{True, True, True, True}, {True, True, True, True}} Regards, -- Jean-Marc