# load the Deriv package
library(Deriv)
Find \(f_x\), \(f_y\), \(f_{xx}\), \(f_{yy}\), \(f_{xy}\) and \(f_{yx}\) of the following equation:
\(f(x,y) = y^3 + 3xy^2 + 3x^2y + x^3\)
\(f_x(x,y)= \lim _{h \to 0} \frac{f(x+h,y) - f(x,y)}{h}\)
\[ \begin{align} f_x(x,y)&= \lim _{h \to 0} \frac{y^3 + 3(x+h)y^2 + 3 (x+h)^2 y + (x+h)^3 - (y^3 + 3xy^2 + 3x^2y + x^3)}{h}\\ &= \lim _{h \to 0} \frac{y^3 + 3xy^2+3hy^2 + 3x^2y + 6xhy + 3h^2y + x^3 + 3x^2h+3xh^2+h^3 - y^3 - 3xy^2 - 3x^2y - x^3}{h}\\ &=\lim _{h \to 0} \frac{3hy^2 + 6xhy+3h^2y+3x^2h+3xh^2+h^3}{h}\\ &=\lim _{h \to 0} 3y^2+6xy+3hy+3x^2+3xh+h^2\\ f_x(x,y)&=3y^2+6xy+3x^2 \end{align} \]
Let’s check our answer using R:
# Define the function
f_expr <- expression(y^3 + 3*x*y^2 + 3*x^2*y + x^3)
# Compute the partial derivative of f with respect to x
df_dx <- Deriv(f_expr, "x")
# Print the expression for the partial derivative with respect to x
print(df_dx)
## expression(3 * x^2 + y * (3 * y + 6 * x))
\(f_y(x,y)= \lim _{h \to 0} \frac{f(x,y+h) - f(x,y)}{h}\)
\[ \begin{align} f_y(x,y)&= \lim _{h \to 0} \frac{(y+h)^3 + 3x(y+h)^2 + 3 x^2 (y+h) + x^3 - (y^3 + 3xy^2 + 3x^2y + x^3)}{h}\\ &= \lim _{h \to 0} \frac{(y^3 + 3y^2h+3yh^2 + h^3) + 3x(y^2+2yh+h^2) + 3x^2y+3x^2h+x^3 - y^3-3xy^2-3x^2y-x^3}{h}\\ &=\lim _{h \to 0} \frac{3y^2h+3yh^2+h^3+6xyh+3xh^2+3x^2h}{h}\\ &=\lim _{h \to 0} 3y^2+3yh+h^2+6xy+3xh+3x^2\\ f_y(x,y)&=3y^2+6xy+3x^2 \end{align} \]
Let’s check our answer using R:
# Define the function
f_expr <- expression(y^3 + 3*x*y^2 + 3*x^2*y + x^3)
# Compute the partial derivative of f with respect to y
df_dy <- Deriv(f_expr, "y")
# Print the expression for the partial derivative with respect to y
print(df_dy)
## expression(3 * x^2 + y * (3 * y + 6 * x))
\(f_{xx}=\frac{\partial}{\partial x} (3y^2+6xy+3x^2)\)
\[ \begin{align} f_{xx}(x,y) &= \frac{\partial}{\partial x} (3y^2+6xy+3x^2)\\ &= 6y+6x \end{align} \]
Let’s check our answer using R
# Define the first derivative with respect to x
first_d <- expression(3*y^2+6*x*y+3*x^2)
# Compute the second partial derivative of f with respect to x
df_dxx <- Deriv(first_d, "x")
# Print the expression for the second partial derivative with respect to x
print(df_dxx)
## expression(6 * x + 6 * y)
\(f_{yy}=\frac{\partial}{\partial y} (3y^2+6xy+3x^2)\)
\[ \begin{align} f_{yy}(x,y) &= \frac{\partial}{\partial y} (3y^2+6xy+3x^2)\\ &= 6y+6x \end{align} \]
Let’s check our answer using R
# Define the first derivative with respect to y
first_d <- expression(3*y^2+6*x*y+3*x^2)
# Compute the second partial derivative of f with respect to y
df_dyy <- Deriv(first_d, "y")
# Print the expression for the second partial derivative with respect to y
print(df_dyy)
## expression(6 * x + 6 * y)
\(f_{xy}=\frac{\partial}{\partial y} (3y^2+6xy+3x^2)\)
\[ \begin{align} f_{xy}(x,y) &= \frac{\partial}{\partial y} (3y^2+6xy+3x^2)\\ &= 6y+6x \end{align} \]
Let’s check our answer using R
# Define the first derivative with respect to x
first_d <- expression(3*y^2+6*x*y+3*x^2)
# Compute the second partial derivative of f with respect to y
df_dxy <- Deriv(first_d, "y")
# Print the expression for the second partial derivative with respect to y
print(df_dxy)
## expression(6 * x + 6 * y)
\(f_{yx}=\frac{\partial}{\partial x} (3y^2+6xy+3x^2)\)
\[ \begin{align} f_{yx}(x,y) &= \frac{\partial}{\partial x} (3y^2+6xy+3x^2)\\ &= 6y+6x \end{align} \]
Let’s check our answer using R
# Define the first derivative with respect to y
first_d <- expression(3*y^2+6*x*y+3*x^2)
# Compute the second partial derivative of f with respect to x
df_dyx <- Deriv(first_d, "y")
# Print the expression for the second partial derivative with respect to x
print(df_dyx)
## expression(6 * x + 6 * y)