import sympy as spx, y = sp.symbols('x y')# Define the functionf = x * y**2# Calculate the partial derivativespartial_x = sp.diff(f, x) # Partial derivative with respect to xpartial_y = sp.diff(f, y) # Partial derivative with respect to y# Display the resultsprint("Partial derivatives wrt x and y:")display(partial_x, partial_y)
Partial derivatives wrt x and y:
\displaystyle y^{2}
\displaystyle 2 x y
import numpy as npimport plotly.graph_objects as go# Define the range for x and ypi = np.pix = np.linspace(-2* pi, 2*pi, 100)y = np.linspace(-2*pi, 2*pi, 100)x, y = np.meshgrid(x, y)# Calculate z based on the given functionz = np.sin(x) + np.sin(y)color1 ='orange'color2 ='orange'# Create the surface plot with custom colorsfig = go.Figure(data=[go.Surface(z=z, x=x, y=y, colorscale='viridis', showscale=False, hoverinfo ='skip')])# Update layout for background and titlesfig.update_layout( title='Surface Plot of z = y^2 cos(xy)', scene=dict(xaxis_title='X', yaxis_title='Y', zaxis_title='Z'))showbackground =Falsefig.update_layout(scene =dict( xaxis =dict( backgroundcolor="rgb(200, 200, 230)", gridcolor="white", showbackground=showbackground, zerolinecolor="black",), yaxis =dict( backgroundcolor="rgb(230, 200,230)", gridcolor="white", showbackground=showbackground, zerolinecolor="black"), zaxis =dict( backgroundcolor="rgb(230, 230,200)", gridcolor="white", showbackground=showbackground, zerolinecolor="black",),),# width=700, margin=dict( r=10, l=10, b=10, t=26) )# Show the plotfig.show()
import numpy as npimport plotly.graph_objects as go# Define the paraboloid z = x^2 + y^2def paraboloid(x, y):return x**2+ y**2# Create a grid for x and yx = np.linspace(-2.5, 2.5, 100)y = np.linspace(-2.5, 2.5, 100)x, y = np.meshgrid(x, y)z = paraboloid(x, y)mask = x**2+ y**2<=4z[~mask] = np.nan # Set values outside the circle to NaN for visualization# Define the intersection plane x = 1x_intersection =1y_intersection = np.linspace(-2, 2, 100)z_intersection = paraboloid(x_intersection, y_intersection)# Point of tangency on the intersectiony_tangent_point =0.5# You can choose another point on the parabolaz_tangent_point = paraboloid(x_intersection, y_tangent_point)# Calculate the slope of the tangent line# Derivative of z with respect to y: dz/dy = 2ytangent_slope =2* y_tangent_point # at y = 0, this is 0# Create the tangent line in the plane z = k + m(y - y0)y_tangent = np.linspace(y_tangent_point -1, y_tangent_point +1, 100)z_tangent = z_tangent_point + tangent_slope * (y_tangent - y_tangent_point)# Create the figurefig = go.Figure()# Add paraboloid color1 ='orange'color2 ='orange'fig.add_trace(go.Surface(z=z, x=x, y=y, colorscale=[[0, color1], [1,color2]], opacity=0.7, name='Paraboloid', hoverinfo ='skip'))# Add intersecting planefig.add_trace(go.Scatter3d(x=[x_intersection]*len(y_intersection), y=y_intersection, z=z_intersection, mode='lines', name='Intersection Parabola', line=dict(color='red', width=5)))# Add tangent linefig.add_trace(go.Scatter3d(x=[x_intersection]*len(y_tangent), y=y_tangent, z=z_tangent, mode='lines', name='Tangent Line', line=dict(color='blue', width=5)))# Update layoutfig.update_layout(title='Paraboloid with Intersection and Tangent Line', scene=dict(xaxis_title='X', yaxis_title='Y', zaxis_title='Z'), width=800, height=600, paper_bgcolor='white')# Show the plotfig.show()