Inner matrix dimensions must agree?

2 views (last 30 days)
Steven
Steven on 2 Jul 2014
Answered: Joseph Cheng on 2 Jul 2014
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.

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 2 Jul 2014
Edited: Azzi Abdelmalek on 2 Jul 2014
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 on 2 Jul 2014
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)].

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!