![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1323430/image.png)
Why am I getting "Arrays have incompatible sizes for the operation." error message?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Abdullah
le 14 Mar 2023
Réponse apportée : Image Analyst
le 14 Mar 2023
>> % Circuit parameters
>> C = 15e-6; % capacitance (F)
>> L = 240e3; % inductance (H)
>> vm = 24; % source voltage amplitude (V)
>>
>>
>> % Range of frequencies and resistances
>> f = 60:1:110; % driving frequency (Hz)
>> R = 10:1:40; % resistance (ohms)
>>
>>
>> % Calculate amplitude of current
>> wd = 2*pi*f;
>> I = vm ./ sqrt(R.^2 + (wd*L - 1./(wd*C)).^2);
Arrays have incompatible sizes for this operation.
Related documentation
>>
0 commentaires
Réponse acceptée
Image Analyst
le 14 Mar 2023
% Circuit parameters
C = 15e-6; % capacitance (F)
L = 240e3; % inductance (H)
vm = 24; % source voltage amplitude (V)
% Range of frequencies and resistances
f = 60:1:110; % driving frequency (Hz)
R = 10:1:40; % resistance (ohms)
% Calculate amplitude of current
wd = 2*pi*f;
whos R
whos wd
I = vm ./ sqrt(R.^2 + (wd*L - 1./(wd*C)).^2);
So R has 31 and wd has 51 elements so they can't be added together. Try using linspace to make sure they have the same number of elements.
% Circuit parameters
C = 15e-6; % capacitance (F)
L = 240e3; % inductance (H)
vm = 24; % source voltage amplitude (V)
% Range of frequencies and resistances
numElements = 51;
f = linspace(60, 110, numElements); % driving frequency (Hz)
R = linspace(10, 40, numElements); % resistance (ohms)
% Calculate amplitude of current
wd = 2*pi*f;
whos R
whos wd
I = vm ./ sqrt(R.^2 + (wd*L - 1./(wd*C)).^2);
plot(I, 'b.-', 'LineWidth', 2, 'MarkerSize', 20)
grid on;
xlabel('Index');
ylabel('I')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1323430/image.png)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Switches and Breakers dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!