Plotting Complex Functions in MATLAB: Understanding Period Placement

  • Context: MATLAB 
  • Thread starter Thread starter dillonmhudson
  • Start date Start date
  • Tags Tags
    Matlab Matrix
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
dillonmhudson
Messages
47
Reaction score
0
Matrix "." Help in MATLAB

Here is my code:

f=linspace(0,1000,1000);
xf=abs((1-exp(1-2*pi*f.*1i))/(2*pi*f.*1i-1)+(((exp(4*pi*f.*1i)-1)*exp(1-6*pi*f.*1i))/(2*pi*f.*1i))+(((2*pi*f.*1i-1)*exp(1-6*pi*f.*1i)+exp(1-10*1i*f.*pi))/(8*pi^2*f.^2*1i)));
func=plot(f,xf)

I just need to know where the periods need to go, I don't get what I'm doing wrong.

TIA
 
on Phys.org


Use periods in front of operators where one of the operands is a matrix if you want an element-by-element operation. It would probably be easiest just to replace every * and / with .* and ./
 


Great! Got it working, thanks for the help!
 


No problem.

When you aren't wanting to do matrix calcs, make sure to use element-by-element operators otherwise MATLAB will throw errors when trying to multiply matrices with incompatible dimensions.

There's also a built-in function that will do this for certain expressions called http://www.mathworks.com/help/techdoc/ref/vectorize.html".
 
Last edited by a moderator:


Ok, quite the noob with MATLAB right now. I have heard of vectorize though! Thanks :cool: