

Robots can be fixed, glory is forever  Brandon Holley [more] 



Thread Tools  Rate Thread  Display Modes 
#16




Re: Math Quiz 11
Letting matlab do the work. Set up a system of equations. x(1) = point2.x, x(2) = point2.y, x(3) = point3.x, etc. This is a set of (xsrcxdst)^2 + (ysrcydst)^2  distance^2 = 0 equations derived from the list given in the OP.
Code:
function F = distEQ(x) F(1) = (x(1)  x(5))^2 + (x(2)  x(6))^2  47.8017^2; F(2) = (x(3)  x(7))^2 + (x(4)  x(8))^2  69.2026^2; F(3) = (x(7)  x(15))^2 + (x(8)  x(16))^2  148.492^2; F(4) = (x(11)  x(13))^2 + (x(12)  x(14))^2  86.764^2; F(5) = (x(7)  x(9))^2 + (x(8)  x(10))^2  63.0714^2; F(6) = (x(1)  x(13))^2 + (x(2)  x(14))^2  189.528^2; F(7) = (x(9)  x(11))^2 + (x(10)  x(12))^2  65.192^2; F(8) = (x(5)  x(15))^2 + (x(6)  x(16))^2  147.085^2; F(9) = (x(1)  x(3))^2 + (x(2)  x(4))^2  90.5207^2; F(10) = (x(9)  x(13))^2 + (x(10)  x(14))^2  86.0349^2; F(11) = (x(3)  x(15))^2 + (x(4)  x(16))^2  171.956^2; F(12) = (x(5)  x(11))^2 + (x(6)  x(12))^2  88.8144^2; F(13) = x(1)  0; F(14) = x(2)  0; Code:
>> fun = @distEQ; >> x0(1:16) = 10; >> x = fsolve(fun, x0) x = Columns 1 through 7: 8.7244e20 4.0763e20 8.9553e+01 1.3199e+01 3.9964e+01 2.6228e+01 3.3832e+01 Columns 8 through 14: 2.7839e+01 8.8708e+01 5.8929e+01 5.3763e+01 1.1396e+02 1.3930e+02 1.2852e+02 Columns 15 and 16: 1.0523e+02 1.5804e+02 # Convert to x,y coords for point2, 3, 4, etc. >> xx = reshape(x,2,8)' xx = 8.7244e20 4.0763e20 8.9553e+01 1.3199e+01 3.9964e+01 2.6228e+01 3.3832e+01 2.7839e+01 8.8708e+01 5.8929e+01 5.3763e+01 1.1396e+02 1.3930e+02 1.2852e+02 1.0523e+02 1.5804e+02 # Sanity check pt2 > pt4 matches the initial conditions >> sqrt(sum((xx(1,:)  xx(3,:)).^2)) ans = 47.802 # see what this run gets for 8>9 (remember index  1) >> sqrt(sum((xx(7,:)  xx(8,:)).^2)) ans = 45.081 
#17




Re: Math Quiz 11
I have attached a spreadsheet which goes through the calculations to solve this problem. I haven't verified everything on it yet, but I have fixed a lot of problems along the way; I'm mostly posting to show that the problem IS soluble and as a demo of the sorts of ambiguities and multiple roots that make result in multiple solutions to the system of twelve equations in twelve unknowns.
The cells highlighted in yellow are intended to be set as you investigate different values of distance 89, and the different ambiguities, or if you want to zoom in to a particular segment of angle 859; see the notes in the spreadsheet for details. The top graph is a layout of the eight points based on all of the constraints EXCEPT the distance 24, and also based on the four ambiguity states and the initial angle 859. The second plot spans a range of angles 859. By default, I have it set for the range from 0 to 2pi. Essentially, you enter the value for distance 89, then try each of the 16 ambiguity states, and look for places where the actual distance between points 2 and 4 (red curve) crosses the constraint distance (green line), then trace up that angle to a value for distance 89 (blue curve). Ideally, you would use Newton's method or similar to determine where a crossing occurs, and zoom in on it to find more precisely where the crossing occurs. With the assumed distance 89 of 55.17, I found two solutions for falsefalsefalsetrue, (approx 190 and 186), two for falsetruetruefalse (127, 183), and a near miss on truetruetruefalse (109). I don't think I've used anything more complex than the law of cosines to do any of this. Does this answer your question, Jon Stratis? 
#18




Re: Math Quiz 11
Math Quiz 11, Part B: Given three points p1, p2, p3 with coordinates (1,1), (1.5,0.5), and (2.0,0.75) respectively... ... find the coordinates of the point p4 whose distance from points p1, p2, p3 is 1.477601434758372, 1.909792135285932, 2.416879392936271 respectively. 
#19




Re: Math Quiz 11
Quote:
Solution here. This method adds a free parameter to the distance measurements representing measurement error (assuming it is uniform across all measurements), which lets us solve the system of equations efficiently to find the point representing the center of the three circlecircle intersections (obtained by leaving out one constraint at a time). "h" represents the radius^2 of the circle joining those intersections (which can be imaginary, as in this case, depending on whether or not all three circles overlap or not). The fact that "h" is small in magnitude shows that the solution is very close. It would also be reasonable to want a (perhaps weighted by distance) least squares solution, but this would require whipping out a nonlinear least squares solver. 
#20




Re: Math Quiz 11
Gee, that's some nice math
For part B... Is the system actually solvable? You can define each circle with the simple equation (x+a)^2 + (y+b)^2 = r^2. That leaves you with 3 equations but only 2 unknowns, which makes it really easy for there to be no solution. Of course, there's no guarantee that the circles even intersect, but we should assume they do, right? Two circles can have 2, 1, or no intersections in common, likewise three circles can have 2, 1, or 0 common intersections! Plotting it out, it initially looks like there's an intersection point (near 0.409, 0.555) ... but zoom in and the circles just miss having a common intersection. Plug the system of equations into Wolfram Alpha, and it comes back with no solution, supporting this finding. So, lets simplify it down to pairs of circles, see how close we actually get. p1 + p2: x=0.409 y=0.5550000000000005 p1 + p3: x=0.4089999999999995 y=0.5549999999999989 p2 + p3: x=0.4089999999999999 y=0.5550000000000041 Given how close we are... Is this just a rounding issue with your numbers Ether, or is there intentionally no solution? 
#21




Re: Math Quiz 11
The solver approach also gives p4 = (.409, .555). I modified the distEQ from my previous post and it converged pretty much immediately.
Not sure what Wolfram Alpha uses but e15 looks an awful lot like C++'s double epsilon value, meaning it it likely hitting limits of the precision an 8byte floating point number can handle. Last edited by KJaget : 05112017 at 11:51 AM. 
#22




Re: Math Quiz 11
Point (.409, .555) works out just fine in gawk (running under cygwin running under windows 7 32 bit); I suspect differences in round off.
Code:
GeeTwo@Teal ~ $ cat ./MQ11.gawk #!/bin/gawk f BEGIN {x[1]=1; x[2]=1.5; x[3]=2.0; y[1]=1;y[2]=0.5; y[3]=0.75; r[1]=1.477601434758372; r[2]=1.909792135285932; r[3]=2.416879392936271; tx=.409; ty=0.555; for (i=1; i<4; i++) { printf "point %d: %.15f %.15f\n", i, r[i], sqrt((txx[i])*(txx[i])+(tyy[i])*(tyy[i]));} } GeeTwo@Teal ~ $ ./MQ11.gawk point 1: 1.477601434758372 1.477601434758372 point 2: 1.909792135285932 1.909792135285932 point 3: 2.416879392936271 2.416879392936271 Last edited by GeeTwo : 05112017 at 12:21 PM. 
#23




Re: Math Quiz 11
Nice work Jared and Jon. Thanks for posting. Quote:
Good question. Technically, no, because it's overdetermined as Jared (and you) said... ... but, I purposely picked distance values that make all 3 circles have a common intersection point (to several decimal digits), so in that sense it is solvable for a unique solution. EDIT: Hey Gus, welcome to the gawk club! It's my goto tool for data munging and quick math stuff. Last edited by Ether : 05112017 at 01:16 PM. 
#24




Re: Math Quiz 11
Quote:
Now the 3 circles no longer have a common point of intersection, so it becomes an optimization problem. Maxima can use Powell's COBYLA algorithm to find a "best fit" value based on an objective function that the user can define. The red boxes are the solution using equal weights for all three distance errors. The green boxes are the solution for relative weights inversely proportional to the distance. 
#25




Re: Math Quiz 11
Quote:
Then I didn't know what to do. SolidWorks doesn't (that I know of) have a way to set the length of a line to it's minimum acceptable value. So I just started plugging in numbers, a number larger than the minimum error would be accepted, a number smaller would make the sketch unsolvable. So I started hopping between two numbers, averaging them, getting a new domain, averaging them, etc. I did like 20 iterations of this, eventually working with numbers that were ten decimals long. Then I finally noticed something interesting, as the error became closer to the minimum value the lines became closer and closer to being colinear. So I scrapped dimensioning the error lines and just set each error line as colinear with its respective distance line. This generated the final position of my point four. Which I got to be (.50036693, .54231098) with an error length of .09102222. This was a different location than Ether's so I tried plugging in his point for equal error. When I did this the minimum error I could get was .118118 (coincidence? I think not). Ether is a lot smarter than I am, and he actually used math so I'm assuming I just couldn't get SolidWorks to get a smaller error using his point. So what I want to know is what is the error for Ether's calculation and is it actually smaller than mine (I assume so)? 
#26




Re: Math Quiz 11
Quote:
The answer you get depends on what you're trying to minimize and what constraints you impose. As Jared posted earlier in this thread: Quote:
I minimized the sum of the squares of the errors (SSE), with no residual equality constraint, so my solution has a smaller SSE than yours. Last edited by Ether : 05132017 at 06:31 PM. 
#27




Re: Math Quiz 11
Quote:
The coordinates of the solution (green box) match yours, and the residuals (orange box) match yours. 
Thread Tools  
Display Modes  Rate This Thread 

