<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/214708</link>
    <title>MATLAB Central Newsreader - Solving equations</title>
    <description>Feed for thread: Solving equations</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 19 Aug 2008 06:28:02 -0400</pubDate>
      <title>Re: Solving equations</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/214708#596261</link>
      <author>Miroslav Balda</author>
      <description>&quot;Mazahir &quot; &amp;lt;maz_p5@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g8bugl$e7c$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am finding out the location of a sound source using&lt;br&gt;
&amp;gt; microphones. The co-ordinates of the 3 mics are fixed.&lt;br&gt;
&amp;gt; Suppose  the co-ordinates of the 3 mics are (x1,y1),(x2,y2)&lt;br&gt;
&amp;gt; and (x3,y3) and the distance of source of sound from the 1st&lt;br&gt;
&amp;gt; mic to the 2nnd is - del12 and the source of sound from the&lt;br&gt;
&amp;gt; 1st mic to the 3rd is del13. how do i find the location of&lt;br&gt;
&amp;gt; the source (x,y) in MATLAB using the following formula.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; del12=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x2-x)^2+(y2-y)^2)&lt;br&gt;
&amp;gt; del13=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Solving this equation of 2 unknowns simultaneously will give&lt;br&gt;
&amp;gt; me the point (x,y). But i do not know how to do it in&lt;br&gt;
&amp;gt; matlab. I think there is a solution using matrices. Please&lt;br&gt;
&amp;gt; help. thank you. &lt;br&gt;
&lt;br&gt;
Hi,&lt;br&gt;
&lt;br&gt;
Mazahir, your problem is more complicated, because there is&lt;br&gt;
one equation more:&lt;br&gt;
del23=sqrt((x2-x)^2+(y2-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
Since your measured dels suffer from measurement error, the&lt;br&gt;
three equations are overdetermined for two unknowns [x,y].&lt;br&gt;
It is a problem which can be solved by a least squares&lt;br&gt;
method. there is the code for simulated problem:&lt;br&gt;
&lt;br&gt;
x = [14,95,72];&lt;br&gt;
y = [30,18,73];&lt;br&gt;
xy = [x;y];&lt;br&gt;
dxy = [59,27,39]; %  approximate distances from corners&lt;br&gt;
d = [dxy(1)-dxy(2),dxy(2)-dxy(3),dxy(3)-dxy(1)]; % deltas&lt;br&gt;
del = @(a,b) sqrt((a-b)'*(a-b));&lt;br&gt;
res = @(z) [del(xy(:,1),z)-del(xy(:,2),z) - d(1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;del(xy(:,2),z)-del(xy(:,3),z) - d(2)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;del(xy(:,3),z)-del(xy(:,1),z) - d(3)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;];&lt;br&gt;
[XY,ssq,cnt] = LMFnlsq(res,sum(xy')'/3,'Display',1)&lt;br&gt;
&lt;br&gt;
with the solution:&lt;br&gt;
&lt;br&gt;
XY =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;73.0034&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;33.8819&lt;br&gt;
ssq =&lt;br&gt;
&amp;nbsp;&amp;nbsp;4.6659e-024&lt;br&gt;
cnt =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;br&gt;
&lt;br&gt;
The solution is very good, because sum of squares from the&lt;br&gt;
staring point, chosen in the centre of gravity ofthe&lt;br&gt;
triangle, has been ssq=1e3 (!). The function LMFnlsq is from&lt;br&gt;
File Exchange under Id 17534.&lt;br&gt;
&lt;br&gt;
Hope it helps.&lt;br&gt;
&lt;br&gt;
Mira</description>
    </item>
    <item>
      <pubDate>Wed, 20 Aug 2008 18:25:04 -0400</pubDate>
      <title>Re: Solving equations</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/214708#596635</link>
      <author>Mazahir </author>
      <description>&quot;Miroslav Balda&quot; &amp;lt;balda.nospam@cdm.it.cas.cz&amp;gt; wrote in&lt;br&gt;
message &amp;lt;g8dp5i$509$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Mazahir &quot; &amp;lt;maz_p5@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;g8bugl$e7c$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hello,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I am finding out the location of a sound source using&lt;br&gt;
&amp;gt; &amp;gt; microphones. The co-ordinates of the 3 mics are fixed.&lt;br&gt;
&amp;gt; &amp;gt; Suppose  the co-ordinates of the 3 mics are (x1,y1),(x2,y2)&lt;br&gt;
&amp;gt; &amp;gt; and (x3,y3) and the distance of source of sound from the 1st&lt;br&gt;
&amp;gt; &amp;gt; mic to the 2nnd is - del12 and the source of sound from the&lt;br&gt;
&amp;gt; &amp;gt; 1st mic to the 3rd is del13. how do i find the location of&lt;br&gt;
&amp;gt; &amp;gt; the source (x,y) in MATLAB using the following formula.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; del12=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x2-x)^2+(y2-y)^2)&lt;br&gt;
&amp;gt; &amp;gt; del13=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Solving this equation of 2 unknowns simultaneously will give&lt;br&gt;
&amp;gt; &amp;gt; me the point (x,y). But i do not know how to do it in&lt;br&gt;
&amp;gt; &amp;gt; matlab. I think there is a solution using matrices. Please&lt;br&gt;
&amp;gt; &amp;gt; help. thank you. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Mazahir, your problem is more complicated, because there is&lt;br&gt;
&amp;gt; one equation more:&lt;br&gt;
&amp;gt; del23=sqrt((x2-x)^2+(y2-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
&amp;gt; Since your measured dels suffer from measurement error, the&lt;br&gt;
&amp;gt; three equations are overdetermined for two unknowns [x,y].&lt;br&gt;
&amp;gt; It is a problem which can be solved by a least squares&lt;br&gt;
&amp;gt; method. there is the code for simulated problem:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x = [14,95,72];&lt;br&gt;
&amp;gt; y = [30,18,73];&lt;br&gt;
&amp;gt; xy = [x;y];&lt;br&gt;
&amp;gt; dxy = [59,27,39]; %  approximate distances from corners&lt;br&gt;
&amp;gt; d = [dxy(1)-dxy(2),dxy(2)-dxy(3),dxy(3)-dxy(1)]; % deltas&lt;br&gt;
&amp;gt; del = @(a,b) sqrt((a-b)'*(a-b));&lt;br&gt;
&amp;gt; res = @(z) [del(xy(:,1),z)-del(xy(:,2),z) - d(1)&lt;br&gt;
&amp;gt;             del(xy(:,2),z)-del(xy(:,3),z) - d(2)&lt;br&gt;
&amp;gt;             del(xy(:,3),z)-del(xy(:,1),z) - d(3)&lt;br&gt;
&amp;gt;            ];&lt;br&gt;
&amp;gt; [XY,ssq,cnt] = LMFnlsq(res,sum(xy')'/3,'Display',1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; with the solution:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; XY =&lt;br&gt;
&amp;gt;    73.0034&lt;br&gt;
&amp;gt;    33.8819&lt;br&gt;
&amp;gt; ssq =&lt;br&gt;
&amp;gt;   4.6659e-024&lt;br&gt;
&amp;gt; cnt =&lt;br&gt;
&amp;gt;      4&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The solution is very good, because sum of squares from the&lt;br&gt;
&amp;gt; staring point, chosen in the centre of gravity ofthe&lt;br&gt;
&amp;gt; triangle, has been ssq=1e3 (!). The function LMFnlsq is from&lt;br&gt;
&amp;gt; File Exchange under Id 17534.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hope it helps.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Mira&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hi Mira,&lt;br&gt;
&lt;br&gt;
Sorry but I could not understand your solution well. I know&lt;br&gt;
that solving by least square method might be the best option&lt;br&gt;
but can you please describe the solution and the variables&lt;br&gt;
used like d,a,b,z, res, etc.. dxy is the approx. distance&lt;br&gt;
from corners, but distance of what? Also are the values&lt;br&gt;
randomly taken by you?&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Also below I am explaining you the problem again in detail,&lt;br&gt;
so that you can get a clear picture.&lt;br&gt;
&lt;br&gt;
I have to find the location of a sound source on a 2d plane.&lt;br&gt;
(I am not considering z axis). I have 4 mics the&lt;br&gt;
co-ordinates of which are m1(0,0), m2(0,6), m3(4,6), m4(4,0). &lt;br&gt;
del12 is the difference between the distance from mic 1 to&lt;br&gt;
the source and from mic 2 to the source. &lt;br&gt;
del12=((time taken to reach 1st mic-time taken to reach 2nd&lt;br&gt;
mic) x v sound i.e. 340m/s)/fs i.e. 44000. Therefore, for a&lt;br&gt;
particular set of readings, the calculated del12 = 0.0848.&lt;br&gt;
Similarly, del13 = 0.9098 and del14 = 0.5937&lt;br&gt;
&lt;br&gt;
Now solving the equations below simultaneously using least&lt;br&gt;
square method will give me the point. &lt;br&gt;
&lt;br&gt;
del12=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x2-x)^2+(y2-y)^2)&lt;br&gt;
del13=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
del14=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x4-x)^2+(y4-y)^2)&lt;br&gt;
&lt;br&gt;
Now this is the exact problem which I cant get hang of. &lt;br&gt;
&lt;br&gt;
I think 1st solving with just 3 mics and 2 equations will be&lt;br&gt;
good enough to predict the output before going to the 4th mic. &lt;br&gt;
&lt;br&gt;
Also what I know is that such systems can also be solved by&lt;br&gt;
techniques such as multilateration. If yes, would that be&lt;br&gt;
easier?&lt;br&gt;
&lt;br&gt;
Please do reply soon.&lt;br&gt;
&lt;br&gt;
Thank you,&lt;br&gt;
Mazahir </description>
    </item>
    <item>
      <pubDate>Wed, 20 Aug 2008 20:49:01 -0400</pubDate>
      <title>Re: Solving equations</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/214708#596665</link>
      <author>Miroslav Balda</author>
      <description>&quot;Mazahir &quot; &amp;lt;maz_p5@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g8hni0$klf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
:&lt;br&gt;
SNIP&lt;br&gt;
:&lt;br&gt;
&amp;gt; Hi Mira,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Sorry but I could not understand your solution well. I know&lt;br&gt;
&amp;gt; that solving by least square method might be the best option&lt;br&gt;
&amp;gt; but can you please describe the solution and the variables&lt;br&gt;
&amp;gt; used like d,a,b,z, res, etc.. dxy is the approx. distance&lt;br&gt;
&amp;gt; from corners, but distance of what? Also are the values&lt;br&gt;
&amp;gt; randomly taken by you?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Also below I am explaining you the problem again in detail,&lt;br&gt;
&amp;gt; so that you can get a clear picture.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have to find the location of a sound source on a 2d plane.&lt;br&gt;
&amp;gt; (I am not considering z axis). I have 4 mics the&lt;br&gt;
&amp;gt; co-ordinates of which are m1(0,0), m2(0,6), m3(4,6), m4(4,0). &lt;br&gt;
&amp;gt; del12 is the difference between the distance from mic 1 to&lt;br&gt;
&amp;gt; the source and from mic 2 to the source. &lt;br&gt;
&amp;gt; del12=((time taken to reach 1st mic-time taken to reach 2nd&lt;br&gt;
&amp;gt; mic) x v sound i.e. 340m/s)/fs i.e. 44000. Therefore, for a&lt;br&gt;
&amp;gt; particular set of readings, the calculated del12 = 0.0848.&lt;br&gt;
&amp;gt; Similarly, del13 = 0.9098 and del14 = 0.5937&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Now solving the equations below simultaneously using least&lt;br&gt;
&amp;gt; square method will give me the point. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; del12=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x2-x)^2+(y2-y)^2)&lt;br&gt;
&amp;gt; del13=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
&amp;gt; del14=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x4-x)^2+(y4-y)^2)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Now this is the exact problem which I cant get hang of. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I think 1st solving with just 3 mics and 2 equations will be&lt;br&gt;
&amp;gt; good enough to predict the output before going to the 4th&lt;br&gt;
mic. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Also what I know is that such systems can also be solved by&lt;br&gt;
&amp;gt; techniques such as multilateration. If yes, would that be&lt;br&gt;
&amp;gt; easier?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Please do reply soon.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you,&lt;br&gt;
&amp;gt; Mazahir &lt;br&gt;
&lt;br&gt;
Hi Mazahir,&lt;br&gt;
&lt;br&gt;
Since that you have changed your descriptiom of the problem,&lt;br&gt;
I will not return to the previous example, which was set by&lt;br&gt;
my by random distances, which I chose. The solution of your&lt;br&gt;
problem is as follows:&lt;br&gt;
&lt;br&gt;
x  = [0,0,4,4];&lt;br&gt;
y  = [0,6,6,0];&lt;br&gt;
xy = [x;y];&lt;br&gt;
dij = [0.0848,0.99098,0.5937];&lt;br&gt;
&lt;br&gt;
del = @(d) sqrt(d'*d);&lt;br&gt;
res = @(z) [del(xy(:,1)-z) - del(xy(:,2)-z) - dij(1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;del(xy(:,1)-z) - del(xy(:,3)-z) - dij(2)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;del(xy(:,1)-z) - del(xy(:,4)-z) - dij(3)];&lt;br&gt;
&lt;br&gt;
[XY,ssq,cnt] = LMFnlsq(res,[2;3],'display',1)&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; test080820&lt;br&gt;
***************************************************************************&lt;br&gt;
&amp;nbsp;&amp;nbsp;itr  nfJ   SUM(r^2)        x           dx           l    &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lc&lt;br&gt;
***************************************************************************&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;0    1  1.3417e+000  2.0000e+000  0.0000e+000           &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.0000e+000  0.0000e+000 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;1    2  2.6097e-002  2.6290e+000 -6.2904e-001 &lt;br&gt;
0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.1136e+000 -1.1355e-001 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;2    3  2.4987e-002  2.6390e+000 -9.9365e-003 &lt;br&gt;
0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.1240e+000 -1.0411e-002 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;3    4  2.4987e-002  2.6392e+000 -1.9470e-004 &lt;br&gt;
0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.1240e+000 -3.6993e-005 &lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;4    5  2.4987e-002  2.6392e+000  6.9462e-007 &lt;br&gt;
0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.1240e+000 -1.9698e-006 &lt;br&gt;
XY =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2.6392&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.1240&lt;br&gt;
ssq =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0250&lt;br&gt;
cnt =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;br&gt;
&lt;br&gt;
* xy  are coordinates of microphones,&lt;br&gt;
* dij are your calculated differences,&lt;br&gt;
* del is the handle of anonymous function for calculation of&lt;br&gt;
yours sqrt((x1-x)^2 + ....),&lt;br&gt;
* res is the handle to anonymous function that declares&lt;br&gt;
residuals (errors of your equations)&lt;br&gt;
* XY are coordinates of the sound source,&lt;br&gt;
* ssq is a sum of squares of residuals,&lt;br&gt;
* cnt number of calls to res and Jacobian matrix.&lt;br&gt;
&lt;br&gt;
You see that ssq is only by approx. 10^2 lower then for the&lt;br&gt;
initial guess. It means that yours delijs are inexact.&lt;br&gt;
Better way would be in taking times of wave approach to&lt;br&gt;
microphones. More over having reading from 4 microphones&lt;br&gt;
could set 6 equations -&amp;gt; residuals and by least squares get&lt;br&gt;
much more accurate coordinates of the source.&lt;br&gt;
&lt;br&gt;
I think, that it is all what to say to it.&lt;br&gt;
Hope it helps.&lt;br&gt;
&lt;br&gt;
Mira&lt;br&gt;
&lt;br&gt;
PS: The time shift makes the communication difficult. Now is&lt;br&gt;
almost 23 o'clock at Pilsen (CZ).</description>
    </item>
    <item>
      <pubDate>Sun, 24 Aug 2008 19:37:02 -0400</pubDate>
      <title>Re: Solving equations</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/214708#597081</link>
      <author>Mazahir </author>
      <description>&quot;Miroslav Balda&quot; &amp;lt;miroslav.nospam@balda.cz&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g8hvvt$r50$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Mazahir &quot; &amp;lt;maz_p5@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;g8hni0$klf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; :&lt;br&gt;
&amp;gt; SNIP&lt;br&gt;
&amp;gt; :&lt;br&gt;
&amp;gt; &amp;gt; Hi Mira,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Sorry but I could not understand your solution well. I know&lt;br&gt;
&amp;gt; &amp;gt; that solving by least square method might be the best option&lt;br&gt;
&amp;gt; &amp;gt; but can you please describe the solution and the variables&lt;br&gt;
&amp;gt; &amp;gt; used like d,a,b,z, res, etc.. dxy is the approx. distance&lt;br&gt;
&amp;gt; &amp;gt; from corners, but distance of what? Also are the values&lt;br&gt;
&amp;gt; &amp;gt; randomly taken by you?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Also below I am explaining you the problem again in detail,&lt;br&gt;
&amp;gt; &amp;gt; so that you can get a clear picture.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I have to find the location of a sound source on a 2d plane.&lt;br&gt;
&amp;gt; &amp;gt; (I am not considering z axis). I have 4 mics the&lt;br&gt;
&amp;gt; &amp;gt; co-ordinates of which are m1(0,0), m2(0,6), m3(4,6),&lt;br&gt;
m4(4,0). &lt;br&gt;
&amp;gt; &amp;gt; del12 is the difference between the distance from mic 1 to&lt;br&gt;
&amp;gt; &amp;gt; the source and from mic 2 to the source. &lt;br&gt;
&amp;gt; &amp;gt; del12=((time taken to reach 1st mic-time taken to reach 2nd&lt;br&gt;
&amp;gt; &amp;gt; mic) x v sound i.e. 340m/s)/fs i.e. 44000. Therefore, for a&lt;br&gt;
&amp;gt; &amp;gt; particular set of readings, the calculated del12 = 0.0848.&lt;br&gt;
&amp;gt; &amp;gt; Similarly, del13 = 0.9098 and del14 = 0.5937&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Now solving the equations below simultaneously using least&lt;br&gt;
&amp;gt; &amp;gt; square method will give me the point. &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; del12=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x2-x)^2+(y2-y)^2)&lt;br&gt;
&amp;gt; &amp;gt; del13=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
&amp;gt; &amp;gt; del14=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x4-x)^2+(y4-y)^2)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Now this is the exact problem which I cant get hang of. &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I think 1st solving with just 3 mics and 2 equations will be&lt;br&gt;
&amp;gt; &amp;gt; good enough to predict the output before going to the 4th&lt;br&gt;
&amp;gt; mic. &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Also what I know is that such systems can also be solved by&lt;br&gt;
&amp;gt; &amp;gt; techniques such as multilateration. If yes, would that be&lt;br&gt;
&amp;gt; &amp;gt; easier?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Please do reply soon.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thank you,&lt;br&gt;
&amp;gt; &amp;gt; Mazahir &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hi Mazahir,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Since that you have changed your descriptiom of the problem,&lt;br&gt;
&amp;gt; I will not return to the previous example, which was set by&lt;br&gt;
&amp;gt; my by random distances, which I chose. The solution of your&lt;br&gt;
&amp;gt; problem is as follows:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x  = [0,0,4,4];&lt;br&gt;
&amp;gt; y  = [0,6,6,0];&lt;br&gt;
&amp;gt; xy = [x;y];&lt;br&gt;
&amp;gt; dij = [0.0848,0.99098,0.5937];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; del = @(d) sqrt(d'*d);&lt;br&gt;
&amp;gt; res = @(z) [del(xy(:,1)-z) - del(xy(:,2)-z) - dij(1)&lt;br&gt;
&amp;gt;             del(xy(:,1)-z) - del(xy(:,3)-z) - dij(2)&lt;br&gt;
&amp;gt;             del(xy(:,1)-z) - del(xy(:,4)-z) - dij(3)];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [XY,ssq,cnt] = LMFnlsq(res,[2;3],'display',1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; test080820&lt;br&gt;
&amp;gt;&lt;br&gt;
***************************************************************************&lt;br&gt;
&amp;gt;   itr  nfJ   SUM(r^2)        x           dx           l    &lt;br&gt;
&amp;gt;       lc&lt;br&gt;
&amp;gt;&lt;br&gt;
***************************************************************************&lt;br&gt;
&amp;gt;    0    1  1.3417e+000  2.0000e+000  0.0000e+000           &lt;br&gt;
&amp;gt;                                                          &lt;br&gt;
&amp;gt; 0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;gt;                         3.0000e+000  0.0000e+000 &lt;br&gt;
&amp;gt;    1    2  2.6097e-002  2.6290e+000 -6.2904e-001 &lt;br&gt;
&amp;gt; 0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;gt;                         3.1136e+000 -1.1355e-001 &lt;br&gt;
&amp;gt;    2    3  2.4987e-002  2.6390e+000 -9.9365e-003 &lt;br&gt;
&amp;gt; 0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;gt;                         3.1240e+000 -1.0411e-002 &lt;br&gt;
&amp;gt;    3    4  2.4987e-002  2.6392e+000 -1.9470e-004 &lt;br&gt;
&amp;gt; 0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;gt;                         3.1240e+000 -3.6993e-005 &lt;br&gt;
&amp;gt;  &lt;br&gt;
&amp;gt;    4    5  2.4987e-002  2.6392e+000  6.9462e-007 &lt;br&gt;
&amp;gt; 0.0000e+000  1.0000e+000 &lt;br&gt;
&amp;gt;                         3.1240e+000 -1.9698e-006 &lt;br&gt;
&amp;gt; XY =&lt;br&gt;
&amp;gt;     2.6392&lt;br&gt;
&amp;gt;     3.1240&lt;br&gt;
&amp;gt; ssq =&lt;br&gt;
&amp;gt;     0.0250&lt;br&gt;
&amp;gt; cnt =&lt;br&gt;
&amp;gt;      4&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; * xy  are coordinates of microphones,&lt;br&gt;
&amp;gt; * dij are your calculated differences,&lt;br&gt;
&amp;gt; * del is the handle of anonymous function for calculation of&lt;br&gt;
&amp;gt; yours sqrt((x1-x)^2 + ....),&lt;br&gt;
&amp;gt; * res is the handle to anonymous function that declares&lt;br&gt;
&amp;gt; residuals (errors of your equations)&lt;br&gt;
&amp;gt; * XY are coordinates of the sound source,&lt;br&gt;
&amp;gt; * ssq is a sum of squares of residuals,&lt;br&gt;
&amp;gt; * cnt number of calls to res and Jacobian matrix.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You see that ssq is only by approx. 10^2 lower then for the&lt;br&gt;
&amp;gt; initial guess. It means that yours delijs are inexact.&lt;br&gt;
&amp;gt; Better way would be in taking times of wave approach to&lt;br&gt;
&amp;gt; microphones. More over having reading from 4 microphones&lt;br&gt;
&amp;gt; could set 6 equations -&amp;gt; residuals and by least squares get&lt;br&gt;
&amp;gt; much more accurate coordinates of the source.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I think, that it is all what to say to it.&lt;br&gt;
&amp;gt; Hope it helps.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Mira&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; PS: The time shift makes the communication difficult. Now is&lt;br&gt;
&amp;gt; almost 23 o'clock at Pilsen (CZ).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
Hi Mira,&lt;br&gt;
&lt;br&gt;
You are right. there is something wrong with my time delays&lt;br&gt;
because the point at which i captured the sound is (1,2) and&lt;br&gt;
the ans = (2,3). &lt;br&gt;
Secondly, as the formulas are :&lt;br&gt;
del12=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x2-x)^2+(y2-y)^2)&lt;br&gt;
del13=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
del14=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x4-x)^2+(y4-y)^2)&lt;br&gt;
&lt;br&gt;
instead of this complicated method, can i make use of least&lt;br&gt;
square method using matrices and the least square formula to&lt;br&gt;
calculate the location: &lt;br&gt;
x= ((A(transpose)*A)^- 1 )A(transpose) * B&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.ee.oulu.fi/~mpa/matreng/ematr5_5.htm&quot;&gt;http://www.ee.oulu.fi/~mpa/matreng/ematr5_5.htm&lt;/a&gt;&lt;br&gt;
&lt;a href=&quot;http://www.ee.oulu.fi/~mpa/matreng/eem5_5-1.htm&quot;&gt;http://www.ee.oulu.fi/~mpa/matreng/eem5_5-1.htm&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
If yes, then please do let me how do i arrange the elements&lt;br&gt;
in the matrices (It is difficult for me to crack because of&lt;br&gt;
the unknown x and the square root).&lt;br&gt;
&lt;br&gt;
Thank you.&lt;br&gt;
&lt;br&gt;
- Mazahir </description>
    </item>
    <item>
      <pubDate>Mon, 18 Aug 2008 13:47:01 -0400</pubDate>
      <title>Solving equations</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/214708#575418</link>
      <author>Mazahir </author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
I am finding out the location of a sound source using&lt;br&gt;
microphones. The co-ordinates of the 3 mics are fixed.&lt;br&gt;
Suppose  the co-ordinates of the 3 mics are (x1,y1),(x2,y2)&lt;br&gt;
and (x3,y3) and the distance of source of sound from the 1st&lt;br&gt;
mic to the 2nnd is - del12 and the source of sound from the&lt;br&gt;
1st mic to the 3rd is del13. how do i find the location of&lt;br&gt;
the source (x,y) in MATLAB using the following formula.&lt;br&gt;
&lt;br&gt;
del12=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x2-x)^2+(y2-y)^2)&lt;br&gt;
del13=sqrt((x1-x)^2+(y1-y)^2)- sqrt((x3-x)^2+(y3-y)^2)&lt;br&gt;
&lt;br&gt;
Solving this equation of 2 unknowns simultaneously will give&lt;br&gt;
me the point (x,y). But i do not know how to do it in&lt;br&gt;
matlab. I think there is a solution using matrices. Please&lt;br&gt;
help. thank you. </description>
    </item>
    <item>
      <pubDate>Mon, 13 Jul 2009 14:36:03 -0400</pubDate>
      <title>Re: Solving equations</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/214708#664830</link>
      <author>Miguel Torres</author>
      <description>In order to solve your equations you need to solve it by the non-linear least-square methodology. In the link below you can find a brief mathematical description which will help you to solve your problem.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.ndt.net/article/ewgae2004/pdf/l58schubert.pdf&quot;&gt;http://www.ndt.net/article/ewgae2004/pdf/l58schubert.pdf&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Anyhow, you can solve this problem as well with the code provided by Prof. Balda (LMFnlsq function).&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Best regards,&lt;br&gt;
&lt;br&gt;
Miguel Angel</description>
    </item>
    <item>
      <pubDate>Tue, 14 Jul 2009 02:06:02 -0400</pubDate>
      <title>Re: Solving equations</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/214708#665012</link>
      <author>John D'Errico</author>
      <description>&quot;Miguel Torres&quot; &amp;lt;gugugifo@yahoo.com&amp;gt; wrote in message &amp;lt;h3fgoj$jtq$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; In order to solve your equations you need to solve it by the non-linear least-square methodology. In the link below you can find a brief mathematical description which will help you to solve your problem.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.ndt.net/article/ewgae2004/pdf/l58schubert.pdf&quot;&gt;http://www.ndt.net/article/ewgae2004/pdf/l58schubert.pdf&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Anyhow, you can solve this problem as well with the code provided by Prof. Balda (LMFnlsq function).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Best regards,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Miguel Angel&lt;br&gt;
&lt;br&gt;
NO. You do not need nonlinear least squares to solve&lt;br&gt;
this.&lt;br&gt;
&lt;br&gt;
While it looks like a nonlinear problem because of the&lt;br&gt;
sqrt, or square terms, it turns out this is not necessary&lt;br&gt;
at all.&lt;br&gt;
&lt;br&gt;
There are three circles of known radii, all must have&lt;br&gt;
the same (unknown) center. Call that center (x0,y0).&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;(x0 - x1)^2 + (y0 - y1)^2 = r1^2&lt;br&gt;
&amp;nbsp;&amp;nbsp;(x0 - x2)^2 + (y0 - y2)^2 = r2^2&lt;br&gt;
&amp;nbsp;&amp;nbsp;(x0 - x3)^2 + (y0 - y3)^2 = r3^2&lt;br&gt;
&lt;br&gt;
The only unknowns are x0 and y0. Expand and subtract.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;2*(x2 - x1)*x0 + 2*(y2 - y1)*y0 = r2^2 - r1^2 + x1^2 - x2^2&lt;br&gt;
&amp;nbsp;&amp;nbsp;2*(x3 - x1)*x0 + 2*(y3 - y1)*y0 = r3^2 - r1^2 + x1^2 - x3^2&lt;br&gt;
&lt;br&gt;
You are left with two LINEAR equations in the two&lt;br&gt;
unknowns. Solve. If you have noise in the data, one&lt;br&gt;
option that I recall seems to help is to make it a&lt;br&gt;
least squares problem. Generate the 3x2 linear system:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;2*(x2 - x1)*x0 + 2*(y2 - y1)*y0 = r2^2 - r1^2 + x1^2 - x2^2&lt;br&gt;
&amp;nbsp;&amp;nbsp;2*(x3 - x1)*x0 + 2*(y3 - y1)*y0 = r3^2 - r1^2 + x1^2 - x3^2&lt;br&gt;
&amp;nbsp;&amp;nbsp;2*(x3 - x2)*x0 + 2*(y3 - y2)*y0 = r3^2 - r2^2 + x2^2 - x3^2&lt;br&gt;
&lt;br&gt;
Again, solve using backslash.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
  </channel>
</rss>

