Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

YouTube Tutorial: https://youtu.be/t7x3iUJDJyc

Transcription: Hello everyone, my name is Blaec Bejarano. Today, I'll demonstrate how to plot the gradient of a function alongside its contour plot using SageMath in a Jupyter notebook on CoCalc. This example is inspired by Gregory Bard's textbook "Sage for Undergraduates" and attributed to Augustin O'Keefe.

  1. Define the multivariate function f(x,y)=cos(x)2sin(y)f(x,y) = \cos(x) - 2\sin(y).

The gradient of this function can be written in angle bracket notation as:

f(x,y)=fx,fy=sin(x),2cos(y)\nabla f(x,y) = \left\langle \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right\rangle = \left\langle -\sin(x), -2\cos(y) \right\rangle
  1. In the Jupyter notebook, define the function and compute its gradient: f(x,y)=cos(x)-2*sin(y) gradient = derivative(f)

  2. Create the vector field plot of the gradient: plot1 = plot_vector_field(gradient, (x, -5, 5), (y, -5, 5))

  3. Create the contour plot of the function: plot2 = contour_plot(f, (x, -5, 5), (y, -5, 5), fill=True)

  4. Display both plots together: show(plot1 + plot2)

This tutorial showcases CoCalc's ability to perform mathematical computations and visualizations seamlessly within a collaborative environment. Please like, subscribe, and follow for more content. See you next time. Thanks again!

#SageMath #Jupyter #Gradient #ContourPlot #CoCalc

51 views
ubuntu2204
Kernel: SageMath 10.6
f(x,y)=cos(x)2sin(y)f(x,y) = \cos(x) - 2\sin(y)f(x,y)=fx,fy=sin(x),2cos(y)\nabla f(x,y) = \left\langle \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right\rangle = \left\langle -\sin(x), -2\cos(y) \right\rangle
f(x,y)=cos(x)-2*sin(y) gradient = derivative(f) plot1 = plot_vector_field(gradient, (x, -5, 5), (y, -5, 5)) plot2 = contour_plot(f, (x, -5, 5), (y, -5, 5), fill=False) show(plot1 + plot2)
Image in a Jupyter notebook