title: Trilateration with LMFIT Python
body: <p>I'm trying to perform Non-Linear Least-Squares Fitting LMFIT for Trilateration purposes:   </p>
  
  <ul>
  <li><a href="http://cars9.uchicago.edu/software/python/lmfit/intro.html" rel="nofollow noreferrer">LMFIT</a></li>
  <li>beacons includes beacon position x,y,z   </li>
  <li><code>Parameters()</code> include <code>Xinit</code> location to estimate.   </li>
  <li><code>tag_distances[i]</code> include measurements (distance from tag to <code>beacon[i]</code>)</li>
  </ul>
  
  <p>I get this error:   </p>
  
  <blockquote>
    <p>raise TypeError('Improper input: N=%s must not exceed M=%s' % (n, m))
    TypeError: Improper input: N=3 must not exceed M=1</p>
  </blockquote>
  
  <pre><code>import numpy as np
  from math import pow
  from lmfit import minimize, Parameters
  
  beacons=np.array([[0.,0.,5.],
                [0.,15.,5.],
                [15.,0.,5.],
                [15.,15.,5.]])
  
  tag=np.array([0,15,0])  
  tag_distances=np.arange(float(beacons.shape[0]))
  
  xinit=np.array([5.,5.,2.])
  
  def distance (p1, p2):
      s=0
      for i in range (0,3):
      s+=(p1[i]-p2[i])**2
      return s**.5
  
  for i in range (0,beacons.shape[0]): 
    tag_distances[i]=distance(beacons[i,:],tag)
  tag_distances= tag_distances.reshape(beacons.shape[0], 1)
  
  def residual(params, measures , beacons, eps_data):
      x=np.array([ params['x'].value,
                 params['y'].value,
                 params['z'].value])
      s=0
      for i in range (0,beacons.shape[0]): 
         s+=(measures[i,0]-distance(beacons[i,:],x))**2
   return s 
  
  params = Parameters()
  params.add('x', value=xinit[0])
  params.add('y', value=xinit[1])
  params.add('z', value=xinit[2])
  
  eps_data=np.array([1.0,1.0,1.0,1.0])
  
  out = minimize(residual, params, args=(tag_distances, beacons, eps_data))
  </code></pre>