MATLAB: How to plot real and imaginary parts on one graph(figure)? And how to do that separately

MATLAB

clear all
clc
syms x
epsilon(x) = 1-(9.1/(((6*pi*10.^8)/x).^2+0.005184)) + i*(5.96232/((((6*pi*10.^8)/x).^3+0.005184*(6*pi*10.^8)/x)));
a(x) = 42592*pi*((1.1025*(epsilon(x)+4.205)+0.16765*(epsilon(x)-2.1025))/(4.1025*(epsilon(x)+4.205)+0.07102*(epsilon(x)-2.1025)));
for n = 400:600
eval(a(n))
end
**Could you please help me to add the rest of the code and explain how does it work? I need to plot an imaginary part of a(x) and real part of a(x) on the one figure(graph)? I would much appreciate your help.

Best Answer

No need for symbolics here...I'd use function handles instead--
xred=@(x) 6*pi*10.^8./x; % make a simplification by defining the reduced x variable
epsilon =@(x) 1-(9.1./(xred(x).^2+0.005184)) + i*(5.96232./(xred(x).^3+0.005184*xred(x)));
a = @(x) 42592*pi*((1.1025*(epsilon(x)+4.205) + 0.16765*(epsilon(x)-2.1025))./ ...
(4.1025*(epsilon(x)+4.205) + 0.07102*(epsilon(x)-2.1025)));
x=400:600; % independent variable range
y=a(x); % evaluate over that range
plotyy(x,real(y),x,imag(y)) % plot the two components
NB: the Im components are near machine eps while the Re components are large but their magnitude only changes by a very small amount over the range.