This document is one of More SageMath Tutorials. You may edit it on github. \(\def\NN{\mathbb{N}}\) \(\def\ZZ{\mathbb{Z}}\) \(\def\QQ{\mathbb{Q}}\) \(\def\RR{\mathbb{R}}\) \(\def\CC{\mathbb{C}}\)
Calculus, plotting & interact¶
Some differentiating and plotting¶
Exercises
Let \(f(x) = x^4 + x^3 - 13 x^2 - x + 12\). Define \(f\) as a symbolic function.
sage: # edit here
Plot \(f\) on the domain \(-4.5 \leq x \leq 3.5\).
sage: # edit here
Find numerical approximations for the critical values of \(f\) by taking the derivative of \(f\) and using the
find_root
method. (Hint: plot the derivative.)sage: # edit here
Find numerical approximations for the critical values of \(f\) by taking the derivative of \(f\) and using the
roots(ring=RR)
method. (Here,RR
stands for the real numbers.) Are there any roots over the ring of rationals (QQ
)?sage: # edit here
Compute the equation \(y = mx +b\) of the tangent line to the function \(f\) at the points \(x=-1\) and \(x=2\).
sage: # edit here
Write a function that takes \(x\) as an argument and returns the equation of the tangent line to \(f\) through the point \(x\).
sage: # edit here
Write a function that takes \(x\) as an argument and plots \(f\) together with the the tangent line to \(f\) through the point \(x\). Make the line red.
sage: # edit here
Convert the function you created above into an
@interact
object. Turn the argument \(x\) into aslider
. (Hint: see the documentation forinteract
for examples on creatingsliders
.)sage: # edit here
Differential Equations¶
Using symbolic functions and the command desolve
in Sage, we can
define and solve differential equations. Here is an example.
We will solve the following differential equation:
First we define the variable \(t\):
sage: var('t')
t
Next, we define the symbolic function \(y\):
sage: y = function('y', t)
sage: y
y(t)
We can now create the differential equation:
sage: diff_eqn = diff(y,t) + y - 1
sage: diff_eqn
diff(y(t), t, 1) + y(t) - 1
We can use the show
command to typeset the above equation to make it
easier to read:
sage: show(diff_eqn)
Finally, we use the desolve
command to solve the differential equation:
sage: soln = desolve(diff_eqn, y)
sage: soln
e^(-t)*(e^t + c)
sage: show(soln)
Exercises
Find and plot the solution to the following differential equation with the intial condition \(y(0) = -2\).
\[y'(t) = y(t)^2 - 1\](Hint: see the documentation of the
desolve
command for dealing with initial conditions.)sage: # edit here
Find and plot the solution to the differential equation
\[t y'(t) + 2 y(t) = \frac{e^t}{t}\]with initial conditions \(y(1) = -2\). (Hint: see the documentation of the
desolve
command for dealing with initial conditions.) [Introductory Differential Equations using SAGE, David Joyner]sage: # edit here
Problem¶
Let \(a>b>0\) be fixed real numbers and form a triangle with one vertex on the line \(y=x\), one vertex on the line \(y=0\) and the third vertex equal to \((a,b)\).
Find the coordinates of the vertices that minimize the perimeter of the triangle (remember that (a,b) is fixed!). What is the perimeter?
sage: # edit here