Error using / Matrix dimensions must agree...

4 ビュー (過去 30 日間)
Salih Korkut
Salih Korkut 2020 年 6 月 10 日
編集済み: Fabio Freschi 2020 年 6 月 10 日
Below is my script:
clc;
clear;
clear all;
% plotting frequency-current graph according to variable frequency values
f=100:100:100000; % variable frequency values
V=3.536; % AC voltage source
L=33*10^-3; %inductor (henry)
C=47*10^-9; %capacitor (farad)
R=820; %resistor (ohm)
W=2*(pi)*f; % Angular frequency formula
XL=W*L; % inductor impedance
XC=1/(W*C); % capacitor impedance
Z=(2*R)+1i*(XL-XC); % total impedance
I=V/Z; % current
plot(f,I)
May I know why I keep getting this error and how can I fix?
Error using /
Matrix dimensions must agree.
Error in deney3_2 (line 14)
XC=1/(W*C); % capacitor impedance

回答 (1 件)

Fabio Freschi
Fabio Freschi 2020 年 6 月 10 日
編集済み: Fabio Freschi 2020 年 6 月 10 日
f is a vector, as well as W. So you must use the dotted version of the division (that is ./ that performs the operation elementwise). You may find more information here
https://www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
clear;
clear all;
% plotting frequency-current graph according to variable frequency values
f=100:100:100000; % variable frequency values
V=3.536; % AC voltage source
L=33*10^-3; %inductor (henry)
C=47*10^-9; %capacitor (farad)
R=820; %resistor (ohm)
W=2*(pi)*f; % Angular frequency formula
XL=W*L; % inductor impedance
XC=1./(W*C); % capacitor impedance
Z=(2*R)+1i*(XL-XC); % total impedance
I=V./Z; % current
figure,plot(f,I)
Note that you are plotting only the real part, as noticed in the warning
  1 件のコメント
KSSV
KSSV 2020 年 6 月 10 日
Read about element by element operations in MATLAB.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimscape Electrical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by