0

I want to solve a set of non linear equations in matlab. I mean lets say I have two points defined by (lat1,lon1) and (lat2,lon2). Now I want to find a point lat3,lon3 such that it is at a distance of 20km from both of the points. It is given by the intersection of the circles with radius 20km drawn with points (lat1,lon1) and (lat2,lon2) as center.

However, I am a bit confused about how to solve this equation.

I have the function to calculate the distance between two points in matlab

function [ distance ] = calculateDistance( latitude1,longitude1,latitude2,longitude2 )
radius = 6371;
dLat = degtorad(latitude2-latitude1);
dLon = degtorad(longitude2-longitude1);
a = sin(dLat/2) * sin(dLat/2) + cos(degtorad(latitude1)) * cos(degtorad(latitude2)) * sin(dLon/2) * sin(dLon/2);
c = 2 * atan2(sqrt(a), sqrt(1-a));
distance = radius * c;
end

and I am trying to use the solve function of matlab available at http://www.mathworks.com/help/toolbox/symbolic/solve.html

However when I define

syms lat3 lon3

and try to get the equations to pass to the solve function it throws the error that atan2 only accepts arguments of type sym. How can I over this?

4

1 回答 1

0

如果您只需要解决该特定问题,则不需要 Matlab 的任何方程求解函数。您可以简单地使用毕达哥拉斯的公式:

如果您的点是(0,0)和(1,0)并且半径是x,那么距离(0,0)和(1,0)都是x的两个点是

(0.5, sqrt (x^2 - 0.25) ) 和 (0.5, - sqrt (x^2 - 0.25))。

现在如果你的点是(a,b)和(c,d),那么两点的距离是

dist = sqrt ( (ca)^2 + (db)^2 )。

好的,现在我们采用一个坐标系,原点为 (a,b),单位为 dist,横轴经过 (c,d)。在这个坐标系中,有问题的点是

(0.5, +/- sqrt ( (r/dist)^2 - 0.25 ) )。

现在,为了得到原始坐标系,我们必须乘以 dist,得到

(0.5 * dist, +/- sqrt (r^2 - 0.25 * dist^2)),

然后随着矩阵旋转(dist,0)到(ca,db),即

cos alpha   -sin alpha
sin alpha   cos alpha

其中 alpha = arccos ( (db) / dist),即矩阵

(d-b) / dist   -(c-a) / dist
(c-a) / dist    (d-b) / dist

这使

(0.5 (db) -/+ (ca) sqrt (r^2 / dist^2 - 0.25), 0.5 (ca) +/- (db) sqrt (r^2 / dist^2 - 0.25)

最后加上 (a,b),得到

(a + 0.5 (db) -/+ (ca) sqrt (r^2 /dist^2 - 0.25), b + 0.5 (ca) +/- (db) sqrt (r^2 /dist^2 - 0.25) )

这些是您正在寻找的要点。可能我在某个地方犯了一个错误,但我希望方向应该是明确的。

于 2012-06-04T20:55:23.397 回答