Lab 3: Secant and Tangent Lines



1a. To define a function in SageMath, you write f(x) = .... SageMath has built-in function names, like sin and cos. For a list of commands, please see the Sage Commands page. Note that capialization is important. After defining a function, you can evaluate it at a particular number by writing f(##), where “##” is the number you wish to evaluate. Then, select the “Evaluate” button. If you want a decimal approximation, write N(...). For example, if I want to define \( f(x) = \cos(x) \) and evaluate \( f(3) \) with a decimal approximation, I would write

f(x)=cos(x)
N(f(3))

Use the SageMath cell below to define the function assigned in your lab report and evaluate the function at the number assigned in your lab report.  


Name:
1b. The symbol / denotes division; for example, \( \pi/3 \) is entered as pi/3. The symbol ^ denotes exponentiation; for example, \( 2^3 \) is entered as 2^3. If you want to take \(n\)-th roots, you can write this as ^(1/n). For example, \( \sqrt[5]{3} \) is entered as 3^(1/5). SageMath uses the symbol * for multiplication. It is important to remember that in contrast to regular math notation the multiplication symbol * is not optional in SageMath: that is, anytime you want to multiply two quantities you must use the symbol *. Thus, to enter the expression \(5x\), you would write 5*x. Use the SageMath cell below to define the function assigned in your lab report and evaluate the function at the number assigned in your lab report.


Name:
1c. You can define multiple functions at once, and compose functions. For example, if I have defined \( f(x) \) and \( g(x) \) already, I can evaluate \( (f \circ g)(3) \) by entering f(g(3)). Use the SageMath cell below to define the functions assigned in your lab report and evaluate the composition at the number assigned in your lab report.


Name:

1d. SageMath can plot functions. For example, to graph the function \( f(x) = x^2 + 2x + 7 \) for \(-5 \le x \le 5\), we enter the following command:

f(x)=x^2+2*x+7
plot(f(x),-5,5)

We can also graph multiple functions at once. For example, suppose we want to graph \( f(x) = x^2 + 2x + 7 \) and \( g(x) = 4 \sin(3x) \) on \(-5 \le x \le 5\), we would enter:

f(x)=x^2+2*x+7
g(x)=4*sin(3*x)
plot([f(x),g(x)],-5,5)

Use the SageMath cell below to define the functions assigned in your lab report and plot the functions in the interval assigned in your lab report.


Name:
Skip to toolbar