Borrar filtros
Borrar filtros

Compute the partial derivative numerically

26 visualizaciones (últimos 30 días)
F.O
F.O el 21 de Dic. de 2017
Editada: F.O el 21 de Dic. de 2017
Hi, I want to compute the first and second partial derivative with respect to x, y for this function
x0=0
y0=0
x=[-1:0.1:1];
y=[-2:0.1:2];
v=x+exp(-((x-x0).^2+(y-y0).^2))

Respuesta aceptada

Star Strider
Star Strider el 21 de Dic. de 2017
See if the gradient (link) function will do what you want:
Example
x0=0;
y0=0;
x=[-1:0.1:1];
y=[-2:0.1:2];
[X,Y] = meshgrid(x, y);
v = @(x,y) x+exp(-((x-x0).^2+(y-y0).^2));
[dX,dY] = gradient(v(X,Y));
figure(1)
surf(X, Y, v(X,Y), 'FaceAlpha',0.5, 'EdgeColor',[0.3 0.3 0.7])
hold on
surf(X, Y, dX, 'EdgeColor','g')
surf(X, Y, dY, 'EdgeColor','r')
hold off
grid on
legend('v(x,y)', 'dX', 'dY')
xlabel('\bfX')
ylabel('\bfY')
view(40, 20)
figure(2)
contour(X, Y, v(X,Y))
hold on
quiver(X, Y, dX, dY)
hold off
legend('v(x,y)', 'Gradient')
  4 comentarios
F.O
F.O el 21 de Dic. de 2017
Thanks for the answer
Star Strider
Star Strider el 21 de Dic. de 2017
My pleasure.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by