Graphing an propagating electric field: This code was provided by the author and it is meant to assist with the drawing of the electrical field at different points in time as it travels in along the x-axis.
Reference: Elements of Electromagnetics Matthew N.O. Sadiku 5th Edition (Page 450), Chapter 10 Example 1
Problem: I have tried to fix some parts of the original code, by substituting symbolic omega into the E field equation after user inputs omega. However, the issue lies in the ploting section of the code. This is where y knowledge of MATLAB is limited and I cannot resolve the errors.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% This script assists with the solution and graphing if Example 10.1.
% We use Symbolic variables in the creation of the waveform equation that
% describes the expression for the electrical field.
clear
% Create symbolic variables for fields, time, and frequency.
syms E omega Beta t x
% Enter the frequency (in rad/s)
w = input('Enter the angular frequency \n > ');
%The expression for the y-component of the electrical field is:
E = 50*cos(omega*t+Beta*x);
% Part (b)
% Solve for β
% -----------
B = w/3e8; % B is the numerical variable for
% Beta, with value as calculated here
E = subs(E, omega, w);
E = subs(E, Beta, B); % Substitude the value B in for variable Beta
% Generate Numerical Sequence
% ----------------------------
xfinal = ceil (6*2*pi/B); % We will compute spatial values out to 3λ
dx = xfinal/1000; % Discrete distance
space = 0:dx:xfinal; % Create a vector of 1000 discrete space
% segments.
unityvec = ones(1,length(space)); % Create avector of 1s that is the same
% length as the spatial vector discrete
% space segments
% Plot
% ----
figure(1) % Create figure window with title.
f = w/(2*pi); % Determine the frequency of the field
for time = 0:1/(20*f):1/f
En = subs(E,{x,t},{space, unityvec*time}); % Substitute the time and space vector in the
% variable to get a vector of the field as a function of
plot(space, En)
axis([0 6*2*pi/B min(En)-10 max(En)+10])
xlabel('x-axis (m)') % add buffer space of 5 units to graph
ylabel('y-axis (m)')
str=strcat('time = ', num2str(time),' (s)' ); % concatenate string ‟time = ‟ to the actual time text(1.5, max(En)+5, str) % put annotation on figure
% to show time
text(1.5, max(En)+5, str)
pause(0.5) % pause for half a second then re-draw
hold off
end

 채택된 답변

Voss
Voss 2022년 5월 14일

0 개 추천

The only error I ran into was with using axis with symbolic expressions. You can correct that error by changing this line:
axis([0 6*2*pi/B min(En)-10 max(En)+10])
to this:
axis(double([0 6*2*pi/B min(En)-10 max(En)+10]))

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 5월 14일

답변:

2022년 5월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by