2016-12-13 2 views
3

Ich bin nicht sehr gut mit Python und ich brauche eine Gleichung zu verankern, die die unbekannten innerhalb Bessel-Funktionen enthält und der Code lautet wie folgt:Ergebnis von Funktionsaufruf ist kein ordnungsgemäßes Array von Floats. fsolve

import scipy.special as sp 
import numpy as np 
import matplotlib.pyplot as plt 
from scipy.optimize import fsolve 
import math 


eff = 50-10j     
e = 2.25     
w = 4e9*2*np.pi   
a = 7.5e-6   
c = 3e8     
p = 0.0022/100.   
L = np.sqrt(np.pi*a**2/p) 
lc= 0.05     
largo=0.38     
ancho=0.34    
prof=2./1000.    
volm=largo*ancho*prof  
volc=np.pi*a**2*lc   
volct=volm*p    
n=volct/volc    
nh=n*1e-4/(largo*ancho) 


func = lambda ec : e - (np.pi*a**2/L**2)*(2*ec*(sp.j1((ec**0.5)*w*a/c)/((ec**0.5)*w*(a/c)*sp.j0((ec**0.5)*w*a/c))))/(((((ec**0.5)*w*a/c)**2)*(sp.j1((ec**0.5)*w*a/c))/(((ec**0.5)*w*(a/c)*sp.j0((ec**0.5)*w*a/c))*np.log(L/a)))-1) - eff 


# Solver 

ec_initial_guess = 0.1 
ec_solution = fsolve(func, ec_initial_guess) 


print "Solution for ec is = %f" % ec_solution 
print "when the value of the expression is %f" % func(ec_solution) 

und ich bekomme die Fehlermeldung:

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
TypeError: Cannot cast array data from dtype('complex128') to dtype('float64') according to the rule 'safe' 

--------------------------------------------------------------------------- 
error          Traceback (most recent call last) 
<ipython-input-13-a9b1acf35136> in <module>() 
    40 
    41 ec_initial_guess = 1 
---> 42 ec_solution = fsolve(func, ec_initial_guess) 
    43 
    44 

/home/feliperossik/anaconda2/lib/python2.7/site-packages/scipy/optimize/minpack.pyc in fsolve(func, x0, args, fprime, full_output, col_deriv, xtol, maxfev, band, epsfcn, factor, diag) 
    144    'diag': diag} 
    145 
--> 146  res = _root_hybr(func, x0, args, jac=fprime, **options) 
    147  if full_output: 
    148   x = res['x'] 

/home/feliperossik/anaconda2/lib/python2.7/site-packages/scipy/optimize/minpack.pyc in _root_hybr(func, x0, args, jac, col_deriv, xtol, maxfev, band, eps, factor, diag, **unknown_options) 
    222    maxfev = 200 * (n + 1) 
    223   retval = _minpack._hybrd(func, x0, args, 1, xtol, maxfev, 
--> 224         ml, mu, epsfcn, factor, diag) 
    225  else: 
    226   _check_func('fsolve', 'fprime', Dfun, x0, args, n, (n, n)) 

error: Result from function call is not a proper array of floats. 

Dies ist meine erste Frage hier, ich sorge mich um das Eqution-Format, ich weiß nicht wirklich, wie ich es schreiben soll, wie ich es in Latex machen würde.

Ich würde mich über jede Hilfe freuen! Danke im Voraus!

bearbeiten: Im das komplexe Denken ist nicht richtig edit2: Die sp.j1 und sp.j0 sind Bessel fucntions

Antwort

2

fsolve() ist nur für echte Funktionen, und Sie in der Definition der ec() Lambda-Funktion der komplexe Wert

+0

Ach ja, muss ich die Funktion dann ändern, da ich komplexe Werte einfügen muss! Hast du eine Empfehlung? Müssen Sie auch die Bessel-Funktionen nutzen! Ich danke Ihnen sehr für Ihre Antwort!! –

Verwandte Themen