Inner matrix dimensions must agree?

1 次查看(过去 30 天)
I am trying to graph the magnitude and phase of this equation, and I keep getting that error.
I am a matlab newbie, no clue what's wrong at all.
%USER
w = [-25:25]*pi/25;
T = [-25:25];
X = -(2*1i*exp(-(1/2)*1i*T*w)*(-1+exp((1i* T* w)/2))*(-2+T))/(T*w);
magX = abs(X); phaX = angle(X);
In case it helps here is the function I am trying to graph in a more readable form.

回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2014-7-2
编辑:Azzi Abdelmalek 2014-7-2
When you multiply or divide two vectors, element by element, you need to add a dot (.) before your operator, in your case: .* and ./
w = [-25:25]*pi/25;
T = [-25:25];
X = -(2*1i*exp(-(1/2)*1i*T.*w).*(-1+exp((1i* T.* w)/2)).*(-2+T))./(T.*w);

Joseph Cheng
Joseph Cheng 2014-7-2
What is happening is that you're performing matrix multiplication in your X = equation. which isn't what you want to do here. you need to perform the Element by element multiplication that Azzi has shown. this is performed by the '.*' which means for each element of w it will be multiplied by the same element in T. such that w.*T = [w(1)*T(1) w(2)*T(2) .... w(n)*T(n)].

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by