I am trying to estimate the position of a point $P$ in Matlab. I have $n$ access points (AP) at known positions ($n>2$) as well as the distances to the point $P$ from each AP. These distances all have a distance error. I know how to solve this using multilateration if the circles from the known nodes would intersect, but they don't.
The distances are computed from RSSI measurements (received signal strength indication) and might be weighted (larger weight if RSSI is high).
See code below. Note that I'm not weighting the RSSI measurements. I'm creating an error function, where $xp$ and $yp$ are the point's unknown coordinates. $x$ and $y$ are known coordinates of the APs. I want to sum all the errors and find the $xp$ and $yp$ that minimize the error function, but not sure how to do this in Matlab.
for n=1:N % N - number of APs d(n)=getDistance(rssi(n),tx,2); err=@(px,py) sqrt((x(n)-px).^2+(y(n)-py).^2)-d(n); end err=sum(err); % this doesn't work obviously x0 = [xp_true(k),yp_true(k)]; out= fminunc(err,x0); xp(k,sample)=out(1); yp(k,sample)=out(2);