Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: MATLAB PROBLEM
Date: Tue, 7 Sep 2010 17:44:23 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 42
Message-ID: <i65tln$sek$1@fred.mathworks.com>
References: <i602m1$3v$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1283881463 29140 172.30.248.38 (7 Sep 2010 17:44:23 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 7 Sep 2010 17:44:23 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:668256

"Mamon " <mamoon_hatmal@yahoo.com> wrote in message <i602m1$3v$1@fred.mathworks.com>...
> Hi ALL ; 
> I'm a PhD student at USC, I'm trying to use matlab to solve a group of equations ( I want to find the values of x(1),x(2),x(3),x(4),x(5),and x(6)), I'm trying to use fsolve in *.m file because I need the results to be written directly for output file, could you please help me in that, the code that I use is between the two lines (but it always gives me an error):
> ........
> also I have a question about how can we get all the solutions for the above equations, because fsolve now gives just one solution, and I wonder if there is a method to produce all the solutions or if we can change the initial guess by using " for loop".
> 
> any help is appreciated,
> Thank you,
> Ma'mon hatmal
- - - - - - -
  Ma'mon, it pains me to think of you using fsolve in the manner you have explained and on such an elementary problem.  The following is a direct way of using matlab to compute the two intersections (if any) of three spheres.

  Let C1, C2, and C3 be three-element coordinate vectors of the spheres' centers and let r1, r2, and r3 be their respective radii.  Then do this:

% Define three random spheres and radii
C1 = randn(1,3); C2 = randn(1,3); C3 = randn(1,3);
r1 = 2+rand; r2 = 2+rand; r3 = 2+rand;

% Find their intersection points
U = C2-C1;
V = C3-C1;
W = cross(U,V);
w2 = dot(W,W);
P = ((r1^2-r2^2+dot(U,U))*cross(V,W)-(r1^2-r3^2+dot(V,V))*cross(U,W))/(2*w2);
h2 = r1^2-dot(P,P);
if h2 >= 0
 Q = sqrt(h2)*W/sqrt(w2);
 I1 = C1+P+Q;
 I2 = C1+P-Q;
else
 fprintf('The spheres don''t intersect.\n')'
end

% Test
[norm(I1-C1)-r1,norm(I1-C2)-r2,norm(I1-C3)-r3;
 norm(I2-C1)-r1,norm(I2-C2)-r2,norm(I2-C3)-r3]

The points I1 and I2 are the two points of intersection.

  Note: The point C1+P above is the point I previously mentioned "where the line connecting the two solutions passes through the plane of the three centers."  Q and -Q are vectors pointing from C1+P in opposite directions along the line orthogonal to the centers' plane by the appropriate distance.

Roger Stafford