Home ->Getting Started -> Functions -> Functions Math

STOP HERE

EXAMPLES ON MY SAGE PAGE: Functions in Sage


Here we are looking at Math Functions. They are two types: built-in or user defined. (See also: Functions Programming and Commands.)

Definition: A mathematical function is a function that has 1, 2, 3 or more independent variables. You must declare each of the independent variables using the command var before defining or using your function. When you substitute values (numbers) for these variables, the function yields a value.

(A built-in math function has no options and one parameter. For example, cos(x) is a built-in math function. See list and use at bottom of this page.)

A user-defined math function can be defined as explicit: f(x)=3x^2 or vector-parametric: r=vector((sin(t),cos(t),t)). It can also be used as implicit: x^2+y^2==0


  • Example 1
    # You must declare the variables used in your functions
    #Here we define a explicit (regular) function f(x) with one independent variable x and then evaluate it at x=4.
    var('x')
    f(x)=3*x*sqrt(x)
    a=f(4)
    print a
    Result:
    24

  • Example 2
    #Look carefully at this. x is the variable in the function. w is just a "variable name". We need to declare both.
    #Here we define a explicit (regular) function f(x) with one independent variable x, a constant w and then evaluate it at x=4.
    var('x w')
    f(x)=w*x*sqrt(x)
    a=f(4)
    print a
    Result:
    8*w

  • Example 3

    #Notice that there is no r(t) at left. There is just r. But with explicit functions you must write f(x).
    #(I think this means you cannot have "constants" in your vector-parametric function.)
    #Notice the double parenthesis around the vector-parametric function.
    var('t')
    r=vector((cos(t),sin(t),t))
    a=f(x=4)
    print a

    Result:
    [-4, 0, 4]

Built-in Math Functions in Sage

Function

Returns the ****  of the argument

abs(x) absolute value
sqrt(x) square root
exp(x)  e^x
log(x) natural logarithm
log(x,10) logarithm base 10
sin(x) sine
cos(x) cosine
tan(x) tangent
asin(x) arcsine
acos(x) arccosine
atan(x) arctangent
cosh(x) hyperbolic cosine
coth(x) hyperbolic cotangent
ceil(x) ceiling
floor(x) floor
int(x) integer part
round(x) rounds to whole number
random() random number in the interval [0, 1)


Pages about Types of Math Functions and Using them in Sage
blank15.png

EXAMPLES ON MY SAGE PAGE: Functions in Sage


Here we are looking at Math Functions. They are two types: built-in or user defined. (See also: Functions Programming and Commands.)

Definition: A mathematical function is a function that has 1, 2, 3 or more independent variables. You must declare each of the independent variables before defining or using your function. When you substitute values (numbers) for these variables, the function yields a value.

(A built-in math function has no options and one parameter. For example, cos(x) is a built-in math function. See list and use at bottom of this page.)

A user-defined math function can be defined as explicit: f(x)=3x^2 or vector-parametric: r=vector((sin(t),cos(t),t)). It can also be used as implicit: x^2+y^2==0


  • Example 1
    # You must declare the variables used in your functions
    #Here we define a explicit (regular) function f(x) with one independent variable x and then evaluate it at x=4.
    var('x')
    f(x)=3*x*sqrt(x)
    a=f(4)
    print a
    Result:
    24

  • Example 2
    #Look carefully at this. x is the variable in the function. w is just a "variable name". We need to declare both.
    #Here we define a explicit (regular) function f(x) with one independent variable x, a constant w and then evaluate it at x=4.
    var('x w')
    f(x)=w*x*sqrt(x)
    a=f(4)
    print a
    Result:
    8*w

  • Example 3

    #Notice that there is no r(t) at left. There is just r. But with explicit functions you must write f(x).
    #(I think this means you cannot have "constants" in your vector-parametric function.)
    #Notice the double parenthesis around the vector-parametric function.
    var('t')
    r=vector((cos(t),sin(t),t))
    a=f(x=4)
    print a

    Result:
    [-4, 0, 4]

Built-in Math Functions in Sage

Function

Returns the ****  of the argument

abs(x) absolute value
sqrt(x) square root
exp(x)  e^x
log(x) natural logarithm
log(x,10) logarithm base 10
sin(x) sine
cos(x) cosine
tan(x) tangent
asin(x) arcsine
acos(x) arccosine
atan(x) arctangent
cosh(x) hyperbolic cosine
coth(x) hyperbolic cotangent
ceil(x) ceiling
floor(x) floor
int(x) integer part
round(x) rounds to whole number
random() random number in the interval [0, 1)

Reference: Sage_for_Newbies, pp.43 (Ted Kosan)


Keywords: functions, mathematics, variables, explicit, implicit, parametric, vector, vector-parametric