# E field plot

Discussion in 'Programmer's Corner' started by ihaveaquestion, Apr 30, 2011.

1. ### ihaveaquestion Thread Starter Active Member

May 1, 2009
314
0
Hi all,

I'm trying to do a very simple plot of E field as a function of theta with 0 <= theta >= 90 for the following E field:

E = exp(-1j*k*(r-(a/2)*sin(theta)))+exp(-1j*k*(r+(a/2)*sin(theta)));

I've attached a picture of the E function in handwriting which may be easier to see... (I hope my express above matches)

Here is my code (assumptions made are that E$_{}o$: is 1 and a/r =0, i.e., r >> a... also k = $\beta$)

r = 1000;
lam = 1;
a = lam/4;
k = 2*pi/lam;
theta = 0:5:90;
x = exp(-1j*k*(r-(a/2)*sin(theta)))+exp(-1j*k*(r+(a/2)*sin(theta)));
plot(theta,x);
xlabel('theta');
ylabel('E');

Is this correct?

Thanks a lot everyone

• ###### HW4.jpg
File size:
16.5 KB
Views:
23
Last edited: Apr 30, 2011
2. ### ihaveaquestion Thread Starter Active Member

May 1, 2009
314
0
anyone willing to help?

Jul 7, 2009
1,585
141
You don't say whether you want the real or imaginary part (I assume you mean j is the unit imaginary). Unless I screwed up on my algebra, this expression can be simplified to a complex exponential times a cosine (see attached).

I've also attached a plot of this function I made using python, numpy, and matplotlib.

Code ( (Unknown Language)):
1.
2. from pylab import *
3. theta, A = arange(0, pi/2, 0.1), 1
4. plot(theta, 2*cos(A*sin(theta)))
5. xlabel('theta')
6. text(0.6, 2, r"$2cos(A sin \theta)$", size=18)
7. savefig("cos_term.png", dpi=75)
8.

File size:
57.5 KB
Views:
19
File size:
15.7 KB
Views:
14
4. ### ihaveaquestion Thread Starter Active Member

May 1, 2009
314
0
Yes, I think you're right about just taking the real part.... is there a command in MATLAB to just take the real part of the function to avoid any algebra errors?

Would it also be possible for you to please post the magnitude of E as a function of theta with theta sweeping from 0 to 90? I'd like to see if our graphs match... thanks

Jul 7, 2009
1,585
141
I don't have or use Matlab, so I can't help you. It's easy to do in python though (and the nice thing about the python tools is that they are open source and free).

I did plot the function of theta -- see the second image in my post above. That curve is just multiplied by a complex exponential in r, which you can take as a constant, as it won't change as theta varies.

But since it's trivial to do in python, here's the code to plot the E function you gave (I just set the constants to convenient values):

Code ( (Unknown Language)):
1.
2. from pylab import *
3. theta, A = arange(0, pi/2, 0.1), 1
4. a, r, k = 2, 1, 1
5. E = exp(-1j*k*(r - a/2*sin(theta))) + exp(-1j*k*(r + a/2*sin(theta)))
6. plot(theta, E.real)
7. xlabel('theta')
8. ylabel('Real part of E')
9.
The plot is attached. BTW, the folks who wrote the matplotlib library I use for plotting modeled it after Matlab, so it's possible the Matlab code is quite similar to the python code. One nice feature of matplotlib is that you can put equations and text on the screen anywhere and in the titles and axis labels. Makes it easier to produce useful plots.

• ###### e_plot.png
File size:
15.6 KB
Views:
20
Related Forum Posts:
1. Replies:
1
Views:
851
2. Replies:
5
Views:
1,313
3. Replies:
6
Views:
2,192
4. Replies:
4
Views:
6,366
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 2, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8093254566192627, "perplexity": 3181.1182897722574}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-44/segments/1476988718034.77/warc/CC-MAIN-20161020183838-00238-ip-10-171-6-4.ec2.internal.warc.gz"}