Question:
Matlab Plotting E field?
Zac
2008-11-05 15:19:46 UTC
Hi,

I need some help to plot a 2-D electrostatic field using matlab.. Any ideas on how to start?
I've looked up on numerical methods in Engineering Electromagnetics by Hayt.
The functions that I'm currently using are meshgrid, gradient, and quiver.

However, based on the numerical method, I need to assign values to each of the grid itself, and so far, I haven't come across any functions that could help me do that..... Any advice would be greatly appreciated
Three answers:
Steve W
2008-11-05 16:04:22 UTC
While you describe it as a 2-D field, the plot you need to make is either a 3-D plot or a contour plot, or some combination of both.



Basically, use the equations for E as a function of x and y to develop a 2D matrix where each matrix value is E or |E| or some other result of your E(x,y) equations.



It will be necessary to define vectors of x and y, with suitably small step size to obtain the desired resolution.



Your matrix may be as large as 1000 x 1000 or 10k x 10k, but check it first with 100 x 100.



Oh, and all of this assumes that you will be using the built-in looping capabilities of Matlab.



As for the underlying equations, go back to Maxwell's equations. It all starts there. Everything else (BEM, etc) is just a numerical method for solving the equations.



If you have a simple case, it may be possible to write the equations directly.



Good luck!
Ian W
2008-11-05 15:56:26 UTC
Are you given the form of the 2-D field, maybe as an equation? To plot the function, you need a matrix of the same size as the grid and you can then write a simple 'for' loop to assign the values based on the grid positions. If you're just given a grid of values you'll need to enter these in a matrix to plot. If you don't have any values, then you'll need an equation and some boundary conditions to solve in the first place...
?
2016-05-26 02:49:17 UTC
Since MATLAB allows vectors and matrices to be multiplied two different ways (1. matrix multiplication, as in linear algrebra or 2. element-by-element), you need to specify the correct multiplication. Try this: t = 0:0.001:01; y = exp(t/2) .* cos(2*t); plot(t,y) See the 'help' function for more information: help times versus help mtimes


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...