[sage-cloud]: unable to convert x to an integer

920 views
Skip to first unread message

Андрей Ширшов

unread,
Jun 8, 2014, 12:40:42 PM6/8/14
to sage-s...@googlegroups.com
Hi!
I tried this example in SMC: http://cs613429.vk.me/v613429802/ce70/vEsYiuWxR4c.jpg
When I just evaluate values all works fine:

[1+cos(fibonacci(floor(tan((abs(alpha+pi/2)^0.22))))) for alpha in srange(-pi/2, pi/2, pi/50, include_endpoint= True)]

But when I try to create polar_plot, I get an error message:

alpha=var('alpha')
polar_plot
((1+cos(fibonacci(tan((abs(alpha+pi/2)^0.22))))), (alpha, -3*pi/2, pi/2))

Error in lines 2-2
Traceback (most recent call last):
  File "/projects/7243d055-0edb-400d-978c-4845eb30b0c5/.sagemathcloud/sage_server.py", line 734, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "", line 2, in fibonacci
  File "/usr/local/sage/sage-6.2.rc0/local/lib/python2.7/site-packages/sage/combinat/combinat.py", line 502, in fibonacci
    n = ZZ(n)
  File "parent.pyx", line 1070, in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:8858)
  File "coerce_maps.pyx", line 223, in sage.structure.coerce_maps.NamedConvertMap._call_ (sage/structure/coerce_maps.c:5442)
  File "expression.pyx", line 862, in sage.symbolic.expression.Expression._integer_ (sage/symbolic/expression.cpp:6113)
TypeError: unable to convert x (=floor(tan(abs(1/2*pi + alpha)^0.220000000000000))) to an integer

What's wrong?
Thanks in advance, Andrei.

Андрей Ширшов

unread,
Jun 8, 2014, 1:34:49 PM6/8/14
to sage-s...@googlegroups.com
Sorry, I forgot floor in polar_plot. But result is the same.

alpha=var('alpha')
polar_plot
((1+cos(fibonacci(floor(tan((abs(alpha+pi/2)^0.22)))))), (alpha, -pi/2, pi/2))

воскресенье, 8 июня 2014 г., 20:40:42 UTC+4 пользователь Андрей Ширшов написал:

Nils Bruin

unread,
Jun 8, 2014, 4:07:41 PM6/8/14
to sage-s...@googlegroups.com
On Sunday, June 8, 2014 9:40:42 AM UTC-7, Андрей Ширшов wrote:
TypeError: unable to convert x (=floor(tan(abs(1/2*pi + alpha)^0.220000000000000))) to an integer

The problem is that "fibonacci" isn't a symbolic function, so when you give it an argument, it wants to evaluate it to an integer immediately. The polar-plot thing never comes in:

 sage: fibonacci(floor(tan((abs(alpha+pi/2)^0.22))))

TypeError: unable to convert x (=floor(tan(abs(1/2*pi + alpha)^0.220000000000000))) to an integer

Plot functions also accept python-callables as arguments (as long as they have a way of getting their data points, they're happy), so the following does work:

sage: polar_plot(lambda alpha:(1+cos(fibonacci(floor(tan((abs(alpha+pi/2)^0.22)))))), (alpha, -pi/2, pi/2))

Alternatively, you could use the closed formula for the fibonacci sequence as a symbolic expression and work with that:

sage: fib(n)=(((1+sqrt(5))/2)^n-((1-sqrt(5))/2)^n)/sqrt(5)
sage: polar_plot((1+cos(fib(floor(tan((abs(alpha+pi/2)^0.22)))))), (alpha, -pi/2, pi/2))

Андрей Ширшов

unread,
Jun 10, 2014, 2:30:30 AM6/10/14
to sage-s...@googlegroups.com
Hi!
Thank you very much for your answer!
As for Fibonacci function this task proved more difficult than expected. Wolfram Aplha used so called quasi-sine Fibonacci function.
More information about this function you can get on http://www.student.oulu.fi/~taneliha/Phi6/1/The_%F4golden%F6_hyperbolic_models_of_Universe.pdf (page 165).
Also there is there is very similar state on Russian: http://www.trinitas.ru/rus/doc/0232/004a/02320034.htm
The task solution is the following:
gold_ratio = (1+sqrt(5))/2
sFb
(x) = (gold_ratio^(x) - (gold_ratio^(-x))*cos(pi*x))/sqrt(5)
r
(alpha) = 1 + cos(sFb(tan((abs(alpha+pi/2))^0.22)))
polar_plot
(r(alpha), (alpha, -1.5*pi, 0.5*pi))
The result plot is in attachment.
Thanks,
Andrei.

понедельник, 9 июня 2014 г., 0:07:41 UTC+4 пользователь Nils Bruin написал:
Image 003.png

Vladyslav Grynko

unread,
Jun 6, 2018, 11:49:16 AM6/6/18
to sage-support
Holy shit. 
I made original graph in wolframalpha 4 years ago.
Tried to reproduce it recently, but did not recall precise combination of functions.
So, just googled "wolfram fibonacci 0.22" without braces and so, I'm here.

Thank you. XD

вівторок, 10 червня 2014 р. 09:30:30 UTC+3 користувач Андрей Ширшов написав:
Reply all
Reply to author
Forward
0 new messages