Determining electric field from electrostatic potential
조회 수: 12 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
nick
2024년 9월 2일
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
nick
2024년 9월 12일
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!
추가 답변 (2개)
Shivam
2024년 9월 3일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
