MATLAB help needed for electric field plotting

In summary, the conversation discusses the task of using a computational approach to calculate the electric field due to a truncated line of electric charge with a linear charge density of ρ= 8 C/m. The formula E = [ρ/(4∏εr)] [(sin β1 - sin β2) + (cos β1 - cos β2)] is mentioned, but there is uncertainty on how to proceed with obtaining a value instead of an equation. A sample code using the quiver command in MATLAB is given, but it is not clear how to use it with the given values. The conversation ends with a request for clarification on what expressions to use for the vector components Ex and Ey.
  • #1
killerdevil
20
0

Homework Statement




A straight wire of electric charge truncate to length L has a linear charge density of ρ= 8 C/m. Using a computational approach calculate the electric field due to the truncated line at any arbitrary point in space.

Consider L = 1 m, assume line lies along y-axis with the two ends at (0,−L / 2) and (0, L / 2) , and use the MATLAB command quiver to provide a vector plot of the electric field in the x-y plane for a range of −1 m < x < 1m and −1 m < y <1m

Homework Equations



The Attempt at a Solution



I have attempted at this question and got the following equation:

E = [ρ/(4∏εr)] [(sin β1 - sin β2) + (cos β1 - cos β2)]
- where β is the angle between an arbitrary point and the line.
- sine is in the x direction, cosine is in the y direction

in an attempt to get a value instead of an equation, i place point P at the corner of the "imaginary box" (since the limit given to me was a 1 by 1 box).

β1 = 56.3°
β2 = 26.6°


the problem is i don't know how am i suppose to continue.

worst of all, i don't get what i am suppose to expect from the graph and having no experience in MATLAB, i don't know how to plot it.

a sample code (as shown below) was given to me to analysis but when i tried playing around with the codes using my value, but i got a weird looking graph (not even having a single vector) was given to me.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example: quiver command
% let's plot the function 1/x as quiver plot over an XY
% region in space
clear all % clear memory, etc
% choose a region over which to plot
[x,y]=meshgrid(0:1:10,0:1:10);
% let x cpt be just equal to 1/x
Ex=1./x;
% set y cpt to zero and remember to make matrix sizes all
% the same (X, Y, Ex and Ey)
Ey=0*y;
% plot as 2-D arrow plot using quiver mode
% (the 0 at the end just auto-scales arrows)
quiver(x,y,Ex,Ey,0);
% insert labels for axes and title
xlabel('x');ylabel('y');title('Example of using quiver plot')
% Export figure into JPG format
print -f1 -r300 -djpeg example_quiver
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
Physics news on Phys.org
  • #2
Hi killer. You didn't really explain how you came up with a formula for vector components Ex(x,y) and Ey(x,y).

Are you supposed to use a "closed form" expression for these or are you to calculate them numerically in matlab? For example, I can fairly easily write them as a definite integral (which I could evaluate numerically in matlab) but I don't seem to be able to get anything simpler.

Start by clearly explaining exactly what expressions you are trying to use for the vector components Ex,Ey.
 

1. What is MATLAB and how is it used for electric field plotting?

MATLAB is a high-level programming language and interactive environment commonly used in scientific and engineering applications. It allows users to analyze and visualize data, including electric field data, through the use of built-in functions and tools.

2. How do I plot electric field data in MATLAB?

To plot electric field data in MATLAB, you can use the "quiver" function, which creates a vector field plot with arrows representing the magnitude and direction of the electric field at each point. You can also use the "contour" or "surf" functions to create 2D or 3D plots of the electric field.

3. Can I customize the appearance of my electric field plot in MATLAB?

Yes, MATLAB allows for customization of plot appearance through the use of various functions and options. For example, you can change the color, size, and orientation of the arrows in a "quiver" plot, or adjust the color map and contour levels in a "contour" or "surf" plot.

4. How do I import and manipulate my electric field data in MATLAB?

To import and manipulate electric field data in MATLAB, you can use the "importdata" function to load data from a file or the "readmatrix" function to read data from a spreadsheet. You can then use various functions and operations to manipulate the data, such as calculating the magnitude or direction of the electric field at each point.

5. Are there any resources available for learning more about electric field plotting in MATLAB?

Yes, MATLAB offers extensive documentation and tutorials on its website, as well as user forums and support communities where you can ask for help and advice. There are also many online resources and books available for learning MATLAB and its various applications, including electric field plotting.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
825
  • Engineering and Comp Sci Homework Help
Replies
1
Views
866
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
841
  • Engineering and Comp Sci Homework Help
Replies
1
Views
949
  • Engineering and Comp Sci Homework Help
Replies
2
Views
813
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
10
Views
971
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Replies
8
Views
802
Back
Top