MATLAB: Trouble with plotting on log scale with current data

helplinear scale to log scalelog scale plotting

So I have the plot down for linear scale but when I go to use the same code for log scale, using loglog, I get an error message. I believe its from using a syms on theta.
"Data must be numeric, datetime, duration or an array convertible to double."
Was looking for some points on how to change my code to accept my data to plot on log.
syms theta
kD = 0.1:10;
x = (kD.*sin(theta));
R = (1 - ((2*besselj(1,x))./(x)));
X = ((2*besselj(1,x))./(x)) + (((2*bessely(1,x))./(x))*1i);
figure(3)
fplot(R)
axis([0 1.8 -0.2 1.2])
grid on
title('Plot of Radiation Resistance and Reactance')
hold on
fplot(real(X)+ imag(X))
axis([0 1.8 -0.2 1.2])
grid on
hold off
loglog(R)

Best Answer

fplot(R, [realmin, 1.8])
set(gca, 'XScale', 'log', 'YScale', 'log')
loglog() is reserved for numeric plots, not used for symbolic plots.
fplot() is doing the work of taking your symbolic formula and substituting in values for the variable and plotting the result, along with hidden work in the back-ground to try to ensure that the plot is plotted densely enough to take into account the oscillations or steepness.
You will find that the plot is very choppy and difficult to understand. A portion of that is because your plot starts at 0 and there is an infinite amount of log space between 0 and 1. It gets a bit better if you are willing to ignore almost all of that and start at (for example) eps, but it is still not nice.
You might prefer something like,
TH = logspace(-1,log10(1.8), 250);
loglog(TH,subs(R,theta,TH.'))
or
fplot(R, [.1 1.8])
set(gca, 'XScale', 'log', 'YScale', 'log')
Related Question