Last active
August 29, 2015 13:57
-
-
Save straypacket/9521219 to your computer and use it in GitHub Desktop.
Linalg for wifi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'linalg' | |
include Linalg | |
# Linear equation to solve: | |
# a * x = b | |
# | |
# Example | |
# a = DMatrix[[1,0,0],[0,2,0],[0,0,1]] | |
# b = DMatrix[[1,1],[2,2],[3,3]] | |
# | |
# x = DMatrix.solve(a,b) | |
b = DMatrix[[2156,779],[2249,793],[2333,842],[2492,751],[2369,734],[2120,668],[2121,508],[2260,484],[2238,605],[2130,566],[2486,839],[2292,739],[2226,517]] | |
# We don't have "distances" between measurement points, but we can try to approximate them by the difference of powers | |
p = DMatrix[[38,27,41],[49,31,37],[45,43,30],[43,40,27],[45,36,32],[27,27,43],[29,36,41],[23,40,54],[33,36,47],[34,43,36],[53,38,15],[46,28,35],[28,36,52]] | |
pr = p.rows.count | |
a = DMatrix.new(pr,pr) | |
0.upto(pr-1) { |x| 0.upto(pr-1) { |y| a[x,y] = ((p[x,0]-p[y,0])**2 + (p[x,1]-p[y,1])**2 + (p[x,2]-p[y,2])**2)**0.5 } } | |
# Solve equations | |
x = DMatrix.solve(a,b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment