Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168733
Image: ubuntu2004

Basic examples of Sage

Multiplying Two Numbers

245365768\displaystyle 24536*5768

24536*5768
141523648

Evaluating Sine

sinπ2\displaystyle \sin \frac {\pi}2

sin(pi/2)
1

Evaluating Natural Logarithm

ln2\displaystyle \ln 2

log(2)
log(2)

Finding a Numerical Approximation to Natural Logarithm

ln2\displaystyle \ln 2

n(log(2))
0.693147180559945

Finding a Limit

limx0sinxx\displaystyle \lim_{x \to 0} \frac {\sin x}x

limit(sin(x)/x, x=0)
1

Evaluating a Sum

15n2+1\displaystyle \sum_1^5 \sqrt{n^2 +1}

sum(sqrt(n^2 +1) for n in [1..5])
sqrt(2) + sqrt(5) + sqrt(10) + sqrt(17) + sqrt(26)

Finding a Numerical Approximation to a Sum

15n2+1\displaystyle \sum_1^5 \sqrt{n^2 +1}

n(sum(sqrt(n^2 +1) for n in [1..5]))
16.0346843392517

Finding the Derivative of a Function of One Variable

ddx[sin(x2+6x2)]\displaystyle \frac d{dx} [\sin (x^2 + 6x - 2)]

diff(sin(x^2 + 6*x - 2), x)
2*(x + 3)*cos(x^2 + 6*x - 2)

Finding the Indefinite Integral of a Function of One Variable

lnxdx\displaystyle \int \ln x\, dx

integral(ln(x), x)
x*log(x) - x

Finding the Definite Integral of a Function of One Variable

35lnxdx\displaystyle \int_3^5 \ln x\, dx

integral(ln(x), x, 3, 5)
-3*log(3) + 5*log(5) - 2

Finding a Numerical Approximation to a Definite Integral of a Function of One Variable

35lnxdx\displaystyle \int_3^5 \ln x\, dx

n(integral(ln(x), x, 3, 5))
2.75135269616617

Plotting the Graph of a Function of One Variable

f(x)=4x6x23+2\displaystyle f(x) = 4x - 6x^{\frac 23} + 2

x = var('x') plot(4*x - 6*((x^2)^(1/3)) + 2, (x,-5,5))

Plotting the Graphs of Two Functions of One Variable

The graph of f(x)=x2\displaystyle f(x) = x^2 is in blue.

The graph of g(x)=cosx\displaystyle g(x) = - \cos x is in red.

x = var('x') P = plot(x^2, (x,-5,5)) Q = plot(-cos(x), (x,-5,5), color='red') P + Q

Plotting the Graph of a Function of Two Variables

f(x,y)=x2+y29\displaystyle f(x, y) = x^2 + \frac {y^2}9

x, y = var('x,y') plot3d(x^2 + (1/9)*y^2, (x,-4,4), (y,-6,6), aspect_ratio=1)

Plotting the Graphs of Two Functions of Two Variables

The graph of f(x,y)=x2+y2\displaystyle f(x, y) = x^2 + y^2 is in blue.

The graph of g(x,y)=2x+3y\displaystyle g(x, y) = 2x + 3y is in green.

x, y = var('x,y') P = plot3d(2*x + 3*y, (x,-2,2), (y,-2,2), color='green') Q = plot3d(x^2 + y^2, (x,-2,2), (y,-2,2)) P + Q

Plotting a Surface in R3\mathbb{R}^3

x29y24+2z=1\displaystyle \frac {x^2}9 - \frac {y^2}4 + 2z = 1

x, y, z = var('x,y,z') implicit_plot3d((1/9)*x^2 - (1/4)*y^2 + 2*z==1, (x, -30, 30), (y, -30,30), (z, -30,30), aspect_ratio=1)

Plotting a Function in Polar Coordinate

r=1+cosθr = 1 + \cos\theta

polar_plot(1 + cos(x), (x, 0, 2*pi), aspect_ratio=1, color='red')

Plotting a Vector-Valued Function in R3\mathbb{R}^3

r(t)=(cost,sint,t)\displaystyle r(t) = (\cos t, \sin t, t)

t = var('t') parametric_plot3d((cos(t), sin(t), t), (t,0,4*pi), color='purple', aspect_ratio=1)