Plot the potential surface and electric field strength vectors in the Oxy plane
49 views (last 30 days)
Show older comments
Write Matlab program to:
1) Enter an expression , for example, lg (x) + y
2) Limit the space of the Oxy plane with xmax = ymax = 10
3) Use symbolic operations to compute and compute Ex and Ey components at all points in given space.
4) Plot the potential surface V and electric field vectors .
0 Comments
Answers (1)
Shishir Reddy
on 6 Nov 2024
Hi Nguyen
As per my understanding, you would like to write a MATLAB program that computes and visualizes the potential surface and electric field vectors from a user-defined mathematical expression over a specified 2D space.
Kindly refer the following snippets to achieve the tasks you've outlined (Assumption - ‘V’, ‘xmax’,’ ymax’ are defined)–
Computing the Electric field components –
Ex = -diff(V, x);
Ey = -diff(V, y);
Creating a grid for plotting –
[xGrid, yGrid] = meshgrid(linspace(-xmax, xmax, 20), linspace(-ymax, ymax, 20));
Evaluating the potential and electric field components on the grid
VGrid = double(subs(V, {x, y}, {xGrid, yGrid}));
ExGrid = double(subs(Ex, {x, y}, {xGrid, yGrid}));
EyGrid = double(subs(Ey, {x, y}, {xGrid, yGrid}));
Plotting the potential surface –
surf(xGrid, yGrid, VGrid);
Plotting the electric field vectors –
quiver(xGrid, yGrid, ExGrid, EyGrid);
For more information regarding the ‘diff’, ‘meshgrid’, ‘subs’, ‘surf’, ‘quiver’ functions, kindly refer to the following documentations -
I hope this helps.
See Also
Categories
Find more on Red in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!