Sympy plot кусочно TypeError: '<=' не поддерживается между экземплярами 'complex' и 'float'

Я пытаюсь выяснить, как построить следующую симпти кусочную функцию

import sympy
from sympy.abc import x
from sympy.plotting import plot    

...

def camber_line(self):
    """The equation of the camber line"""
    m = self._max_camber
    p = self._max_camber_pos
    c = float(self._chord.value)
    """"Symmetrical airfoils"""
    if m == 0:
        return 0
    """Cambered airfoils"""
    return sympy.Piecewise(
        (c * m / p**2 * (2 * p * (x / c) - (x / c)**2), x <= p * c),
        (c * m / (1 - p)**2 * ((1 - 2 * p) + 2 * p * (x / c) - (x / c)**2), x >= p * c)
    )

где-нибудь еще

plot(self.camber_line(), (x, 0, self._chord))

Я получаю следующую ошибку: TypeError: '<=' not supported between instances of 'complex' and 'float'

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py", line 194, in __call__
    result = complex(self.lambda_func(args))
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py", line 316, in __call__
    return self.lambda_func(*args, **kwargs)
  File "<string>", line 1, in <lambda>
TypeError: '<=' not supported between instances of 'complex' and 'float'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "aero464ass4.py", line 66, in _calc_button_action
    plot(self.camber_line(), (x, 0, self._chord))
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/plot.py", line 1295, in plot
    plots.show()
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/plot.py", line 196, in show
    self._backend.show()
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/plot.py", line 1029, in show
    self.process_series()
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/plot.py", line 908, in process_series
    collection = self.LineCollection(s.get_segments())
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/plot.py", line 514, in get_segments
    f_start = f(self.start)
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py", line 231, in __call__
    result = self.lambda_func(args)
  File "/usr/local/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py", line 316, in __call__
    return self.lambda_func(*args, **kwargs)
  File "<string>", line 1, in <lambda>
TypeError: '<=' not supported between instances of 'complex' and 'float'

Что-то не так с сравнением неравенства. Симпи символ кажется комплексным числом? У кого-нибудь есть предложение, как я могу заставить это работать? Спасибо!

ОБНОВЛЕНИЕ: отключение адаптивной выборки исправляет это, но также дает загадочную ошибку

plot(self.camber_line(), (x, 0, self._chord), adaptive=False, nb_of_points=400)

/usr/local/lib/python3.6/site-packages/sympy/plotting/experimental_lambdify.py:165: UserWarning: The evaluation of the expression is problematic. We are trying a failback method that may still work. Please report this as a bug.
  warnings.warn('The evaluation of the expression is'

0 ответов

Другие вопросы по тегам