Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004
ww=4/3
vv=acos(0)
print ww, vv
4/3 1/2*pi
show(ww), show(vv)
\frac{4}{3}
\frac{1}{2} \, \pi
(None, )
var('X,y,z')
(X, y, z)
f(x)=exp(-x)*sin(x)
g(x,y)=sqrt(x^2+y^2); g.show()
\left( x, y \right) \ {\mapsto} \ \sqrt{x^{2} + y^{2}}
h(x,y,z)=atan(g(x,y)/z)
h2(x,y,z)=f(x)*g(x,y)
print(h2)
(x, y, z) |--> sqrt(x^2 + y^2)*e^(-x)*sin(x)
show(h2)
\left( x, y, z \right) \ {\mapsto} \ \sqrt{x^{2} + y^{2}} e^{-x} \sin\left(x\right)
h2(1,1,1)
sqrt(2)*e^(-1)*sin(1)
h2(1,1,1).n()
0.437783774515160
pi .n(1000)
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127
eqn=[(y+x)/(2*y-x)==1]
solve(eqn,x)
[x == 1/2*y]
f
x |--> e^(-x)*sin(x)
f.plot()
f.plot(-3/2,5,color='red',thickness=3)
h(x,2,2).plot(x,-1,1)
h(2,2,z).plot((y,-1,1),color='red',thickness=3)
f(x).plot()+g(x,0.1).plot(color='red')
fig1=f(x).plot()+g(x,0.1).plot(color='red')
fig2=h(x,1,1).plot(color='green')
fig1+fig2
fig1 += text('Eje X',(0.9,-0.3))
fig1 += text('EjeY', (-0.2,1.0))
fig1
h1(x)=sin(2*x); h2=cos(x)
parametric_plot( (h1(x),h2(x)), (x,0,2*pi),figsize=[4,4])
__main__:7: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
i(t)=sin(t)*(exp(cos(t))-2*cos(4*t)-sin(t/12.)^5);i.show()
t \ {\mapsto}\ -{(\sin\left(0.0833333333333333 \, t\right)^{5} - e^{\cos\left(t\right)} + 2 \, \cos\left(4 \, t\right))} \sin\left(t\right)
j(t)=cos(t)*(exp(cos(t))-2*cos(4*t)-sin(t/12.)^5);j.show()
t \ {\mapsto}\ -{(\sin\left(0.0833333333333333 \, t\right)^{5} - e^{\cos\left(t\right)} + 2 \, \cos\left(4 \, t\right))} \cos\left(t\right)
parametric_plot((i(t),j(t)), (t,0,12*pi),plot_points=500)
var('x,y')
(x, y)
eqn=[(x^2+y^2)==1]
solve(eqn,y)
[y == -sqrt(-x^2 + 1), y == sqrt(-x^2 + 1)]
e(x)=-sqrt(-x^2 + 1);r(x)=sqrt(-x^2 + 1)
e.plot(color='red')+ r.plot(color='blue')
h1(t)=sin(t);h1.show()
t \ {\mapsto}\ \sin\left(t\right)
h2(t)=cos(t);h2.show()
t \ {\mapsto}\ \cos\left(t\right)
parametric_plot ((h1(t),h2(t)),(0,2*pi), plot_points=500)
x,y=var('x,y') f=exp(-(x^2+y^2)) plot_vector_field(f.gradient(), (x,-2,2), (y,-2,2))
f1(x)=sin(x)^2; f2(x)=exp(x) g1(x)=f1(f2(x));g1.show()
x \ {\mapsto}\ \sin\left(e^{x}\right)^{2}
g2(x)=f2(f1(x));g2.show()
x \ {\mapsto}\ e^{\sin\left(x\right)^{2}}
g1(x).plot()+g2(x).plot(color="green")
g1(x).diff()
2*e^x*sin(e^x)*cos(e^x)
g1(x).diff().show()
2 \, e^{x} \sin\left(e^{x}\right) \cos\left(e^{x}\right)
g2(x).diff() g2(x).diff().show()
2 \, e^{\sin\left(x\right)^{2}} \sin\left(x\right) \cos\left(x\right)
f(x)=e^(-x)*sin(x);f
x |--> e^(-x)*sin(x)
f(x).integrate().show()
-\frac{1}{2} \, {(\sin\left(x\right) + \cos\left(x\right))} e^{-x}
g1(x)
sin(e^x)^2
g1(x).integrate()
1/2*x - 1/2*integrate(cos(2*e^x), x)
g1(x).integrate().show()
\frac{1}{2} \, x - \frac{1}{2} \, \int \cos\left(2 \, e^{x}\right)\,{d x}
numerical_integral(g1(x),-1,1)
(1.1440261602989841, 1.2701241839374423e-14)
numerical_integral(f(x),-1,1)
(-0.66349366663124132, 1.282003047907945e-14)
f(x)=exp(-x)*sin(x) f(x).taylor(x,pi,5)
-1/30*(pi - x)^5*e^(-pi) + 1/3*(pi - x)^3*e^(-pi) + (pi - x)^2*e^(-pi) + (pi - x)*e^(-pi)
f(x).taylor(x,n(pi),5)
0.00144046394213*(x - 3.14159265359)^5 - (9.7892701402e-19)*(x - 3.14159265359)^4 - 0.0144046394213*(x - 3.14159265359)^3 + 0.0432139182638*(x - 3.14159265359)^2 - 0.0432139182638*x + 0.13576052815
f(x).plot(pi/2,3*pi/2)+(f(x).taylor(x,n(pi),5)).plot((pi/2,3*pi/2),color='red')
f(x).find_root(3,5); f(x).find_root(5,10)
3.1415926535897931 9.4247779607693793
f(x)=x-cos(x);plot(f)
f(x).find_root(0,1)
0.7390851332151559
h1(x)=sin(2*x);h2(x)=cos(x);h3(x)=cos(3*x) parametric_plot3d((h1(x),h2(x),h3(x)),(0,2*pi),rgbcolor=(0,0.5,0.5),thickness=3)
g1(x,y)=x*cos(y);g2(x,y)=y*cos(x);g3(x,y)=x^2+y^2; parametric_plot3d((g1(x,y),g2(x,y),g3(x,y)),(x,0,pi),(y,0,pi),mesh=true, color='green')
f(x,y)=x*exp(-(x^2+y^2)) plot3d(f(x,y),(x,-2,2),(y,-2,2),mesh=true,rgbcolor='red',opacity=0.8)
var('z') fig1a=implicit_plot3d((2*z^2-x^2-y^2)*exp(-1.2*(x^2+y^2+z^2)),(x,-2,2),(y,-2,2),(z,-3,3),contour=(0.3,0.1,0.05),opacity=0.6,color='red') fig1b=implicit_plot3d((2*z^2-x^2-y^2)*exp(-1.2*(x^2+y^2+z^2)),(x,-2,2),(y,-2,2),(z,-3,3),contour=(-0.3,-0.1,-0.05),opacity=0.6,color='blue')
fig1a+fig1b
fig1a=implicit_plot3d((x^2-y^2)*exp(-1.2*(x^2+y^2+z^2)),(x,-2,2),(y,-2,2),(z,-3,3),contour=(0.3,0.1,0.05),opacity=0.6,color='green') fig1b=implicit_plot3d((x^2-y^2)*exp(-1.2*(x^2+y^2+z^2)),(x,-2,2),(y,-2,2),(z,-3,3),contour=(-0.3,-0.1,-0.05),opacity=0.6,color='yellow') fig1a+fig1b
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_2.py", line 7, in <module> fig1a=implicit_plot3d((x**_sage_const_2 -y**_sage_const_2 )*exp(-_sage_const_1p2 *(x**_sage_const_2 +y**_sage_const_2 +z**_sage_const_2 )),(x,-_sage_const_2 ,_sage_const_2 ),(y,-_sage_const_2 ,_sage_const_2 ),(z,-_sage_const_3 ,_sage_const_3 ),contour=(_sage_const_0p3 ,_sage_const_0p1 ,_sage_const_0p05 ),opacity=_sage_const_0p6 ,color='green') NameError: name 'y' is not defined
contour_plot((y^2-1)^2+(x-y)^2,(x,-4,4),(y,-2,2),plot_points=200, contours=(0.01,1,2,4,7),cmap='prism', fill=false).show(aspect_ratio=1)
plot3d((y^2-1)^2+(x-y)^2,(x,-4,4),(y,-2,2),(0,45))
f(x,y,z)=-5*x^6-15*x^4*y^2-15*x^2*y^4-5*y^6+90*x^4*z^2+180*x^2*y^2*z^2+90*y^4*z^2-120*x^2*z^4-120*y^2*z^4+16*z^6
d2xf=f(x,y,z).diff(x,2);show(d2xf)
-150 \, x^{4} - 180 \, x^{2} y^{2} + 1080 \, x^{2} z^{2} - 30 \, y^{4} + 360 \, y^{2} z^{2} - 240 \, z^{4}
d2yf=f(x,y,z).diff(y,2);show(d2yf)
-30 \, x^{4} - 180 \, x^{2} y^{2} + 360 \, x^{2} z^{2} - 150 \, y^{4} + 1080 \, y^{2} z^{2} - 240 \, z^{4}
d2zf=f(x,y,z).diff(z,2);show(d2zf)
180 \, x^{4} + 360 \, x^{2} y^{2} - 1440 \, x^{2} z^{2} + 180 \, y^{4} - 1440 \, y^{2} z^{2} + 480 \, z^{4}
d2xf+d2yf+d2zf
0
f(x,y,z)=x^4*y^4*z^4+12*x^3*y^2+12*y^3*z^2+12*x^2*z^3
d1xf=f(x,y,z).diff(x,1);show(d1xf) d1yf=f(x,y,z).diff(y,1);show(d1yf) d1zf=f(x,y,z).diff(z,1);show(d1zf) d2xf=f(x,y,z).diff(x,2);show(d2xf) d2yf=f(x,y,z).diff(y,2);show(d2yf) d2zf=f(x,y,z).diff(z,2);show(d2zf) d2xyf=d1xf.diff(y,1);show(d2xyf) d2xzf=d1xf.diff(z,1);show(d2xzf) d2yzf=d1yf.diff(z,1);show(d2yzf)
4 \, x^{3} y^{4} z^{4} + 36 \, x^{2} y^{2} + 24 \, x z^{3}
4 \, x^{4} y^{3} z^{4} + 24 \, x^{3} y + 36 \, y^{2} z^{2}
4 \, x^{4} y^{4} z^{3} + 36 \, x^{2} z^{2} + 24 \, y^{3} z
12 \, x^{2} y^{4} z^{4} + 72 \, x y^{2} + 24 \, z^{3}
12 \, x^{4} y^{2} z^{4} + 24 \, x^{3} + 72 \, y z^{2}
12 \, x^{4} y^{4} z^{2} + 72 \, x^{2} z + 24 \, y^{3}
16 \, x^{3} y^{3} z^{4} + 72 \, x^{2} y
16 \, x^{3} y^{4} z^{3} + 72 \, x z^{2}
16 \, x^{4} y^{3} z^{3} + 72 \, y^{2} z
g(x,y)=sin(x^2+y^2); g.show()
\left( x, y \right) \ {\mapsto} \ \sin\left(x^{2} + y^{2}\right)
gfig=plot3d(g(x,y),(x,-1,1),(y,-1,1),mesh=True,rgbcolor='purple',opacity=8);gfig
h(x,y)=taylor(taylor(g(x,y),x,0,2),y,0,2);h
(x, y) |--> x^2 + y^2
hfig = plot3d (h(x,y),(x,-1,1),(y,-1,1),mesh=true,rgbcolor='red',opacity=0.8); hfig
gfig+hfig
var('a,b,c,d,e,f')
(a, b, c, d, e, f)
eqns= [a==d,a==d,b==e,4*b+c==2*d+2*e+f,2*c==f,-a-b==-d-f]
sol=solve(eqns,a,b,c,d,e,f);sol
[[a == 3, b == 4, c == 2, d == 3, e == 4, f == 4]]
eqns= [a==d,a==d,b==e,4*b+c==2*d+2*e+f,2*c==f,-a-b==-d-f,a==3] sol=solve(eqns,a,b,c,d,e,f);sol
[[a == 3, b == 4, c == 2, d == 3, e == 4, f == 4]]
coefmat=[[1,0,0,-1,0,0],[0,1,0,0,-1,0],[0,4,1,-2,-2,-1],[0,0,2,0,0,-1],[-1,-1,0,1,0,1],[1,0,0,0,0,0]] termind=[0,0,0,0,0,3] from numpy import linalg sol=linalg.solve(coefmat,termind);sol
array([ 3., 4., 2., 3., 4., 4.])
sol[0]
3.0
var('a,b,c,d,e,f') eqns = [a==c,6*a==3*c+e+2*f,a+4*b==2*c+2*d+e+f,b==d] sol=solve(eqns,a,b,c,d,e,f);sol
[[a == 2/3*r1 + 1/3*r2, b == 5/6*r1 + 2/3*r2, c == 2/3*r1 + 1/3*r2, d == 5/6*r1 + 2/3*r2, e == r2, f == r1]]
var('a,b,c,d,e,f') eqns = [2*a==2*c,6*a==3*c+e+2*f,a+4*b==2*c+2*d+e+f,b==d,e==3,f==6] sol=solve(eqns,a,b,c,d,e,f);sol
[[a == 5, b == 7, c == 5, d == 7, e == 3, f == 6]]
data=[[0,1.03],[1,3.19],[2,5.1],[3,7.2],[4,9.1],[5,10.87]] var('a,b') model(x)=a+b*x sol=find_fit(data,model,solution_dict=true);sol
{b: 1.9722857149170498, a: 1.1509523788845293}
f(x)=model(x).substitute(sol) figdat=list_plot(data,pointsize=25) figaj=plot(f(x),(x,0,5),color='red') figdat+figaj
data=[(i,1.2*sin(0.5*i-0.2)+0.97*sin(3.*i+0.5)+0.05*normalvariate(0,1)) for i in xsrange(0,4*pi,0.2)] var('a1,a2,a3,b1,b2,b3,x')
(a1, a2, a3, b1, b2, b3, x)
model(x)=a1*sin(a2*x-a3)+b1*sin(b2*x-b3);show(model(x))
a_{1} \sin\left(a_{2} x - a_{3}\right) + b_{1} \sin\left(b_{2} x - b_{3}\right)
sol=find_fit(data,model,solution_dict=true);sol
{a3: -4.942595571136664, a1: 0.72139356333692151, b2: 0.004199964050585381, b1: -41.068861608063258, a2: 0.65847250164092275, b3: -6.2557927852325994}
g(x)=model(x).substitute(sol);g(x)
-41.0688616080633*sin(0.00419996405058538*x + 6.25579278523260) + 0.721393563336922*sin(0.658472501640923*x + 4.94259557113666)
figdat=list_plot(data) figaj=plot(g(x),(x,0,4*pi),color='red') figdat+figaj
sol=find_fit(data,model,initial_guess=[1.0,0.5,-0.2,1.0,2.9,0.4],parameters=[a1,a2,a3,b1,b2,b3],variables=[x ],solution_dict=true);sol
{a3: 0.22743332097873944, a1: 1.205892760847761, b2: 3.0014169493550185, b1: 0.97550704842879732, a2: 0.5038428039142886, b3: -0.48859791199812452}
g(x)=model(x).substitute(sol);g(x) figdat=list_plot(data) figaj=plot(g(x),(x,0,4*pi),color='red') figdat+figaj
a=['rojo','azul',100,1234,'verde',1.0e-3];a
['rojo', 'azul', 100, 1234, 'verde', 0.00100000000000000]
a[3]
1234
a[2:5]
[100, 1234, 'verde']
a[-3]
1234
a[:4]
['rojo', 'azul', 100, 1234]
a[3:]
[1234, 'verde', 0.00100000000000000]
Syntax Error: ;a
a[0:2]=[1,12];a
[1, 12, 100, 1234, 'verde', 0.00100000000000000]
a[0:2]=[];a
[100, 1234, 'verde', 0.00100000000000000]
a[1:2]=['uno','dos','tres','cuatro'];a
[100, 'uno', 'dos', 'tres', 'cuatro', 'dos', 'tres', 'cuatro', 'verde', 0.00100000000000000]
a=[1,2,3,4,1,4,9,16,1,8,27,64,1,16,81,128] A=matrix(4,4,a) b=[[1,2,3,4],[4,5,6,7,],[7,8,9,10],[8,9,10,11]] B=matrix(4,4,b)
C=matrix(8,8,b)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_22.py", line 5, in <module> exec compile(ur'C=matrix(_sage_const_8 ,_sage_const_8 ,b)' + '\n', '', 'single') File "", line 1, in <module> File "/sage/sage/local/lib/python2.6/site-packages/sage/matrix/constructor.py", line 516, in matrix raise ValueError, "Number of rows does not match up with specified number." ValueError: Number of rows does not match up with specified number.
A+B
[ 2 4 6 8] [ 5 9 15 23] [ 8 16 36 74] [ 9 25 91 139]
A-B
[ 0 0 0 0] [ -3 -1 3 9] [ -6 0 18 54] [ -7 7 71 117]
A*B
[ 62 72 82 92] [ 208 238 268 298] [ 734 834 934 1034] [1656 1882 2108 2334]
c=[2,3,4,5] C=matrix(4,c) A*C
[ 40] [ 130] [ 454] [1014]
C*A
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_3.py", line 6, in <module> exec compile(ur'C*A' + '\n', '', 'single') File "", line 1, in <module> NameError: name 'C' is not defined
D=matrix(1,4,c);D
[2 3 4 5]
D*A
[ 14 128 546 952]
A*D
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_31.py", line 4, in <module> exec compile(ur'A*D' + '\n', '', 'single') File "", line 1, in <module> File "element.pyx", line 1993, in sage.structure.element.Matrix.__mul__ (sage/structure/element.c:13683) File "coerce.pyx", line 765, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:7021) TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 4 by 4 dense matrices over Integer Ring' and 'Full MatrixSpace of 1 by 4 dense matrices over Integer Ring'
A^3
[ 1274 15660 72354 123592] [ 4646 57140 263862 451224] [ 17414 214032 987654 1690672] [ 37518 462364 2136558 3652008]
A^(-3)
[ 48105001/1265472 -27697733/843648 5048117/1265472 259627/281216] [-46218017/2530944 26732245/1687296 -4865173/2530944 -252875/562432] [ 5281771/3796416 -3043151/2530944 551903/3796416 9611/281216] [ 1868695/1687296 -1085635/1124864 197987/1687296 30871/1124864]
(A^(-3)).n()
[ 38.0134850869873 -32.8309117072523 3.98911789435088 0.923229830450614] [ -18.2611772524402 15.8432456427325 -1.92227603613513 -0.449609908397815] [ 1.39125190706182 -1.20237784794922 0.145374742915423 0.0341765760127447] [ 1.10750870031103 -0.965125561845699 0.117339814709452 0.0274442065885298]
A.determinant()
-1248
Ainv=A.inverse()
Ainv.determinant()
-1/1248
A*Ainv
[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]
Ainv*A
[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]
B.determinant()
0
B.inverse()
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_10.py", line 4, in <module> exec compile(ur'B.inverse()' + '\n', '', 'single') File "", line 1, in <module> File "matrix2.pyx", line 5038, in sage.matrix.matrix2.Matrix.inverse (sage/matrix/matrix2.c:30353) File "matrix0.pyx", line 3749, in sage.matrix.matrix0.Matrix.__invert__ (sage/matrix/matrix0.c:20886) File "matrix_rational_dense.pyx", line 652, in sage.matrix.matrix_rational_dense.Matrix_rational_dense.__invert__ (sage/matrix/matrix_rational_dense.c:8695) File "matrix_rational_dense.pyx", line 758, in sage.matrix.matrix_rational_dense.Matrix_rational_dense.__invert__main (sage/matrix/matrix_rational_dense.c:9268) File "matrix_rational_dense.pyx", line 2540, in sage.matrix.matrix_rational_dense.Matrix_rational_dense._invert_pari (sage/matrix/matrix_rational_dense.c:22306) ZeroDivisionError: input matrix must be nonsingular
A=matrix(RDF,4,4,a);A
[ 1.0 2.0 3.0 4.0] [ 1.0 4.0 9.0 16.0] [ 1.0 8.0 27.0 64.0] [ 1.0 16.0 81.0 128.0]
eigspace=A.eigenvectors_right();eigspace
([167.4973559, 2.69328085021, 0.264600757722, -10.4552375075], [-0.0305117418795 -0.651088752341 0.900358014463 0.0534991314627] [ -0.111368668075 -0.751155808589 -0.433102085938 -0.0283501801307] [ -0.41719234141 -0.0110988092326 0.0329583639551 -0.860296348024] [ -0.901452496612 0.108282982187 0.0263016195989 0.506186036745])
eigvec=eigspace[1];eigvec
[-0.0305117418795 -0.651088752341 0.900358014463 0.0534991314627] [ -0.111368668075 -0.751155808589 -0.433102085938 -0.0283501801307] [ -0.41719234141 -0.0110988092326 0.0329583639551 -0.860296348024] [ -0.901452496612 0.108282982187 0.0263016195989 0.506186036745]
eigval=eigspace[0];eigval
[167.4973559, 2.69328085021, 0.264600757722, -10.4552375075]
A*eigvec
[ -5.11063608871 -1.75356486847 0.238235412848 -0.55934612589] [ -18.6539574327 -2.0230735548 -0.11459914011 0.296407866648] [ -69.8786140877 -0.0298922103663 0.0087208080758 8.99460264547] [ -150.990909652 0.291636482328 0.00695942847519 -5.29229523718]
eigvec*diagonal_matrix(eigval)
[ -5.11063608871 -1.75356486847 0.238235412848 -0.55934612589] [ -18.6539574327 -2.0230735548 -0.11459914011 0.296407866648] [ -69.8786140877 -0.0298922103663 0.0087208080758 8.99460264547] [ -150.990909652 0.291636482328 0.00695942847519 -5.29229523718]
(A*eigvec-eigvec*diagonal_matrix(eigval)).n(10)
[ 4.0e-14 -3.6e-15 1.9e-15 2.9e-15] [ 2.1e-14 -2.7e-15 1.2e-15 -1.0e-14] [ 7.1e-14 5.6e-15 2.3e-15 -7.1e-15] [ 1.7e-13 1.0e-14 2.7e-15 -1.4e-14]