http://www.mathworks.com/matlabcentral/newsreader/view_thread/290393
MATLAB Central Newsreader  problem with solving symbolic equation
Feed for thread: problem with solving symbolic equation
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sat, 28 Aug 2010 05:46:12 +0000
problem with solving symbolic equation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/290393#775099
MICHAEL
i wanna find the cross points of 2 circles with center point and radius which changed each run.<br>
i define the following<br>
<br>
syms x y x_center y_center r<br>
eq=(xx_center)^2+(yy_center)^2r^2;<br>
x_center=X(1);<br>
y_center=Y(1);<br>
r=R(1);<br>
eq1=subs(eq);<br>
<br>
x_center=X(2);<br>
y_center=Y(2);<br>
r=R(2);<br>
eq2=subs(eq);<br>
<br>
and to solve i use <br>
<br>
[x12,y12]=solve(eq1,eq2); <br>
x12=eval(x12); y12=eval(y12);<br>
<br>
unfortunately, the run time unpredicteble  it can run very fast, very slow, in the middle and even stuck!!<br>
<br>
how to solve it so it will run normally?

Sat, 28 Aug 2010 07:01:24 +0000
Re: problem with solving symbolic equation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/290393#775107
Roger Stafford
"michael" <bezenchu@gmail.com> wrote in message <i5a7r4$ocl$1@fred.mathworks.com>...<br>
> i wanna find the cross points of 2 circles with center point and radius which changed each run.<br>
> i define the following<br>
> <br>
> syms x y x_center y_center r<br>
> eq=(xx_center)^2+(yy_center)^2r^2;<br>
> x_center=X(1);<br>
> y_center=Y(1);<br>
> r=R(1);<br>
> eq1=subs(eq);<br>
> <br>
> x_center=X(2);<br>
> y_center=Y(2);<br>
> r=R(2);<br>
> eq2=subs(eq);<br>
> <br>
> and to solve i use <br>
> <br>
> [x12,y12]=solve(eq1,eq2); <br>
> x12=eval(x12); y12=eval(y12);<br>
> <br>
> unfortunately, the run time unpredicteble  it can run very fast, very slow, in the middle and even stuck!!<br>
> <br>
> how to solve it so it will run normally?<br>
          <br>
To obtain single expressions for the two intersection points, as occurs when you use solve as you have, produces some rather complicated formulas. That complexity, together with the possibility that in some cases you might have no intersection points, may be responsible for your troubles. It is not efficient to force the symbolic toolbox to repeatedly solve the same messy equations over and over again with each new set of data.<br>
<br>
In my opinion it it much better to solve this problem in two steps. The first step is to find the single intersection point between the line connecting the two circle intersection points and the perpendicular line connecting the two centers. You can obtain the equation of the first of these two lines by subtracting the two circle equations.<br>
<br>
The next step is to use the Pythagoras theorem to move from this intersection point in either direction along the line which connects the two circle intersections by an amount which is compatible with the two given radii.<br>
<br>
This technique should allow you to put your computations in a reasonably simple form and give you a more reliable performance. Once you have developed the appropriate formulas, you won't need the services of solve any more.<br>
<br>
To make sure there are points of intersection of the circles you need to determine that the sum of the two radii is not less than the distance between the centers.<br>
<br>
Roger Stafford

Sat, 28 Aug 2010 07:26:06 +0000
Re: problem with solving symbolic equation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/290393#775116
Roger Stafford
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i5ac84$ppl$1@fred.mathworks.com>...<br>
> ..........<br>
> To make sure there are points of intersection of the circles you need to determine that the sum of the two radii is not less than the distance between the centers.<br>
> <br>
       <br>
Also add to that last paragraph the requirement that the distance between the centers should not be less than the absolute difference between the radii.<br>
<br>
Roger Stafford

Sat, 28 Aug 2010 23:33:04 +0000
Re: problem with solving symbolic equation
http://www.mathworks.com/matlabcentral/newsreader/view_thread/290393#775234
Roger Stafford
"michael" <bezenchu@gmail.com> wrote in message <i5a7r4$ocl$1@fred.mathworks.com>...<br>
> i wanna find the cross points of 2 circles with center point and radius which changed each run.<br>
> .........<br>
           <br>
I've decided to show you some matlab code that finds the two points of intersection of two circles. It should be more efficient and more easily understood than solutions generated automatically by 'solve'.<br>
<br>
Assume that you are given the centers (x1,y1) and (x2,y2) with radii r1 and r2, respectively. Then do this:<br>
<br>
dx = x2  x1; dy = y2  y1;<br>
sr = r2 + r1; dr = r2  r1;<br>
d2 = dx^2 + dy^2;<br>
t = (sr^2  d2) * (d2  dr^2);<br>
if t < 0, error('The circles do not intersect.'), end<br>
t = sqrt(t)/(2*d2);<br>
dx0 = dy * t; dy0 = dx * t;<br>
t = dr * sr / d2;<br>
x0 = (x1 + x2 + dx*t)/2;<br>
y0 = (y1 + y2 + dy*t)/2;<br>
x3 = x0 + dx0; y3 = y0 + dy0;<br>
x4 = x0  dx0; y4 = y0  dy0;<br>
<br>
The points (x3,y3) and (x4,y4) are the two intersections of the circles. As you move from center (x1,y1) to (x2,y2), the intersection (x3,y3) will be to the left and (x4,y4) to the right.<br>
<br>
If the 't' in the line<br>
<br>
t = (sr^2  d2) * (d2  dr^2);<br>
<br>
is negative, that means the circles don't intersect and you will have to figure out how you want to proceed. In such a case the above solutions will be complexvalued.<br>
<br>
Roger Stafford