0

I am currently carrying out a project on antenna group theory. I started developing the theory on shaped patterns from a continuous planar aperture distribution. The next step was to develop this theory on a discreet number of radiating elements.

We should consider a planar aperture with a circular boundary being incised by a family of m concentric circles with N_{m} radiators. Using circular coordinates and applying some simple algebra we can obtain this two-variable Function:

$F(\theta, \phi) = 4 \sum_{m=1}^{20} \sum_{n=1}^{m} I_{m} \cdot \cos \left[\frac{\pi (2m-1)}{4}\cdot \cos\left(\frac{(2 n-1) \pi}{4m}\right) \sin (\theta) \cos (\phi)\right] \cdot \cos \left[\frac{\pi (2m-1)}{4} \sin \left(\frac{(2 n-1) \pi}{4m}\right) \sin (\theta) \sin (\phi)\right]$

Being m the number of circles (20 on this case), N_{m}=4m elements, I_{m} is the current, which has a certain value for each circle and \phi and \theta being the spherical coordinates angles (taking values from -\pi to \pi and from 0 to \pi, respectively).

The fact is that I want to represent this function on a 3D graph. I am going to explain what I tried so far.

I decided to define \phi and \theta as numpy arrays with 50 values each one. Then I decided to create a 20x20 zero matrix, where the double sum calculations will be. Then I defined the double sum with a double loop.

The code I used was the following:

from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt

p=np.linspace(-np.pi, np.pi, 50) #phi angle
t=np.linspace(0,np.pi,50)        #theta angle
F=np.zeros((20,20))              #matrix 
I=np.array([1,0.961,0.851,0.689,0.510,0.377,0.360,0.429,0.497,0.521,0.494,0.427,0.340,0.257,0.199,0.178,0.181,0.191,0.200,0.204]) # I current array

for i in range(20):
    for j in range(i):
        F[i,j]= 4*I[i]*np.cos(np.pi*(2(i+1)-1)/4 * np.cos(np.pi*(2*(j+1)-1)/(4(j+1))) * np.sin(t)* np.cos(p)) * np.cos(np.pi*(2(i+1)-1)/4 * np.sin(np.pi*(2*(j+1)-1)/(4(j+1))) * np.sin(t)* np.sin(p))


ax = plt.axes(projection='3d')
ax.plot_surface(p, t, F, rstride=1, cstride=1,
                cmap='viridis', edgecolor='none')
ax.set_title('surface');

ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('F')

When running the file I have the following TypeError:'int' object is not callable

I do not know what it is going wrong or how could I improve the program in order to obtain the graph or even make it more efficient.

yakilemapa
  • 11
  • 1

1 Answers1

2

You have a typo in your code:

F[i,j]= 4*I[i]*np.cos(np.pi*(2(i+1)-1)/4 * np.cos(np.pi*(2*(j+1)-1)/(4(j+1))) * np.sin(t)* np.cos(p)) * np.cos(np.pi*(2(i+1)-1)/4 * np.sin(np.pi*(2*(j+1)-1)/(4(j+1))) * np.sin(t)* np.sin(p))

in that line, you have a typo, it should be:

F[i,j]= 4*I[i]*np.cos(np.pi*(2*(i+1)-1)/4 * np.cos(np.pi*(2*(j+1)-1)/(4*(j+1))) * np.sin(t)* np.cos(p)) * np.cos(np.pi*(2*(i+1)-1)/4 * np.sin(np.pi*(2*(j+1)-1)/(4*(j+1))) * np.sin(t)* np.sin(p))

You basically missed 4 *.


Edit:

This fixes your error, however, you get another one, since F[i,j] describes one element, but t, and therefore np.sin(t) consists of 50 elements, which do not fit into your provided index.

The way you did it is unnecessary complex. Try this:

  1. loop over your variables theta and phi, as well as the summation.
  2. sum afterwards using np.sum() instead of using complex vectorization. If you understood how this works, you can change it later on for speed anyways.
Dorian
  • 1,439
  • 1
  • 11
  • 26
  • Hello. I tried to implement your suggestions on the code. Nevertheless I found out some difficulties. Firstly, If the variables p and t have 50 elements, then the matrix where I am doing the calculations should be a 50x50 matrix? Secondly, in order to loop over these variables as well as the sumations, should I implement 4 times a ''for ... in range(50)'' operation? Thank you in advanced. – yakilemapa Jul 16 '20 at 14:03
  • yes, imagine `F[theta, phi]` as a 2D function, you would get a grid with 50x50 function values. You can plot this grid and get your 2D functional surface. – Dorian Jul 16 '20 at 16:04
  • 2.: No. why? You need to loop over all function values (`range(50)` times 2), and over your summation (`range(20)`, `range(i)`), nothing changes for that. – Dorian Jul 16 '20 at 16:16