Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Defining a function in SageMath is quite easy. Give the function a name, list the arguments in parentheses, then type out the function.
Defining a function
Function name must start with a letter and can contain numbers and underscores (no spaces)
List the arguments of the function. These do not need to be defined as variables
For example
y(t)=y_0+v_0*t+1/2*a*t^2
Functions can be evaluated by entering values for each argument
For example:
y(1)
yields the value ofy
whent=1
.
Taking Derivatives
Can either use
diff(f(x),x)
or f(x).diff(x)diff()
orderivative()
are identicalSpecify variable to differentiate with respect to
Indicate the order of the derivative
The SageMath derivative returns a function so you can assign it a name or evaluate it at a point just like with other functions.
Plotting Functions
Use the
plot()
command to create a plotArguments of
plot()
include the function to plot, the variable to plot against, and the variable rangeplot(y(t),t,0,10)
plots the function y(t) vs. t from t=0 to t=10
Plots can be given variable names which is useful for modifying features of the plot
For example:
P1=plot(y(t),t,0,10)
The
show()
command displays the plot on the screenFor example:
P1.show()
Try It Yourself
Plot the function vs.
Use
.substitute()
to input values for G, , andChoose a minimum value of so graph does not blow up near the origin
Plotting Multiple Functions
Plots can be 'added' together for display on the same graph