Attempting to plot two lines on the one graph
Afficher commentaires plus anciens
Still fairly new to MatLab, using this code, I am attempting to plot both the |Zo| and Mag (sqrt(L/C)) lines on the same graph. However it is only plotting the |Zo| line. I have also attemped to use hold on an off's, however only the one line is plotted.
% Constants
R = [2.2]; % ohm m^-1
L = [105]*1e-9; % H m^-1
C = [69]*1e-12; % F m^-1
G = [14]*1e-9; % S m^-1
% Frequency range
f = logspace(0,9); % Hz
% Propagation coefficient
alpha = sqrt((R + 1i*2*pi*f.*L).*(G + 1i*2*pi*f.*C));
beta = sqrt((R + 1i*2*pi*f.*L).*(G + 1i*2*pi*f.*C)) .* sqrt(G + 1i*2*pi*f.*C);
% Characteristic impedance
Zo = sqrt((R + 1i*2*pi*f.*L)./(G + 1i*2*pi*f.*C));
% Sqrt(L/C)
Mag = sqrt(L/C);
loglog(f, abs(Zo),f, Mag)
xlabel('Frequency (Hz)');
ylabel('|Z_o| (\Omega)');
title('Characteristic Impedance |\Z_o|');
grid on;
1 commentaire
Compare:
L = [105]*1e-9; % two numbers and two operations
vs.
L = 105e-9; % one number
Only add complexity to code, if it does something useful. Obfuscation is not useful.
Réponses (1)
% Constants
R = [2.2]; % ohm m^-1
L = [105]*1e-9; % H m^-1
C = [69]*1e-12; % F m^-1
G = [14]*1e-9; % S m^-1
% Frequency range
f = logspace(0,9); % Hz
% Propagation coefficient
alpha = sqrt((R + 1i*2*pi*f.*L).*(G + 1i*2*pi*f.*C));
beta = sqrt((R + 1i*2*pi*f.*L).*(G + 1i*2*pi*f.*C)) .* sqrt(G + 1i*2*pi*f.*C);
% Characteristic impedance
Zo = sqrt((R + 1i*2*pi*f.*L)./(G + 1i*2*pi*f.*C));
% Sqrt(L/C)
Mag = sqrt(L/C);
loglog(f, abs(Zo), '-.', f, Mag, '-*')
xlabel('Frequency (Hz)');
ylabel('|Z_o| (\Omega)');
title('Characteristic Impedance |Z_o|');
grid on;
Why the line of * ? Answer: because Mag is a scalar, not a vector. L and C are scalars so sqrt(L/C) is a scalar.
Catégories
En savoir plus sur Images dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
