Here's a template you can use:
% Constants
lambda = 1; % Wavelength
d = lambda / 2; % Distance between elements
% Define the range of theta values
theta = linspace(0, pi, 100);
% Calculate the E-field pattern
z = exp(1i * k * d * cos(theta));
E = sin(theta) .* (z - 1) .* (z.^3 - 1);
% Calculate the magnitude squared of E
E_squared = abs(E).^2;
% Plot the E-field pattern in linear scale
figure;
plot(theta, E_squared);
xlabel('θ (radians)');
ylabel('|E(θ)|^2');
title('E-field Pattern (Linear Scale)');
% Plot the E-field pattern in dB scale
figure;
plot(theta, 10*log10(E_squared));
xlabel('θ (radians)');
ylabel('|E(θ)|^2 (dB)');
title('E-field Pattern (dB Scale)');
In this code, you can adjust the value of lambda to represent the wavelength of the signal, and k is the wave number. The d variable represents the distance between the dipole elements.
The code calculates the E-field pattern for the given range of theta values using the provided formula. Then, it calculates the magnitude squared of E and stores it in the E_squared variable.
Finally, the code plots the E-field pattern in both linear and dB scales using the plot function. The xlabel, ylabel, and title functions are used to label the axes and provide a title for each plot.
You can run this code in MATLAB to visualize the E-field pattern in both linear and dB scales for the given range of theta values.
Hope this helps!