2012-11-06 24 views
1

我有一個物理測量儀器(帶有測力傳感器的力平臺),它給了我三個值A,B和C.由於測量設備的物理特性,這些值應該是正交的 - 實際上有些耦合,這導致施加和返回的力和扭矩值之間的串擾。使用Python/Scipy爲一組測量解決方程組

然後,建議校準矩陣被用於將測量值轉換爲實際值的更好的估計,如下所示:

enter image description here

的問題是,它需要執行一組測量數據,因此不同的measured(Fz, Mx, My)actual(Fz, Mx, My)最小平方得到一個最適合整個系統的C矩陣。

我可以解決Ax = B問題scipy.linalg.lststq,甚至scipy.linalg.solve(給出一個確切的溶液),用於一個測量,但我應如何進行考慮的一組不同的測量,每一個與它自己的方程給出潛在不同的3×3矩陣?

任何幫助非常感謝,因爲閱讀。

+0

如果我理解正確,你想有一個解決**變量**(Fz,Mx,My)的每個**值的3變量方程?如果Fz,Mx和My用6位編碼(等於128個值),那麼給你大約一百萬個3x3矩陣來存儲.. – lucasg

+0

@georgesl我在math.stackexchange.com上發佈了一個類似的問題,其中只包含了這個數學部分,和這個答案解決了這個問題:http://math.stackexchange.com/a/232124/27435 – heltonbiker

+1

在這種情況下,你應該anwser你自己的問題,並關閉線程 – lucasg

回答

1

我張貼含有math.stackexchange.com的這只是數學部分類似的問題,而這個答案解決了這個問題:

math.stackexchange.com/a/232124/27435

在任何情況下,將來有類似的問題,這裏是幾乎字面SciPy的實現,它的答案(第一行是初始化樣板代碼):

import numpy 
import scipy.linalg 

### Origin of the coordinate system: upper left corner! 
""" 
    1----------2 
    |   | 
    |   | 
    4----------3 
""" 

platform_width = 600 
platform_height = 400 

# positions of each load cell (one per corner) 
loadcell_positions = numpy.array([[0, 0], 
            [platform_width, 0], 
            [platform_width, platform_height], 
            [0, platform_height]]) 

platform_origin = numpy.array([platform_width, platform_height]) * 0.5 

# applying a known force at known positions and taking the measurements 
measurements_per_axis = 5 
total_load = 50 

results = [] 
for x in numpy.linspace(0, platform_width, measurements_per_axis): 
    for y in numpy.linspace(0, platform_height, measurements_per_axis): 
     position = numpy.array([x,y]) 
     for loadpos in loadcell_positions: 
      moments = platform_origin-loadpos * total_load 
      load = numpy.array([total_load]) 
      result = numpy.hstack([load, moments]) 
      results.append(result) 
results = numpy.array(results) 
noise = numpy.random.rand(*results.shape) - 0.5 
measurements = results + noise 

# now expand ("stuff") the 3x3 matrix to get a linearly independent 3x3 matrix 
expands = [] 
for n in xrange(measurements.shape[0]): 
    k = results[n,:] 
    m = measurements[n,:] 

    expand = numpy.zeros((3,9)) 
    expand[0,0:3] = m 
    expand[1,3:6] = m 
    expand[2,6:9] = m 
    expands.append(expand) 
expands = numpy.vstack(expands) 

# perform the actual regression 
C = scipy.linalg.lstsq(expands, measurements.reshape((-1,1))) 
C = numpy.array(C[0]).reshape((3,3)) 

# the result with pure noise (not actual coupling) should be 
# very close to a 3x3 identity matrix (and is!) 
print C 

希望這可以幫助別人!