Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70007 > unrolled thread

Plotting the integer-and-fraction remainder of a function value modulo 360

Started byKim Plofker <kim_plofker@yahoo.com>
First post2014-04-09 21:32 -0700
Last post2014-04-09 22:12 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Plotting the integer-and-fraction remainder of a function value modulo 360 Kim Plofker <kim_plofker@yahoo.com> - 2014-04-09 21:32 -0700
    Re: Plotting the integer-and-fraction remainder of a function value modulo 360 Steven D'Aprano <steve@pearwood.info> - 2014-04-10 05:01 +0000
      Re: Plotting the integer-and-fraction remainder of a function value modulo 360 Kim Plofker <kim_plofker@yahoo.com> - 2014-04-09 22:12 -0700

#70007 — Plotting the integer-and-fraction remainder of a function value modulo 360

FromKim Plofker <kim_plofker@yahoo.com>
Date2014-04-09 21:32 -0700
SubjectPlotting the integer-and-fraction remainder of a function value modulo 360
Message-ID<mailman.9111.1397104356.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

How can I get Python to represent a value of a function in degrees, i.e., with values between 0 and 360, by taking the (non-integer) function expression mod 360?

That is, I have a function with non-integer values, called Longitude, which is defined in terms of the variable t. I just want to plot Longitude modulo 360 for a range of values of t: that is, for every value of t, plot the integer-AND-fraction remainder after dividing Longitude by 360.

But Python (in Sage) apparently won't let me use the int function or the // operator on functions defined in terms of a variable: I get a "cannot evaluate symbolic expression numerically" TypeError. How do I do this? There must be a simple way to tell Python that I want it to compute the value of Longitude for a given value of t and then take the integer-and-fraction remainder from dividing by 360.



Many thanks,
Kim

[toc] | [next] | [standalone]


#70009

FromSteven D'Aprano <steve@pearwood.info>
Date2014-04-10 05:01 +0000
Message-ID<534625b5$0$11109$c3e8da3@news.astraweb.com>
In reply to#70007
On Wed, 09 Apr 2014 21:32:27 -0700, Kim Plofker wrote:

> How can I get Python to represent a value of a function in degrees,
> i.e., with values between 0 and 360, by taking the (non-integer)
> function expression mod 360?
> 
> That is, I have a function with non-integer values, called Longitude,
> which is defined in terms of the variable t. I just want to plot
> Longitude modulo 360 for a range of values of t: that is, for every
> value of t, plot the integer-AND-fraction remainder after dividing
> Longitude by 360.
> 
> But Python (in Sage) apparently won't let me use the int function or the
> // operator on functions defined in terms of a variable: I get a "cannot
> evaluate symbolic expression numerically" TypeError. 

That's an issue with Sage itself, probably sympy. Python the language 
doesn't natively understand symbolic expressions, that's added by sympy, 
so you may need to ask some sympy experts.

It may help if you show the actual code you are using, and the full 
traceback generated by the error. When I try something similar, I get a 
different error message:

py> from sympy.abc import x
py> (x + 1) % 60
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for %: 'Add' and 'int'


which could mean I'm doing something different, or just a difference in 
version numbers.


> How do I do this?
> There must be a simple way to tell Python that I want it to compute the
> value of Longitude for a given value of t and then take the
> integer-and-fraction remainder from dividing by 360.

That's simple with numeric types: use the divmod function or % operator. 
But you're using some sort of symbolic library, so we need to know what 
the library is.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#70017

FromKim Plofker <kim_plofker@yahoo.com>
Date2014-04-09 22:12 -0700
Message-ID<mailman.9120.1397112461.18130.python-list@python.org>
In reply to#70009

[Multipart message — attachments visible in raw view] — view raw

Thanks!  As I recently posted in a followup message,

--------
Here's an example of what goes wrong:

t = var('t')

L(t) = t*725.5%360.0


This produces the following error message:

...
TypeError: unsupported operand type(s) for %:
'sage.symbolic.expression.Expression' and
'sage.symbolic.expression.Expression'
--------


So it looks like I've got a Sage-specific problem.  I still don't know how to fix it, but at least I understand the problem better!  

Many thanks,
Kim

________________________________
 From: Steven D'Aprano <steve@pearwood.info>
To: python-list@python.org 
Sent: Thursday, April 10, 2014 1:01 AM
Subject: Re: Plotting the integer-and-fraction remainder of a function value modulo 360
 

On Wed, 09 Apr 2014 21:32:27 -0700, Kim Plofker wrote:

> How can I get Python to represent a value of a function in degrees,
> i.e., with values between 0 and 360, by taking the (non-integer)
> function expression mod 360?
> 
> That is, I have a function with non-integer values, called Longitude,
> which is defined in terms of the variable t. I just want to plot
> Longitude modulo 360 for a range of values of t: that is, for every
> value of t, plot the integer-AND-fraction remainder after dividing
> Longitude by 360.
> 
> But Python (in Sage) apparently won't let me use the int function or the
> // operator on functions defined in terms of a variable: I get a "cannot
> evaluate symbolic expression numerically" TypeError. 

That's an issue with Sage itself, probably sympy. Python the language 
doesn't natively understand symbolic expressions, that's added by sympy, 
so you may need to ask some sympy experts.

It may help if you show the actual code you are using, and the full 
traceback generated by the error. When I try something similar, I get a 
different error message:

py> from sympy.abc import x
py> (x + 1) % 60
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for %: 'Add' and 'int'


which could mean I'm doing something different, or just a difference in 
version numbers.


> How do I do this?
> There must be a simple way to tell Python that I want it to compute the
> value of Longitude for a given value of t and then take the
> integer-and-fraction remainder from dividing by 360.

That's simple with numeric types: use the divmod function or % operator. 
But you're using some sort of symbolic library, so we need to know what 
the library is.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web