Determining electric field from electrostatic potential

15 vues (au cours des 30 derniers jours)
Somnath
Somnath le 2 Sep 2024
I am trying to determine Elecric field from 2D electrostatic potential. E = -grad (V); I have a 2D matrix of (V). When I am writing [Ex Ey]=-imgradient(V,'sobel') I am getting error as Error using '-' , too many arguments. Someone kindly help to correct it.

Réponse acceptée

nick
nick le 2 Sep 2024
Hi Somnath,
I noticed an issue in the code regarding the use of the '-' operator with the 'imgradient' function in MATLAB. To ensure correct functionality, the code should be adjusted as follows:
[Ex Ey]=-1*imgradient(V,'sobel')
You may refer to the following documentation to learn more about operators in MATLAB :
Hope this helps!
  3 commentaires
nick
nick le 12 Sep 2024
Hi Somnath,
Thanks for letting me know about the persistent error. I apologize the inconvenience it may have caused. You can instead of compute gradient of '-1*V' instesad of 'V' to resolve the error.
The 'imgradient' function is primarily used for image processing, as it returns the gradient magnitude of a 2-D image.
To determine the 2-D Electric field frim potential, V, you can instead use the fucntion 'gradient'. The function returns the N components of the gradient of F, where F is an array with N dimensions. Here's an example MATLAB script of the same:
V = rand(5, 5); % Example 2D potential matrix
% Calculate the gradient of V
[Ex, Ey] = gradient(-1*V);
% Display the results
figure;
quiver(Ex, Ey);
title('Electric Field from Potential');
xlabel('X-axis');
ylabel('Y-axis');
axis equal;
You can refer to the following documentations to learn more about 'imgraident' and 'gradient':
I hope this helps, and feel free to reach out if you have any more questions!
Somnath
Somnath le 12 Sep 2024
Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (2)

Shivam
Shivam le 3 Sep 2024
Hi Somnath,
I see that you are encountring the error while calculating electric field from 2D electric potential.
In vector calculus notation, the electric field is given by the negative of the gradient of the electric potential, E = −grad V.
You can follow the below workaround to correctly calculate the Electric Field:
% Compute the gradient components
[Ex, Ey] = imgradient(V);
% The electric field is the negative gradient of the potential
Ex = -Ex;
Ey = -Ey;
I hope this resolves the issue.
Regards,
Shivam

Eliezer
Eliezer le 17 Oct 2024
See more here:

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by