CHE315 Sample Page

1839 days ago by joel.boyd

'Below are several examples of sage utilities that you might find useful in PChem. Note that to execute a line command, you must either click "evaluate" or hit shift-enter on your keyboard.' 
       
Syntax Error:
    'Below are several examples of sage utilities that you might find
useful in PChem.
Syntax Error:
    'Below are several examples of sage utilities that you might find useful in PChem.
solve(x^2+x-6==0,x) 
       
[x == -3, x == 2]
[x == -3, x == 2]
integral(x^2,x) 
       
1/3*x^3
1/3*x^3
integral(x^2,3,8) 
       
485/3
485/3
diff(x^2+5*x,x) 
       
2*x + 5
2*x + 5
diff(x^2+5*x,x,2) 
       
2
2
diff? 
       

File: /usr/local/sage/local/lib/python2.6/site-packages/sage/calculus/functional.py

Type: <type ‘function’>

Definition: diff(f, *args, **kwds)

Docstring:

The derivative of f.

Repeated differentiation is supported by the syntax given in the examples below.

ALIAS: diff

EXAMPLES: We differentiate a callable symbolic function:

sage: f(x,y) = x*y + sin(x^2) + e^(-x)
sage: f
(x, y) |--> x*y + e^(-x) + sin(x^2)
sage: derivative(f, x)
(x, y) |--> 2*x*cos(x^2) + y - e^(-x)
sage: derivative(f, y)
(x, y) |--> x

We differentiate a polynomial:

sage: t = polygen(QQ, 't')
sage: f = (1-t)^5; f
-t^5 + 5*t^4 - 10*t^3 + 10*t^2 - 5*t + 1
sage: derivative(f)
-5*t^4 + 20*t^3 - 30*t^2 + 20*t - 5
sage: derivative(f, t)
-5*t^4 + 20*t^3 - 30*t^2 + 20*t - 5
sage: derivative(f, t, t)
-20*t^3 + 60*t^2 - 60*t + 20
sage: derivative(f, t, 2)
-20*t^3 + 60*t^2 - 60*t + 20
sage: derivative(f, 2)
-20*t^3 + 60*t^2 - 60*t + 20

We differentiate a symbolic expression:

sage: var('a x')
(a, x)
sage: f = exp(sin(a - x^2))/x
sage: derivative(f, x)
-2*e^(sin(-x^2 + a))*cos(-x^2 + a) - e^(sin(-x^2 + a))/x^2
sage: derivative(f, a)
e^(sin(-x^2 + a))*cos(-x^2 + a)/x

Syntax for repeated differentiation:

sage: R.<u, v> = PolynomialRing(QQ)
sage: f = u^4*v^5
sage: derivative(f, u)
4*u^3*v^5
sage: f.derivative(u)   # can always use method notation too
4*u^3*v^5
sage: derivative(f, u, u)
12*u^2*v^5
sage: derivative(f, u, u, u)
24*u*v^5
sage: derivative(f, u, 3)
24*u*v^5
sage: derivative(f, u, v)
20*u^3*v^4
sage: derivative(f, u, 2, v)
60*u^2*v^4
sage: derivative(f, u, v, 2)
80*u^3*v^3
sage: derivative(f, [u, v, v])
80*u^3*v^3

File: /usr/local/sage/local/lib/python2.6/site-packages/sage/calculus/functional.py

Type: <type ‘function’>

Definition: diff(f, *args, **kwds)

Docstring:

The derivative of f.

Repeated differentiation is supported by the syntax given in the examples below.

ALIAS: diff

EXAMPLES: We differentiate a callable symbolic function:

sage: f(x,y) = x*y + sin(x^2) + e^(-x)
sage: f
(x, y) |--> x*y + e^(-x) + sin(x^2)
sage: derivative(f, x)
(x, y) |--> 2*x*cos(x^2) + y - e^(-x)
sage: derivative(f, y)
(x, y) |--> x

We differentiate a polynomial:

sage: t = polygen(QQ, 't')
sage: f = (1-t)^5; f
-t^5 + 5*t^4 - 10*t^3 + 10*t^2 - 5*t + 1
sage: derivative(f)
-5*t^4 + 20*t^3 - 30*t^2 + 20*t - 5
sage: derivative(f, t)
-5*t^4 + 20*t^3 - 30*t^2 + 20*t - 5
sage: derivative(f, t, t)
-20*t^3 + 60*t^2 - 60*t + 20
sage: derivative(f, t, 2)
-20*t^3 + 60*t^2 - 60*t + 20
sage: derivative(f, 2)
-20*t^3 + 60*t^2 - 60*t + 20

We differentiate a symbolic expression:

sage: var('a x')
(a, x)
sage: f = exp(sin(a - x^2))/x
sage: derivative(f, x)
-2*e^(sin(-x^2 + a))*cos(-x^2 + a) - e^(sin(-x^2 + a))/x^2
sage: derivative(f, a)
e^(sin(-x^2 + a))*cos(-x^2 + a)/x

Syntax for repeated differentiation:

sage: R.<u, v> = PolynomialRing(QQ)
sage: f = u^4*v^5
sage: derivative(f, u)
4*u^3*v^5
sage: f.derivative(u)   # can always use method notation too
4*u^3*v^5
sage: derivative(f, u, u)
12*u^2*v^5
sage: derivative(f, u, u, u)
24*u*v^5
sage: derivative(f, u, 3)
24*u*v^5
sage: derivative(f, u, v)
20*u^3*v^4
sage: derivative(f, u, 2, v)
60*u^2*v^4
sage: derivative(f, u, v, 2)
80*u^3*v^3
sage: derivative(f, [u, v, v])
80*u^3*v^3
plot(sin(x),x,-pi,pi) 
       
diff(sin(x)) 
       
cos(x)
cos(x)
diff(cos(x)) 
       
-sin(x)
-sin(x)
integral(sin(x),x,-pi,pi) 
       
0
0
diff(3*x^2*a+y,x) 
       
6*a*x
6*a*x
a,y=var('a,y')