Python scipy fsolve "mismatch between the input and output shape of the 'func' argument" -


this first time posting on stackoverflow, if don't use correct stackoverflow etiquette, i'm sorry.

before go problem, i've searched relevant threads on stackoverflow same problem:

from understand reading error,

raise typeerror(msg)
typeerror: fsolve: there mismatch between input , output shape of 'func' argument 'fsolve_function'

the issue shape of input , output not same.

in code example below, have following:

  • input, initialguess (the starting estimate used in fsolve function in scipy.optimize). input, initialguess has 3 starting estimates coordinates x,y , z. therefore expect starting input estimate have 3 inputs.
  • output, out (non-linear simultaneous equations). in example have 4 non-linear equations.
  • scipy.optimize.fsolve raises error highlighted above, because input , output not have same shape. in particular case, want input have 3 values (to guess initial starting points of x, y, , z). output in case has 4 non-linear equations solve using initial input estimate.
  • side note: using same input , output shape, eg. input shape of 3 [x, y, z] , output of 3 non-linear equations, fsolve calculation accordingly. i'm wondering how extend fsolve use let's equal or more 4 non-linear simultaneous equations 3 input initial estimates?
  • code below:

    from scipy.optimize import fsolve  def fsolve_function(arguments):     x = arguments[0]     y = arguments[1]     z = arguments[2]      out = [(35.85 - x)**2 + (93.23 - y)**2 + (-39.50 - z)**2 - 15**2]     out.append((42.1 - x)**2 + (81.68 - y)**2 + (-14.64 - z)**2 - 27**2)     out.append((-70.90 - x)**2 + (-55.94 - y)**2 + (-68.62 - z)**2 - 170**2)     out.append((-118.69 - x)**2 + (-159.80 - y)**2 + (-39.29 - z)**2 - 277**2)      return out  initialguess = [35, 93, -39] result = fsolve(fsolve_function, initialguess) print result  

thank in advance.

fsolve wrapper of minpack's hybrd, requires function's argument , output have same number of elements. can try other algorithms more general scipy.optimize.root not have restriction (e.g. lm):

from scipy.optimize import fsolve, root  def fsolve_function(arguments):     x = arguments[0]     y = arguments[1]     z = arguments[2]      out = [(35.85 - x)**2 + (93.23 - y)**2 + (-39.50 - z)**2 - 15**2]     out.append((42.1 - x)**2 + (81.68 - y)**2 + (-14.64 - z)**2 - 27**2)     out.append((-70.90 - x)**2 + (-55.94 - y)**2 + (-68.62 - z)**2 - 170**2)     out.append((-118.69 - x)**2 + (-159.80 - y)**2 + (-39.29 - z)**2 - 277**2)      return out  initialguess = [35, 93, -39] result = root(fsolve_function, initialguess, method='lm') print(result.x) 

incidentally, cannot find actual 0 --- there supposed 1 @ all?

you can force fsolve use function if supply initial guess "bogus" fourth variable:

initialguess = [35, 93, -39, 0] 

but i'm not sure how reliable results in case.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -