I am trying to learn sympy by plotting Lissajous curves. I am familiar with 
python and know some math. I downloaded and installed the Anaconda package 
for Windows. I have been able to get a simple curve plotted but the 
attached text file shows the few statements and a plot command which gives 
a "TypeError: can't convert expression to float" I have tried defining the 
symbols as real=true but that did not help. Is the plotting converting a 
float to a complex then complaining that it cannot convert a complex to 
float?  What is the problem with my code?

Attached is a short text file with statements and error.  Thanks for your 
help.

https://en.wikipedia.org/wiki/Lissajous_curve

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/f4965185-4dc6-4299-858e-8f36ba452eb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jupyter QtConsole 4.1.1
Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC 
v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 4.0.3 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

from sympy import *

init_session()
IPython console for SymPy 0.7.6.1 (Python 3.5.1-64-bit) (ground types: python)

These commands were executed:
from __future__ import division
from sympy import *
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)
init_printing()

Documentation can be found at http://www.sympy.org

from sympy.plotting import (plot, plot_parametric,
                    plot3d_parametric_surface, plot3d_parametric_line,
                    plot3d)
from sympy.polys.polyfuncs import interpolate


ampx, ampy, freqx, freqy, theta = symbols('ampx ampy freqx freqy theta', 
real=true)
frictionx, frictiony = symbols('frictionx, frictiony', real=true)
tmin, tmax = symbols('tmin, tmax', real=true)


frictionx = interpolate([(tmin, 0.0), (tmax, ln(0.5))], t)
frictiony = interpolate([(tmin, 0.0), (tmax, ln(0.5))], t)


x = ampx * frictionx * sin(freqx * t + theta)
y = ampy * frictiony * sin(freqy * t)


varx = {'ampx':1.0, 'freqx':3.0, 'theta':pi/4.0, 'frictionx': frictionx}
vary = {'ampy':2.0, 'freqy':1.0, 'frictionx': frictionx}
tmin = 0.0
tmax = 4.0 * pi


plot_parametric(x.subs(varx), y.subs(vary), (t, tmin, tmax))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\plotting\experimental_lambdify.py
 in __call__(self, args)
    193             #The result can be sympy.Float. Hence wrap it with complex 
type.
--> 194             result = complex(self.lambda_func(args))
    195             if abs(result.imag) > 1e-7 * abs(result):

<string> in <lambda>(x0)

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\core\expr.py in 
__complex__(self)
    229         re, im = result.as_real_imag()
--> 230         return complex(float(re), float(im))
    231 

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\core\expr.py in 
__float__(self)
    224             raise TypeError("can't convert complex to float")
--> 225         raise TypeError("can't convert expression to float")
    226 

TypeError: can't convert expression to float

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-8-8f9ff98dad6e> in <module>()
----> 1 plot_parametric(x.subs(varx), y.subs(vary), (t, tmin, tmax))

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\plotting\plot.py in 
plot_parametric(*args, **kwargs)
   1409     plots = Plot(*series, **kwargs)
   1410     if show:
-> 1411         plots.show()
   1412     return plots
   1413 

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\plotting\plot.py in 
show(self)
    183             self._backend.close()
    184         self._backend = self.backend(self)
--> 185         self._backend.show()
    186 
    187     def save(self, path):

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\plotting\plot.py in 
show(self)
   1016 
   1017     def show(self):
-> 1018         self.process_series()
   1019         #TODO after fixing 
https://github.com/ipython/ipython/issues/1255
   1020         # you can uncomment the next line and remove the pyplot.show() 
call

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\plotting\plot.py in 
process_series(self)
    895             # Create the collections
    896             if s.is_2Dline:
--> 897                 collection = self.LineCollection(s.get_segments())
    898                 self.ax.add_collection(collection)
    899             elif s.is_contour:

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\plotting\plot.py in 
get_segments(self)
    627                 list_segments.append([p, q])
    628 
--> 629         f_start_x = f_x(self.start)
    630         f_start_y = f_y(self.start)
    631         start = [f_start_x, f_start_y]

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\plotting\experimental_lambdify.py
 in __call__(self, args)
    226                                                     use_evalf=True,
    227                                                     
complex_wrap_evalf=True)
--> 228                 result = self.lambda_func(args)
    229                 warnings.warn('The evaluation of the expression is'
    230                         ' problematic. We are trying a failback method'

<string> in <lambda>(x0)

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\core\expr.py in 
__complex__(self)
    228         result = self.evalf()
    229         re, im = result.as_real_imag()
--> 230         return complex(float(re), float(im))
    231 
    232     def __ge__(self, other):

K:\Documents\z_Programs\Anaconda\lib\site-packages\sympy\core\expr.py in 
__float__(self)
    223         if result.is_number and result.as_real_imag()[1]:
    224             raise TypeError("can't convert complex to float")
--> 225         raise TypeError("can't convert expression to float")
    226 
    227     def __complex__(self):

TypeError: can't convert expression to float


Reply via email to