Skip to main content
Dev LibreTexts

2.7 Embedded Python

  • Page ID
    2167
  • This is only a test

    # 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()
    
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    Cell In[2], line 2
          1 # Define a symbolic variable
    ----> 2 x = var('x')
          4 # Define a function
          5 f = sin(x) * e^(-x/5)
    
    NameError: name 'var' is not defined

     

    • Was this article helpful?