# Peeter Joot's Blog.

• ## Recent Comments

 ivor on Just Energy Canada nasty busin… A final pre-exam upd… on An updated compilation of note… Anon on About peeterjoot on About Anon on About
• ## People not reading this blog: 6,973,738,433 minus:

• 132,472 hits

# Archive for August 2nd, 2012

## Complex form of Poynting relationship

Posted by peeterjoot on August 2, 2012

[Click here for a PDF of this post with nicer formatting]

This is a problem from [1], something that I’d tried back when reading [2] but in a way that involved Geometric Algebra and the covariant representation of the energy momentum tensor. Let’s try this with plain old complex vector algebra instead.

## Question: Average Poynting flux for complex 2D fields (problem 2.4)

Given a complex field phasor representation of the form

\begin{aligned}\tilde{\mathbf{E}} = \mathbf{E}_0 e^{i (\mathbf{k} \cdot \mathbf{x} - \omega t)}\end{aligned} \hspace{\stretch{1}}(1.0.1)

\begin{aligned}\tilde{\mathbf{H}} = \mathbf{H}_0 e^{i (\mathbf{k} \cdot \mathbf{x} - \omega t)}.\end{aligned} \hspace{\stretch{1}}(1.0.2)

Here we allow the components of $\mathbf{E}_0$ and $\mathbf{H}_0$ to be complex. As usual our fields are defined as the real parts of the phasors

\begin{aligned}\mathbf{E} = \text{Real}( \tilde{\mathbf{E}} )\end{aligned} \hspace{\stretch{1}}(1.0.3)

\begin{aligned}\mathbf{H} = \text{Real}( \tilde{\mathbf{H}} ).\end{aligned} \hspace{\stretch{1}}(1.0.4)

Show that the average Poynting vector has the value

\begin{aligned}\left\langle{{ \mathbf{S} }}\right\rangle = \left\langle{{ \mathbf{E} \times \mathbf{H} }}\right\rangle = \frac{1}{{2}} \text{Real}( \mathbf{E}_0 \times \mathbf{H}_0^{*} ).\end{aligned} \hspace{\stretch{1}}(1.0.5)

## Answer

While the text works with two dimensional quantities in the $x,y$ plane, I found this problem easier when tackled in three dimensions. Suppose we write the complex phasor components as

\begin{aligned}\mathbf{E}_0 = \sum_k (\mathbf{E}_{kr} + i \mathbf{E}_{ki}) \mathbf{e}_k = \sum_k {\left\lvert{\mathbf{E}_k}\right\rvert} e^{i \phi_k} \mathbf{e}_k\end{aligned} \hspace{\stretch{1}}(1.0.6)

\begin{aligned}\mathbf{H}_0 = \sum_k (\mathbf{H}_{kr} + i \mathbf{H}_{ki}) \mathbf{e}_k = \sum_k {\left\lvert{\mathbf{H}_k}\right\rvert} e^{i \psi_k} \mathbf{e}_k,\end{aligned} \hspace{\stretch{1}}(1.0.7)

and also write $\phi_k' = \phi_k + \mathbf{k} \cdot \mathbf{x}$, and $\psi_k' = \psi_k + \mathbf{k} \cdot \mathbf{x}$, then our (real) fields are

\begin{aligned}\mathbf{E} = \sum_k {\left\lvert{\mathbf{E}_k}\right\rvert} \cos(\phi_k' - \omega t) \mathbf{e}_k\end{aligned} \hspace{\stretch{1}}(1.0.8)

\begin{aligned}\mathbf{H} = \sum_k {\left\lvert{\mathbf{H}_k}\right\rvert} \cos(\psi_k' - \omega t) \mathbf{e}_k,\end{aligned} \hspace{\stretch{1}}(1.0.9)

and our Poynting vector before averaging (in these units) is

\begin{aligned}\mathbf{E} \times \mathbf{H} = \sum_{klm} {\left\lvert{\mathbf{E}_k}\right\rvert} {\left\lvert{\mathbf{H}_l}\right\rvert} \cos(\phi_k' - \omega t) \cos(\psi_l' - \omega t) \epsilon_{klm} \mathbf{e}_m.\end{aligned} \hspace{\stretch{1}}(1.0.10)

We are tasked with computing the average of cosines

\begin{aligned}\left\langle{{ \cos(a - \omega t) \cos(b - \omega t) }}\right\rangle=\frac{1}{{T}} \int_0^T \cos(a - \omega t) \cos(b - \omega t) dt=\frac{1}{{\omega T}} \int_0^T \cos(a - \omega t) \cos(b - \omega t) \omega dt=\frac{1}{{2 \pi}} \int_0^{2 \pi}\cos(a - u) \cos(b - u) du=\frac{1}{{4 \pi}} \int_0^{2 \pi}\cos(a + b - 2 u) + \cos(a - b) du=\frac{1}{{2}} \cos(a - b).\end{aligned} \hspace{\stretch{1}}(1.0.11)

So, our average Poynting vector is

\begin{aligned}\left\langle{{\mathbf{E} \times \mathbf{H}}}\right\rangle = \frac{1}{{2}} \sum_{klm} {\left\lvert{\mathbf{E}_k}\right\rvert} {\left\lvert{\mathbf{H}_l}\right\rvert} \cos(\phi_k - \psi_l) \epsilon_{klm} \mathbf{e}_m.\end{aligned} \hspace{\stretch{1}}(1.0.12)

We have only to compare this to the desired expression

\begin{aligned}\frac{1}{{2}} \text{Real}( \mathbf{E}_0 \times \mathbf{H}_0^{*} )= \frac{1}{{2}} \sum_{klm} \text{Real}\left({\left\lvert{\mathbf{E}_k}\right\rvert} e^{i\phi_k}{\left\lvert{\mathbf{H}_l}\right\rvert} e^{-i\psi_l}\right)\epsilon_{klm} \mathbf{e}_m = \frac{1}{{2}} \sum_{klm} {\left\lvert{\mathbf{E}_k}\right\rvert} {\left\lvert{\mathbf{H}_l}\right\rvert} \cos( \phi_k - \psi_l )\epsilon_{klm} \mathbf{e}_m.\end{aligned} \hspace{\stretch{1}}(1.0.13)

This proves the desired result.

# References

[1] G.R. Fowles. Introduction to modern optics. Dover Pubns, 1989.

[2] JD Jackson. Classical Electrodynamics Wiley. John Wiley and Sons, 2nd edition, 1975.

Posted in Math and Physics Learning. | Tagged: , , | 2 Comments »

## Ease of screwing up C string operations.

Posted by peeterjoot on August 2, 2012

Here’s a new way to mess up a strncpy that I hadn’t seen before. I found about 50 instances of this in the component I was working on today:

   ossStrNCopy( pszTarget, pszSource, strlen( pszSource ) + 1 ) ;


Our ossStrNCopy function is a lot like strncpy, but unlike the library interface, ours is explicitly truncating and won’t leave a dangling non-null terminated string. It’s supposed to be called like:

   ossStrNCopy( pszTarget, pszSource, sizeof(pszTarget) ) ;


(where pszTarget is a char [] array and not a char *). The idea is to avoid buffer overflows that would occur if you were to copy more bytes than the target can hold.

This incorrect use is an excellent example of what was probably clueless cut and paste. Perhaps the thought process was: “I don’t know what this last parameter is for. It’s too much work to read the documentation … I’ll just put something.”

The caller is requesting to have one plus the null terminator of the source string copied into the target. If you are going to do that, why not just call strcpy?