Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
483 views

We usually think of a function as something that takes a numerical input and yields a numerical output. But that idea just scratches of the surface. First, inputs and outputs don't have to be numbers, they can be any computer entity whatsoever. Secondly, a function doesn't have to operate on a single input, but can be defined to deal with multiple inputs. In this worksheet we look at just a few ideas that will expand your horizon as far as functions go.

We look at a few different instances of functions that show up. The first is what is called a symbolic function--one in which we give it a name but haven't defined what it does. I will create the function called fnc whose input variable is just x.

fcn=function('fcn')(x) #please notice the syntax, name is wrapped in ' marks and the variable(s) afterwards in () show(fcn) #going to add 5 to this function show(fcn+5)

Now I will work with some more familiar functions. Here comes several simple examples.

  1. The straight line f(x)=2x+3f(x)=2x+3

  2. The quadratic function, quad(x)=4x25x7quad(x)=4x^2-5x-7

  3. Now a function of 2 variables that will compute the area of a triangle. area(b,h)=bh/2area(b,h)=bh/2

f(x)=2*x+3 f(4)#evaluating at x=4 quad(x)=4*x^2-5*x-7 quad(0) b,h=var('b,h')#don't forget to declare new variables!!!!!!!!! area(b,h)=b*h/2 area(5,10)

Precalc tells us we can add functions together. sage knows this. . .

f(x)=2*x+3 quad(x)=4*x^2-5*x-7 b,h=var('b,h')#don't forget to declare new variables!!!!!!!!! area(b,h)=b*h/2 #here comes some examples 3*f(x) quad(x)-f(x) (f(x))^2 area(b,h)+quad(x)