MATLAB Plotting Complex Functions in MATLAB: Understanding Period Placement

  • Thread starter Thread starter dillonmhudson
  • Start date Start date
  • Tags Tags
    Matlab Matrix
AI Thread Summary
The discussion focuses on troubleshooting MATLAB code, specifically regarding the use of element-by-element operations in matrix calculations. The original poster seeks help with their code, which involves complex mathematical expressions. The key advice provided is to use periods before operators (e.g., replacing * with .* and / with ./) to ensure element-by-element operations, preventing errors related to incompatible matrix dimensions. Additionally, a built-in MATLAB function called "vectorize" is mentioned as a tool for simplifying certain expressions. The conversation concludes with the original poster expressing gratitude for the assistance and acknowledging their beginner status with MATLAB.
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
 
Physics news 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:
 

Similar threads

Replies
2
Views
2K
Replies
1
Views
6K
Replies
10
Views
3K
Replies
2
Views
9K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
3
Views
2K
Back
Top