%load_ext sage
a = 1/2 + 1/3
a
5/6
# view(a) view に相当するものは?
from IPython.display import display, Math
def my_show(obj): return display(Math(latex(obj)))
#y = 1 / (x^2+1)
my_show(a)
x = var('x')
# f = x^3 -x^2 - 2*x
f = x**3 -x**2 - 2*x
#view(f)
f
x^3 - x^2 - 2*x
my_show(f)
factor(f)
(x + 1)*(x - 2)*x
from IPython.display import display, Image
plot(f, -2.5, 2.5, figsize=4).save("fig.png")
display(Image('fig.png'))
df = diff(f, x); df
3*x^2 - 2*x - 2
my_show(df)
sol = solve(df, x); sol
[x == -1/3*sqrt(7) + 1/3, x == 1/3*sqrt(7) + 1/3]
my_show(sol)
plot(df, [x,-2.5,2.5], figsize=4).save('fig.png')
display(Image('fig.png'))
print find_root(df, -2, 0), find_root(df, 0, 2)
-0.548583770355 1.21525043702
Test $\alpha+\beta+\gamma$
from IPython.display import display, Math
def my_show(obj): return display(Math(latex(obj)))
y = 1 / (x^2+1)
my_show(y)
#from IPython.display import Math
Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title('A simple chirp');
sphere().save('fig3D.png')
#display(Image('fig3D.png'))
import os
os.system('convert -resize 350x fig3D.png fig3Ds.png')
display(Image('fig3Ds.png'))