Skip to main content
Dev LibreTexts

2.8 Embedded Sagemath

  • Page ID
    2174
  • # Define a symbolic variable
    x = var('x')
    
    # Define a function
    f = sin(x) * e^(-x/5)
    
    # Take the derivative
    f_derivative = diff(f, x)
    
    # Solve for critical points (where derivative is zero)
    critical_points = solve(f_derivative == 0, x)
    
    # Display the function and its derivative
    show(f)
    show(f_derivative)
    show(critical_points)
    
    # Plot the function and its derivative
    plot1 = plot(f, (x, 0, 10), color='blue', legend_label='f(x)')
    plot2 = plot(f_derivative, (x, 0, 10), color='red', linestyle='--', legend_label="f'(x)")
    combined_plot = plot1 + plot2
    combined_plot.show()
    
    e(15x)sin(x)
    • Was this article helpful?