complex numbers
It's me
itsme at yahoo.com
Wed Jan 12 17:30:04 CET 2005
Precisely. One have to convert complex number into vectors, and vector of
complex numbers into vector of vectors, list of complex numbers into list of
vectors, ...., you get the idea.
And my code no longer look like the equation I have on paper...
Like I said, I've travelled down that path before with C++ and Modelica.
It gets ugly.
Anyway.
"Antoon Pardon" <apardon at forel.vub.ac.be> wrote in message
news:slrncu9mmo.1r6.apardon at rcpc42.vub.ac.be...
> Op 2005-01-12, It's me schreef <itsme at yahoo.com>:
> >
> > "Robert Kern" <rkern at ucsd.edu> wrote in message
> > news:cs1mp9$sg9$1 at news1.ucsd.edu...
> >>
> >> That's *it*.
> >
> > So, how would you overload an operator to do:
> >
> > With native complex support:
> >
> > def twice(a):
> > return 2*a
> >
> > print twice(3+4j), twice(2), twice("abc")
> >
> > Let's presume for a moment that complex is *not* a native data type in
> > Python. How would we implement the above - cleanly?
>
>
> I suppose in the same way as (graphic) points and vectors can be
> implemented cleanly.
>
> A few years back I had written a Vector class in python, just
> to get an understanding of how things worked. It worked without
> a problem with your twice function.
>
>
> >>> Vec(1.0,2.0)
> Vector[1.0, 2.0]
> >>> def twice(a):
> ... return 2 * a
> ...
> >>> twice(Vec(1.0,2.0))
> Vector[2.0, 4.0]
> >>>
>
>
> I suppose what can be done with a vector class could have been
> done with a complex class should complex numbers not have been
> native to python.
>
> --
> Antoon Pardon
More information about the Python-list
mailing list