Shared2018-doc101-10-094410.sagewsOpen in CoCalc
2*10

20
parametric_plot((sin(3*x),cos(5*x)),(x,0,2*pi))

def pair(x):
if x%2==0:
return True
return False
def syracuse(x):
if pair(x):
return x//2
else:
return 3*x+1
def suite_de_syracuse(u,n):
for i in range(1,n):
u=syracuse(u)
print(u)
return u
def suite_de_syracuse_1(u):
n=0
while u!=1:
n+=1
u=syracuse(u)
return n
suite_de_syracuse_1(1000)

111
var('x,y,z')
f=(x+y+z)^4
fg=f.expand()
print(fg)

(x, y, z) x^4 + 4*x^3*y + 6*x^2*y^2 + 4*x*y^3 + y^4 + 4*x^3*z + 12*x^2*y*z + 12*x*y^2*z + 4*y^3*z + 6*x^2*z^2 + 12*x*y*z^2 + 6*y^2*z^2 + 4*x*z^3 + 4*y*z^3 + z^4
f.coefficient(x^2*y^2)

0
p=3*x^2*y+7*x*y^2+y^3
p.coefficient(x^2*y)

3
fg1=str(fg).split(' + ')
for d in fg1:
r=1
try:
int(d[0])
r=int(d.split('*')[0])
except:
pass
print(r)

1 4 4 6 6 4 4 1 4 4 1 12 1 12 4 4 6 6 1 12 6 6 4 4 4 4 1
def nb_chif_coef_dev(u):
var('x,y,z')
n=0
while True:
n+=1
f=(x+y+z)^n
fd=str(f.expand()).split(' + ')
for d in fd:
try:
int(d[0])
if len(d.split('*')[0])>u-1:
return n
except:
pass
nb_chif_coef_dev(30)

65
def champernowne():
c='0.'
n=0
while True:
n+=1
c+=str(n)
if '888' in c:
return c.find('888')-1

champernowne()

166
g='1235689478'
g[-3:]

'478'
def test_euler(n,p):
if ((n^((p-1)/2)-1)/p).is_integral() or ((n^((p-1)/2)+1)/p).is_integral():
return True
return False

def enigme_euler(p):
te = False
for n in (2,3,5):
if test_euler(n,p):
te=True
else:
te=False
break
if te and not is_prime(p):
return True
return False
p=3
#enigme_euler(1729)
while not enigme_euler(p):
p+=2
print(p)

1729
-1%217
((2^((217-1)/2)-1)/217).is_integral()

216 True
var('x,a')
f=x^2-x-1
r=solve(f,x)
print(str(r[1]).split('==')[1])
t=((1+sqrt(5))/2)^(2*a/pi)
#t2=((1+sqrt(5))/2)^(2*a/pi)
print(t)
polar_plot(t,(a,0,100*pi))

(x, a) 1/2*sqrt(5) + 1/2 (1/2*sqrt(5) + 1/2)^(2*a/pi)
help(polar_plot)

Help on function polar_plot in module sage.plot.plot: polar_plot(*args, **kwds) polar_plot takes a single function or a list or tuple of functions and plots them with polar coordinates in the given domain. This function is equivalent to the :func:plot command with the options polar=True and aspect_ratio=1. For more help on options, see the documentation for :func:plot. INPUT: - funcs - a function - other options are passed to plot EXAMPLES: Here is a blue 8-leaved petal:: sage: polar_plot(sin(5*x)^2, (x, 0, 2*pi), color='blue') Graphics object consisting of 1 graphics primitive .. PLOT:: g = polar_plot(sin(5*x)**2, (x, 0, 2*pi), color='blue') sphinx_plot(g) A red figure-8:: sage: polar_plot(abs(sqrt(1 - sin(x)^2)), (x, 0, 2*pi), color='red') Graphics object consisting of 1 graphics primitive .. PLOT:: g = polar_plot(abs(sqrt(1 - sin(x)**2)), (x, 0, 2*pi), color='red') sphinx_plot(g) A green limacon of Pascal:: sage: polar_plot(2 + 2*cos(x), (x, 0, 2*pi), color=hue(0.3)) Graphics object consisting of 1 graphics primitive .. PLOT:: g = polar_plot(2 + 2*cos(x), (x, 0, 2*pi), color=hue(0.3)) sphinx_plot(g) Several polar plots:: sage: polar_plot([2*sin(x), 2*cos(x)], (x, 0, 2*pi)) Graphics object consisting of 2 graphics primitives .. PLOT:: g = polar_plot([2*sin(x), 2*cos(x)], (x, 0, 2*pi)) sphinx_plot(g) A filled spiral:: sage: polar_plot(sqrt, 0, 2 * pi, fill=True) Graphics object consisting of 2 graphics primitives .. PLOT:: g = polar_plot(sqrt, 0, 2 * pi, fill=True) sphinx_plot(g) Fill the area between two functions:: sage: polar_plot(cos(4*x) + 1.5, 0, 2*pi, fill=0.5 * cos(4*x) + 2.5, fillcolor='orange') Graphics object consisting of 2 graphics primitives .. PLOT:: g = polar_plot(cos(4*x) + 1.5, 0, 2*pi, fill=0.5 * cos(4*x) + 2.5, fillcolor='orange') sphinx_plot(g) Fill the area between several spirals:: sage: polar_plot([(1.2+k*0.2)*log(x) for k in range(6)], 1, 3 * pi, fill={0: [1], 2: [3], 4: [5]}) Graphics object consisting of 9 graphics primitives .. PLOT:: g = polar_plot([(1.2+k*0.2)*log(x) for k in range(6)], 1, 3 * pi, fill={0: [1], 2: [3], 4: [5]}) sphinx_plot(g) Exclude points at discontinuities:: sage: polar_plot(log(floor(x)), (x, 1, 4*pi), exclude=[1..12]) Graphics object consisting of 12 graphics primitives .. PLOT:: g = polar_plot(log(floor(x)), (x, 1, 4*pi), exclude=list(range(1,13))) sphinx_plot(g)