Gradient of a 2D plot

119 次查看(过去 30 天)
I have a 2D plot of potential (V) (circular contour plot). I have to find the electric field (E) by taking the gradient. How is it possible to see the gradient of V. [U,W]=gradient(V) returns the gradient in X and Y direction and quiver(X,Y,U,W) helps to visualize the vector field. How is it possible to view effective gradient. Contour (X,Y,U) will only help me to see gradient in x direction. How can I see the effect of gradient which is a vector sum of both gradient in X and Y.?
  2 个评论
Ameer Hamza
Ameer Hamza 2020-9-30
What is wrong with quiver. It generates arrows in the gradient direction.
Prince Alex
Prince Alex 2020-9-30
I am looking for contourf plot of the gradient. Thank you

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2020-9-30
See the gradient documentation section on Contour Plot of Vector Field . It demonstrates exactly what you are describing.
  4 个评论
Prince Alex
Prince Alex 2020-9-30
Thank you. I think it will work. But the above script is showing matrix dimension error. Thank you so much
Star Strider
Star Strider 2020-9-30
My pleasure!
It should not be showing any error. It is an example from the documentation (that I linked to in my oridginal Answer), and ran for me without error in R2020b. The ‘px’ and ‘py’ matrices are both (21x21), so the addition should work. If it is not working with your code, please post it.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2020-9-30
M = sqrt(U.^2+W.^2) ;
contour(X,Y,M)
  1 个评论
Prince Alex
Prince Alex 2020-9-30
编辑:Prince Alex 2020-9-30
Its a nice way. But since it is electric field it will have both positive and negative values. Squaring results in absolute value. @ KSSV a simple U + W will give the answer?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by